init
This commit is contained in:
31
services/llm.py
Normal file
31
services/llm.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import openai
|
||||
|
||||
class Llm:
|
||||
def __init__(self, apiKey:str):
|
||||
self.client = openai.OpenAI(
|
||||
api_key=apiKey,
|
||||
base_url='https://api.intelligence.io.solutions/api/v1/'
|
||||
)
|
||||
|
||||
def generate(self, model:str, systemPrompt:str, userPrompt:str, temp:float):
|
||||
'''
|
||||
prompt[user_promtp, system_ptompt]
|
||||
Function generate text by prompt
|
||||
'''
|
||||
|
||||
# Получаем ответ от нейросети
|
||||
response = self.client.chat.completions.create(
|
||||
model=model,
|
||||
messages=[
|
||||
{'role': 'system', 'content': systemPrompt},
|
||||
{'role': 'user', 'content': userPrompt},
|
||||
],
|
||||
temperature=temp,
|
||||
stream=False
|
||||
)
|
||||
|
||||
# Достаем текст
|
||||
text = str(response.choices[0].message.content)
|
||||
|
||||
return text, text
|
||||
|
||||
Reference in New Issue
Block a user