2023-05-11 21:48:16 +02:00
|
|
|
import os
|
|
|
|
import openai
|
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
|
|
|
|
if os.getenv('OPENAI_API_BASE'):
|
|
|
|
openai.api_base = os.getenv('OPENAI_API_BASE')
|
2023-05-11 23:28:39 +02:00
|
|
|
|
2023-05-11 21:48:16 +02:00
|
|
|
openai.api_key = os.getenv('OPENAI_API_KEY')
|
|
|
|
|
|
|
|
MODEL = os.getenv('OPENAI_CHAT_MODEL') or 'gpt-3.5-turbo'
|
|
|
|
|
|
|
|
def generate(messages: str):
|
|
|
|
"""Generates a new message based on the given messages."""
|
|
|
|
|
|
|
|
return openai.ChatCompletion.create(
|
|
|
|
model=MODEL,
|
|
|
|
messages=messages,
|
2023-05-13 14:29:15 +02:00
|
|
|
temperature=0.8,
|
|
|
|
frequency_penalty=0.0,
|
|
|
|
presence_penalty=2,
|
2023-05-11 21:48:16 +02:00
|
|
|
|
2023-05-11 23:28:39 +02:00
|
|
|
).choices[0].message.content
|