diff --git a/README.md b/README.md index 069ab8d..3611067 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ PAUSE #### file 设置当前程序使用哪一个对话记录,如果不设置,则默认开启一个新的对话 #### save -保存当前的对话记录,通常不需要手动调用,因为对话在退出后会自动保存,保存路径为程序所在目录,文件名为当前日期,文件名可以手动修改 +保存当前的对话记录,通常不需要手动调用,因为对话会自动保存,保存路径为当前用户的Documents\chat_logs目录中,文件名为当前日期,文件名可以手动修改 #### image 输入图片描述,返回图片的url,该图片和url不会自动保存,需要用户手动下载保存 #### audio diff --git a/main.py b/main.py index a5f016d..18542f3 100644 --- a/main.py +++ b/main.py @@ -77,7 +77,9 @@ def chat(): messages.append({"role": "user", "content": content}) try: - parseResult_stream(generateCompletion(messages)) if stream else parseResult(generateCompletion(messages)) + res = generateCompletion(messages) + parseResult_stream(res) if stream else parseResult(res) + save() except APIConnectionError: Log.error("[APIConnectionError]:Connection timed out. Please check the network or try again later") except InvalidRequestError: @@ -116,6 +118,7 @@ def setFile(): def save(): global messages, currentFile fileName = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + ".json" if currentFile == "" else currentFile + currentFile = fileName generateCatalogue() doc_path = os.path.join(os.path.expanduser("~"), "Documents") chat_logs_path = os.path.join(doc_path, "chat_logs") @@ -188,8 +191,7 @@ def generateCatalogue(): os.makedirs(chat_logs_path) -if __name__ == "__main__": - Log.info("Project Launch") +def run(): initOpenAI() cli = ClIHandle() cli.add("chat", chat) @@ -203,3 +205,12 @@ def generateCatalogue(): if option == "quit": break cli.parse(option) + + +if __name__ == "__main__": + try: + Log.info("Project Launch") + run() + finally: + Log.info("Project Finish") + save()