From 9e64983d28565e4be383c91afb456f6a39393cbc Mon Sep 17 00:00:00 2001 From: Mathieu B Date: Sun, 26 Mar 2023 12:01:41 +0200 Subject: [PATCH] chatgpt api response timer --- jarvis/utils/chatgpt_utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jarvis/utils/chatgpt_utils.py b/jarvis/utils/chatgpt_utils.py index 1a30ee7..a8e48b1 100644 --- a/jarvis/utils/chatgpt_utils.py +++ b/jarvis/utils/chatgpt_utils.py @@ -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)}