chatgpt api response timer
This commit is contained in:
parent
40c2f8acfa
commit
9e64983d28
@ -11,16 +11,16 @@ def chatgpt_recognise(text, uuid):
|
|||||||
if len(chat_messages) == 0:
|
if len(chat_messages) == 0:
|
||||||
chatgpt_init(uuid)
|
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})
|
chat_messages[uuid].append({"role": "user", "content": text})
|
||||||
|
|
||||||
|
# Call ChatGPT API
|
||||||
|
start_time = time.time()
|
||||||
response = openai.ChatCompletion.create(
|
response = openai.ChatCompletion.create(
|
||||||
model="gpt-3.5-turbo",
|
model="gpt-3.5-turbo",
|
||||||
messages=chat_messages[uuid],
|
messages=chat_messages[uuid],
|
||||||
)
|
)
|
||||||
|
end_time = time.time()
|
||||||
print("END-TIME GPT: " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
|
logging.info("GPT-3 response in " + str(end_time - start_time) + " seconds")
|
||||||
|
|
||||||
# Check if the response is a "valid" JSON
|
# Check if the response is a "valid" JSON
|
||||||
try:
|
try:
|
||||||
@ -30,7 +30,7 @@ def chatgpt_recognise(text, uuid):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
except Exception as e:
|
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))
|
logging.error(str(e))
|
||||||
return {"action": "answer", "answer": get_answer_from_response(response)}
|
return {"action": "answer", "answer": get_answer_from_response(response)}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user