Bugfixes, store output logs

This commit is contained in:
Anton Osika
2023-06-25 10:48:51 +02:00
parent 8b2ea8ef58
commit 2a39cc4cd7
5 changed files with 66 additions and 25 deletions

View File

@@ -10,17 +10,7 @@ logger = logging.getLogger(__name__)
class AI:
def __init__(self, model="gpt-4", temperature=0.1):
self.temperature = temperature
try:
openai.Model.retrieve(model)
self.model = model
except openai.InvalidRequestError:
print(
f"Model {model} not available for provided API key. Reverting "
"to gpt-3.5-turbo. Sign up for the GPT-4 wait list here: "
"https://openai.com/waitlist/gpt-4-api"
)
self.model = "gpt-3.5-turbo"
self.model = model
def start(self, system, user):
messages = [
@@ -61,3 +51,16 @@ class AI:
messages += [{"role": "assistant", "content": "".join(chat)}]
logger.debug(f"Chat completion finished: {messages}")
return messages
def fallback_model(model: str) -> str:
try:
openai.Model.retrieve(model)
return model
except openai.InvalidRequestError:
print(
f"Model {model} not available for provided API key. Reverting "
"to gpt-3.5-turbo. Sign up for the GPT-4 wait list here: "
"https://openai.com/waitlist/gpt-4-api\n"
)
return "gpt-3.5-turbo"