zhayujie / chatgpt-on-wechat

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

当Channel为terminal时执行异常 #1613

Closed qiaolb closed 3 weeks ago

qiaolb commented 8 months ago

前置确认

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

操作系统类型?

MacOS

运行的python版本是?

other

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

Master (branch)

运行的channel类型是?

wx(个人微信, itchat)

复现步骤 🕹

当设置channel为terminal时,执行错误

问题描述 😯

错误内容:

 [ERROR][2023-12-20 14:29:35][chat_channel.py:300] - Worker return exception: 'isgroup'

修改代码:channel/chat_channel.py:

image

if context.get("isgroup", False)判断没有isgroup时增加该key可以解决:

            if context.get("isgroup", False):
               ...
            else:
                context["session_id"] = cmsg.other_user_id
                context["receiver"] = cmsg.other_user_id
                context["isgroup"] = False

终端日志 📒

Debug模式下,日志如下:

Please input your question:
User:hi
[ERROR][2023-12-20 14:29:35][chat_channel.py:300] - Worker return exception: 'isgroup'
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/Documents/workspace/chatgpt-on-wechat/channel/chat_channel.py", line 169, in _handle
    reply = self._generate_reply(context)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/Documents/workspace/chatgpt-on-wechat/channel/chat_channel.py", line 179, in _generate_reply
    e_context = PluginManager().emit_event(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/Documents/workspace/chatgpt-on-wechat/plugins/plugin_manager.py", line 189, in emit_event
    instance.handlers[e_context.event](e_context, *args, **kwargs)
  File "/Users/xxx/Documents/workspace/chatgpt-on-wechat/plugins/linkai/linkai.py", line 112, in on_handle_context
    if context.type == ContextType.TEXT and _find_file_id(context):
                                            ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/Documents/workspace/chatgpt-on-wechat/plugins/linkai/linkai.py", line 283, in _find_file_id
    user_id = _find_user_id(context)
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/Documents/workspace/chatgpt-on-wechat/plugins/linkai/linkai.py", line 265, in _find_user_id
    if context["isgroup"]:
       ~~~~~~~^^^^^^^^^^^
  File "/Users/xxx/Documents/workspace/chatgpt-on-wechat/bridge/context.py", line 46, in __getitem__
    return self.kwargs[key]
           ~~~~~~~~~~~^^^^^
KeyError: 'isgroup'
wonder-perfect commented 6 months ago

[ERROR][2024-02-20 21:39:42][chat_channel.py:302] - Worker return exception: 'isgroup' NoneType: None 可复现,解决方案有效

6vision commented 3 weeks ago

最新版本已修复