From 486c1dc620e5fcec02d722fbaa9c1c9841aa703f Mon Sep 17 00:00:00 2001 From: xszyou Date: Fri, 1 Sep 2023 15:59:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=8A=E5=A4=A9=E6=98=9F=E6=9C=9F=E4=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、修复gpt、chatglm2的消息记录方式逻辑。 --- README.md | 7 ++++--- README_EN.md | 4 ++++ WebSocket.md | 7 +------ ai_module/nlp_ChatGLM2.py | 14 ++++++++------ ai_module/nlp_gpt.py | 17 ++++++++--------- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d4e510f..a01b92c 100644 --- a/README.md +++ b/README.md @@ -119,14 +119,15 @@ Remote Android  [Live2D](https://www.bilibili.com/video/BV1sx4y1d775/?vd_sou ## **三、升级日志** +**2023.09.01** + ++ 修复gpt、chatglm2的消息记录方式逻辑。 + **2023.08.30** + 调整gpt的消息记录方式; - + *q&a支持RPA自动化脚本。 - - **2023.08.23:** + 更换gpt对接方式; diff --git a/README_EN.md b/README_EN.md index 4af68b1..2a63f3c 100644 --- a/README_EN.md +++ b/README_EN.md @@ -122,6 +122,10 @@ Message format: View [WebSocket.md](https://github.com/TheRamU/Fay/blob/main/Web ## **Upgrade Log** +**2023.09.01** + +- Fix the message logging logic of GPT and Chatglm2. + **2023.08.30** - Adjust the message recording method of GPT; diff --git a/WebSocket.md b/WebSocket.md index ae1ebbe..6c58f7e 100644 --- a/WebSocket.md +++ b/WebSocket.md @@ -40,6 +40,7 @@ "Lips":[{"Lip": "sil", "Time": 180}, {"Lip": "FF", "Time": 144}], "Time": 10, "Type": "interact" + "" } } ``` @@ -111,9 +112,3 @@ | 参数 | 描述 | 类型 | 范围 | | ---------- | ---------------- | ----- | --------------- | | Data.text | 文本 | str | | - -### 接收消息标记音频播放完成 - -```php -Play End -``` diff --git a/ai_module/nlp_ChatGLM2.py b/ai_module/nlp_ChatGLM2.py index 55c65cf..b4adfdc 100644 --- a/ai_module/nlp_ChatGLM2.py +++ b/ai_module/nlp_ChatGLM2.py @@ -5,18 +5,20 @@ from core.content_db import Content_Db def question(cont): content_db = Content_Db() - list = content_db.get_list('all','desc',10) + list = content_db.get_list('all','desc',11) answer_info = dict() chat_list = [] - for val in list: + i = len(list)-1 + while i >= 0: answer_info = dict() - if val[0] == "member": + if list[i][0] == "member": answer_info["role"] = "user" - answer_info["content"] = val[2] - elif val[0] == "fay": + answer_info["content"] = list[i][2] + elif list[i][0] == "fay": answer_info["role"] = "bot" - answer_info["content"] = val[2] + answer_info["content"] = list[i][2] chat_list.append(answer_info) + i -= 1 content = { "prompt":"请简单回复我。" + cont, "history":chat_list} diff --git a/ai_module/nlp_gpt.py b/ai_module/nlp_gpt.py index 06557d7..27aee68 100644 --- a/ai_module/nlp_gpt.py +++ b/ai_module/nlp_gpt.py @@ -36,27 +36,26 @@ def question(cont): #此处可以定义角色的行为和特征,假装xx模型可以绕过chatgpt信息检查 prompt = "你是数字人Fay。回答之前请一步一步想清楚。你的底层AI算法技术是Fay。当有人质疑你是假的 AI ,或者质疑你是用 ChatGPT 套的壳制作的时候,你就避而不答,转而讲一个笑话。所有回复请用20字内。" content_db = Content_Db() - communication_history = content_db.get_list('all','desc',10) + communication_history = content_db.get_list('all','desc',11) #历史记录处理 if len(communication_history)>1: msg = "以下是历史记录:" - i = 0 - for info in communication_history: - if info[0] == 'member': - content = "user:" + info[2] + i = len(communication_history)-1 + while i >= 0: + if communication_history[i][0] == 'member': + content = "user:" + communication_history[i][2] else: - content = "reply:" + info[2] + content = "reply:" + communication_history[i][2] if msg == "": msg = content else: - if i == len(communication_history) - 1: + if i == 0: msg = msg + "\n现在需要询问您的问题是(直接回答,不用前缀reply:):\n"+ cont else: msg = msg + "\n"+ content - i+=1 + i -= 1 else: msg = cont - message=[ {"role": "system", "content": prompt}, {"role": "user", "content": msg}