From 4cc74b7a7217406d638893f19ebac890da72860a Mon Sep 17 00:00:00 2001 From: H Vs Date: Thu, 23 Jan 2025 15:52:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/messages_resource.py | 4 +++- wechat/gewe_chat.py | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/resources/messages_resource.py b/resources/messages_resource.py index 3977087..76218aa 100644 --- a/resources/messages_resource.py +++ b/resources/messages_resource.py @@ -680,6 +680,8 @@ def get_messages_from_cache(hash_key,object:object)->list: def fast_gpt_api(messages:list,wixd:str,friend_wxid:str): c=gewe_chat.wxchat.get_wxchat_config_from_cache(wixd) api_key=c.get('agentTokenId',"sk-jr69ONIehfGKe9JFphuNk4DU5Y5wooHKHhQv7oSnFzVbwCnW65fXO9kvH") + print(f'流程key:{api_key}\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n') + #api_key="sk-jr69ONIehfGKe9JFphuNk4DU5Y5wooHKHhQv7oSnFzVbwCnW65fXO9kvH" #测试 #api_key="sk-uJDBdKmJVb2cmfldGOvlIY6Qx0AzqWMPD3lS1IzgQYzHNOXv9SKNI" #开发2 api_url = "http://106.15.182.218:3000/api/v1/chat/completions" @@ -701,7 +703,7 @@ def fast_gpt_api(messages:list,wixd:str,friend_wxid:str): response.raise_for_status() response_data = response.json() logger.info("[CHATGPT] 响应={}".format(json.dumps(response_data, separators=(',', ':'),ensure_ascii=False))) - print(response_data) + #print(response_data) return response_data diff --git a/wechat/gewe_chat.py b/wechat/gewe_chat.py index 919b532..88b3da3 100644 --- a/wechat/gewe_chat.py +++ b/wechat/gewe_chat.py @@ -606,7 +606,7 @@ class GeWeChatCom: ############################### 其他 ############################### - def save_session_messages_to_cache(self, hash_key,object:object)->list: + def save_session_messages_to_cache(self, hash_key,item:object)->list: ''' 对话列表 ''' @@ -614,7 +614,7 @@ class GeWeChatCom: wxid=hash_key.split(':')[-1] if not messages: messages=[{"role": "system", "content": ""}] - messages.append(object) + messages.append(item) redis_helper.redis_helper.set_hash(hash_key,{"data":json.dumps(messages,ensure_ascii=False)},600) else: messages_str=redis_helper.redis_helper.get_hash_field(hash_key,"data") @@ -625,12 +625,13 @@ class GeWeChatCom: if isinstance(content, list) and content: last_content_type = content[-1].get("type") if last_content_type == 'image_url': - content.append(object['content'][0]) + content.append(item['content'][0]) messages[-1]['content']=content else: - messages.append(object) + messages.append(item) else: - messages.append(object) + if last_message!= item: + messages.append(item) redis_helper.redis_helper.set_hash(hash_key,{"data":json.dumps(messages,ensure_ascii=False)},600) return messages