From 86925ddf25ccf08823ab531d5dfffa3e8209022d Mon Sep 17 00:00:00 2001 From: H Vs Date: Wed, 25 Dec 2024 10:27:38 +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 --- bot/chatgpt/chat_gpt_bot.py | 23 ++++++++++++++++++++++- channel/wechat/wechat_channel.py | 8 ++++---- config-dev.json | 7 ++++--- config.json | 1 - 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/bot/chatgpt/chat_gpt_bot.py b/bot/chatgpt/chat_gpt_bot.py index c4a7c25..2a8a091 100644 --- a/bot/chatgpt/chat_gpt_bot.py +++ b/bot/chatgpt/chat_gpt_bot.py @@ -164,7 +164,7 @@ class ChatGPTBot(Bot, OpenAIImage): content=response.choices[0]["message"]["content"] description = '' userSelectOptions = [] - if isinstance(content, list): + if isinstance(content, list) and any(item.get("type") == "interactive" for item in content): # print(content) for item in content: if item["type"] == "interactive" and item["interactive"]["type"] == "userSelect": @@ -181,6 +181,27 @@ class ChatGPTBot(Bot, OpenAIImage): "completion_tokens": response["usage"]["completion_tokens"], "content": description + '------------------------------\n'+values_string, } + + elif isinstance(content, list) and any(item.get("type") == "text" for item in content): + memory.USER_INTERACTIVE_CACHE[session.session_id] = { + "interactive":False + } + text='' + for item in content: + if item["type"] == "text": + text=item["text"]["content"] + + if text=='': + args.pop('chatId', None) # The second argument (None) is the default return value if the key doesn't exist + args.pop('detail', None) + response = openai.ChatCompletion.create(api_key=api_key, messages=messages_to_send, **args) + text=response.choices[0]["message"]["content"] + return { + "total_tokens": response["usage"]["total_tokens"], + "completion_tokens": response["usage"]["completion_tokens"], + "content": text, + } + else: memory.USER_INTERACTIVE_CACHE[session.session_id] = { "interactive":False diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index 2068322..1768322 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -503,7 +503,7 @@ def wx_messages_process_callback(user_nickname,message): kafka_helper.kafka_client.produce_message(message) logger.info("发送对话 %s",message) # 等待随机时间 - time.sleep(random.uniform(30, 60)) + time.sleep(random.uniform(5, 15)) # 处理图片 elif wx_content.get("type",None) == 'image_url': print('发送图片') @@ -536,7 +536,7 @@ def wx_messages_process_callback(user_nickname,message): kafka_helper.kafka_client.produce_message(message) logger.info("发送对话 %s",message) # 等待随机时间 - time.sleep(random.uniform(30, 60)) + time.sleep(random.uniform(5, 15)) #处理文件 elif wx_content.get("type",None) == 'file': print('处理文件') @@ -564,7 +564,7 @@ def wx_messages_process_callback(user_nickname,message): kafka_helper.kafka_client.produce_message(message) logger.info("发送对话 %s",message) # 等待随机时间 - time.sleep(random.uniform(30, 60)) + time.sleep(random.uniform(5, 15)) elif ext in ['.mp4']: @@ -580,7 +580,7 @@ def wx_messages_process_callback(user_nickname,message): kafka_helper.kafka_client.produce_message(message) logger.info("发送对话 %s",message) # 等待随机时间 - time.sleep(random.uniform(30, 60)) + time.sleep(random.uniform(5, 15)) else: logger.warning(f'暂不支持 {ext} 文件的处理') diff --git a/config-dev.json b/config-dev.json index cb07ed2..3dd95c8 100644 --- a/config-dev.json +++ b/config-dev.json @@ -6,7 +6,7 @@ "claude_api_key": "YOUR API KEY", "proxy": "", "hot_reload": true, - "debug": true, + "debug": false, "single_chat_reply_prefix": "", "group_chat_prefix": [ "zhushou" @@ -19,8 +19,9 @@ "group_welcome_msg": "", "trigger_by_self": true, "voice_to_text":"ali", + "text_to_voice":"ali", "speech_recognition": true, - "group_speech_recognition": true, + "group_speech_recognition": false, "voice_reply_voice": true, "conversation_max_tokens": 2500, "expires_in_seconds": 300, @@ -36,7 +37,7 @@ "redis_password":"telpo#1234", "redis_db":3, - "kafka_bootstrap_servers":"192.168.2.121:9092", + "kafka_bootstrap_servers":"172.19.42.53:9092", "aiops_api":"https://id.ssjlai.com/aiopsadmin" } diff --git a/config.json b/config.json index 9bc802d..1942453 100644 --- a/config.json +++ b/config.json @@ -12,7 +12,6 @@ "zhushou" ], "group_name_white_list": [ - "AI好蕴测试群3" ], "image_create_prefix": [