chatgpt api response timer

This commit is contained in:
Mathieu B 2023-03-26 12:01:41 +02:00
parent 40c2f8acfa
commit 9e64983d28

View File

@ -11,16 +11,16 @@ def chatgpt_recognise(text, uuid):
if len(chat_messages) == 0:
chatgpt_init(uuid)
print("START-TIME GPT: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
chat_messages[uuid].append({"role": "user", "content": text})
# Call ChatGPT API
start_time = time.time()
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=chat_messages[uuid],
)
print("END-TIME GPT: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
end_time = time.time()
logging.info("GPT-3 response in " + str(end_time - start_time) + " seconds")
# Check if the response is a "valid" JSON
try:
@ -30,7 +30,7 @@ def chatgpt_recognise(text, uuid):
return response
except Exception as e:
logging.error("Error while parsing GPT-3 response, probably not JSON: " + str(response.choices))
logging.error("Error while parsing ChatGPT response, probably not JSON: " + str(response.choices))
logging.error(str(e))
return {"action": "answer", "answer": get_answer_from_response(response)}