From ecfcdd3f191c6b997ac66d446d0242b89e1fad49 Mon Sep 17 00:00:00 2001 From: Changhua Date: Sat, 1 Apr 2023 16:33:49 +0800 Subject: [PATCH] Fix datetime subtracting error --- func_chatgpt.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/func_chatgpt.py b/func_chatgpt.py index 12f9f83..77d44e8 100644 --- a/func_chatgpt.py +++ b/func_chatgpt.py @@ -1,6 +1,6 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -import datetime +from datetime import datetime import openai @@ -42,12 +42,12 @@ class ChatGPT(): except Exception as e0: rsp = "发生未知错误:" + str(e0) - print(self.conversation_list[wxid]) + # print(self.conversation_list[wxid]) return rsp def updateMessage(self, wxid: str, question: str, role: str) -> None: - now_time = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + now_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) time_mk = "当需要回答时间时请直接参考回复:" # 初始化聊天记录,组装系统信息 @@ -77,15 +77,14 @@ class ChatGPT(): if __name__ == "__main__": - chat = ChatGPT("your key", "https://api.openai.com/v1") while True: q = input(">>> ") try: - time_start = datetime.time() # 记录开始时间 + time_start = datetime.now() # 记录开始时间 print(chat.get_answer(q, "wxid")) - time_end = datetime.time() # 记录结束时间 + time_end = datetime.now() # 记录结束时间 - print(f"{round(time_end - time_start, 2)}s") # 计算的时间差为程序的执行时间,单位为秒/s + print(f"{round((time_end - time_start).total_seconds(), 2)}s") # 计算的时间差为程序的执行时间,单位为秒/s except Exception as e: print(e)