zhayujie / chatgpt-on-wechat

基于大模型搭建的聊天机器人,同时支持 微信公众号、企业微信应用、飞书、钉钉 等接入,可选择GPT3.5/GPT-4o/GPT-o1/ Claude/文心一言/讯飞星火/通义千问/ Gemini/GLM-4/Claude/Kimi/LinkAI,能处理文本、语音和图片,访问操作系统和互联网,支持基于自有知识库进行定制企业智能客服。
https://docs.link-ai.tech/cow
MIT License
30.27k stars 7.96k forks source link

接入企业微信应用后出现调试报错 #2078

Closed samqin123 closed 3 months ago

samqin123 commented 3 months ago

前置确认

⚠️ 搜索issues中是否已存在类似问题

操作系统类型?

MacOS

运行的python版本是?

python 3.8

使用的chatgpt-on-wechat版本是?

Latest Release

运行的channel类型是?

other

复现步骤 🕹

[ERROR][2024-06-14 20:15:36][chat_channel.py:303] - Worker return exception: can only concatenate str (not "list") to str Traceback (most recent call last): File "/usr/local/python3/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/cow-qywx/chatgpt-on-wechat/channel/chat_channel.py", line 176, in _handle reply = self._decorate_reply(context, reply) File "/usr/cow-qywx/chatgpt-on-wechat/channel/chat_channel.py", line 261, in _decorate_reply reply_text = conf().get("single_chat_reply_prefix", "") + reply_text + conf().get("single_chat_reply_suffix", "") TypeError: can only concatenate str (not "list") to str [INFO][2024-06-14 20:16:56][wechatcomapp_channel.py:147] - [wechatcom] receive params: <Storage {'msg_signature': 'aeb6646b9251e3dbd2e3bbdbe18929e3666f5c8d', 'timestamp': '1718367416', 'nonce': '1718551955'}>

问题描述 😯

企业微信应用建立调试中,简单回复如你是谁正常,复杂查询回复报错。 比如[INFO][2024-06-14 20:16:56][wechatcomapp_channel.py:147] - [wechatcom] receive params: <Storage {'msg_signature': 'aeb6646b9251e3dbd2e3bbdbe18929e3666f5c8d', 'timestamp': '1718367416', 'nonce': '1718551955'}> 183.47.98.168:16224 - - [14/Jun/2024 20:16:56] "HTTP/1.1 POST /wxcomapp" - 200 OK [INFO][2024-06-14 20:16:56][chat_gpt_bot.py:49] - [CHATGPT] query=广州今天天气 [WARNING][2024-06-14 20:16:56][session_manager.py:94] - Exception when counting tokens precisely for prompt: name 'get_tokenizer' is not defined [WARNING][2024-06-14 20:17:04][session_manager.py:106] - Exception when counting tokens precisely for session: name 'get_tokenizer' is not defined [INFO][2024-06-14 20:17:04][wechatcomapp_channel.py:63] - [wechatcom] Do send text to QinXiaoQiang: [xyb] 您好,我来了~今天广州的天气预报显示,天气状况为大雨转大到暴雨,气温范围在33℃到26℃之间,风力为3-4级。

如果是复杂的问题,直接会报错 [WARNING][2024-06-14 20:15:19][session_manager.py:94] - Exception when counting tokens precisely for prompt: name 'get_tokenizer' is not defined [WARNING][2024-06-14 20:15:36][session_manager.py:106] - Exception when counting tokens precisely for session: name 'get_tokenizer' is not defined [ERROR][2024-06-14 20:15:36][chat_channel.py:303] - Worker return exception: can only concatenate str (not "list") to str Traceback (most recent call last): File "/usr/local/python3/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/cow-qywx/chatgpt-on-wechat/channel/chat_channel.py", line 176, in _handle reply = self._decorate_reply(context, reply) File "/usr/cow-qywx/chatgpt-on-wechat/channel/chat_channel.py", line 261, in _decorate_reply reply_text = conf().get("", "") + reply_text + conf().get("single_chat_reply_suffix", "") TypeError: can only concatenate str (not "list") to str

gpt4的解释: 这个错误信息表明在 chat_channel.py 文件的第 261 行,你尝试将一个字符串与一个列表进行拼接,这是不允许的。具体来说,reply_text 是一个列表,而你试图将其与字符串 conf().get("single_chat_reply_prefix", "") 和 conf().get("single_chat_reply_suffix", "") 进行拼接。

要解决这个问题,你需要确保 reply_text 是一个字符串,而不是一个列表。你可以通过以下几种方式来处理:

检查 reply_text 的来源:确保在赋值给 reply_text 之前,它已经被正确地转换为字符串。

gpt4给出代码 def _decorate_reply(self, context, reply):

假设 reply_text 是一个列表

reply_text = reply  # 这里假设 reply 是一个列表

# 检查 reply_text 是否为列表,如果是,将其转换为字符串
if isinstance(reply_text, list):
    reply_text = ' '.join(reply_text)  # 使用空格将列表元素连接成字符串

# 现在 reply_text 应该是一个字符串
reply_text = conf().get("single_chat_reply_prefix", "") + reply_text + conf().get("single_chat_reply_suffix", "")

return reply_text

终端日志 📒


<此处粘贴终端日志>
```def _decorate_reply(self, context, reply):
    # 假设 reply_text 是一个列表
    reply_text = reply  # 这里假设 reply 是一个列表

    # 检查 reply_text 是否为列表,如果是,将其转换为字符串
    if isinstance(reply_text, list):
        reply_text = ' '.join(reply_text)  # 使用空格将列表元素连接成字符串

    # 现在 reply_text 应该是一个字符串
    reply_text = conf().get("single_chat_reply_prefix", "") + reply_text + conf().get("single_chat_reply_suffix", "")

    return reply_text
6vision commented 3 months ago

看起来是config.json配置的问题,single_chat_reply_suffix和single_chat_reply_prefix两个参数是字符串,你可能配置成列表了