LangBot icon indicating copy to clipboard operation
LangBot copied to clipboard

[Bug]: controller.py (98) - [ERROR] : local variable 'chunk' referenced before assignment

Open RilesLee opened this issue 8 months ago • 2 comments

运行环境

docker

异常情况

我使用的消息平台是napcat(它们都运行在docker中,已经按照wiki调整两者的容器网络),消息平台和LangBot之间的通讯没有问题。 api平台使用的是dify(模型名称设置在这个地方应当不会生效) dify的地址是局域网中的另一台主机。 dify的API Endpoint:http://172.16.0.121/v1 请求运行器是:dify-service-api 当我认为万事大吉想要发送一条测试消息的时候,Langbot的日志中输出了如下内容:

[04-30 12:01:08.698] process.py (42) - [INFO] : 处理 person_1048893645 的请求(0): 1 [04-30 12:01:39.320] chat.py (94) - [ERROR] : 对话(0)请求失败: UnboundLocalError local variable 'chunk' referenced before assignment [04-30 12:01:39.651] controller.py (98) - [ERROR] : local variable 'chunk' referenced before assignment[04-30 12:02:02.198] process.py (42) - [INFO] : 处理 person_1048893645 的请求(1): 2 [04-30 12:02:33.098] chat.py (94) - [ERROR] : 对话(1)请求失败: UnboundLocalError local variable 'chunk' referenced before assignment [04-30 12:02:33.376] controller.py (98) - [ERROR] : local variable 'chunk' referenced before assignment

复现步骤

1、使用docker部署LangBot和NapCat并设置容器网络。 2、启用LangBot消息适配器(aiocqhttp,host:0.0.0.0,port:2280,设置access token) 3、登录NapCat并设置ws客户端,填写ws:// 4、发送测试消息,验证Napcat和LangBot之间是否通讯正常,langbot是否可以接收NapCat消息 5、配置Langbot的provider,使用Dify Service Chat 6、请求运行器使用:dify-service-api 7、再次发送测试消息,验证模型请求功能

启用的插件

未使用任何插件

RilesLee avatar Apr 30 '25 04:04 RilesLee

dify 上的应用是什么类型?发一下截图?或者dify应用的dsl

RockChinQ avatar May 01 '25 09:05 RockChinQ

把你的 provider.json 文件内容也贴上来看看

RockChinQ avatar May 01 '25 09:05 RockChinQ

dify 上的应用是什么类型?发一下截图?或者dify应用的dsl

在Dify中使用的应用是‘聊天助手’类型的应用

RilesLee avatar May 06 '25 05:05 RilesLee

把你的 provider.json 文件内容也贴上来看看

{
  "dashscope-app-api": {
    "agent": {
      "app-id": "Your_app_id",
      "references_quote": "参考资料来自:"
    },
    "api-key": "sk-1234567890",
    "app-type": "agent",
    "workflow": {
      "app-id": "Your_app_id",
      "biz_params": {
        "city": "北京",
        "date": "2023-08-10"
      },
      "references_quote": "参考资料来自:"
    }
  },
  "dify-service-api": {
    "agent": {
      "api-key": "app-4JcPg4vduePr83uWroLALYnC",
      "timeout": 120
    },
    "app-type": "chat",
    "base-url": "http://172.16.0.121/v1",
    "chat": {
      "api-key": "app-4JcPg4vduePr83uWroLALYnC",
      "timeout": 120
    },
    "options": {
      "convert-thinking-tips": "plain"
    },
    "workflow": {
      "api-key": "app-4JcPg4vduePr83uWroLALYnC",
      "output-key": "summary",
      "timeout": 120
    }
  },
  "enable-chat": true,
  "enable-vision": true,
  "keys": {
    "anthropic": [
      "sk-1234567890"
    ],
    "bailian": [
      "sk-xxxxxxx"
    ],
    "deepseek": [
      "sk-1234567890"
    ],
    "gitee": [],
    "gitee-ai": [
      "XXXXX"
    ],
    "modelscope": [
      "xxxxxxxx"
    ],
    "moonshot": [
      "sk-1234567890"
    ],
    "openai": [
      "sk-xxxxx(此处脱敏)"
    ],
    "ppio": [
      "xxxxxxxx"
    ],
    "siliconflow": [
      "xxxxxxx"
    ],
    "volcark": [
      "xxxxxxxx"
    ],
    "xai": [
      "xai-1234567890"
    ],
    "zhipuai": [
      "xxxxxxx"
    ]
  },
  "mcp": {
    "servers": []
  },
  "model": "gpt-4o",
  "prompt": {
    "default": "You are a helpful assistant."
  },
  "prompt-mode": "normal",
  "requester": {
    "anthropic-messages": {
      "args": {
        "max_tokens": 1024
      },
      "base-url": "https://api.anthropic.com",
      "timeout": 120
    },
    "bailian-chat-completions": {
      "args": {},
      "base-url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
      "timeout": 120
    },
    "deepseek-chat-completions": {
      "args": {},
      "base-url": "https://api.deepseek.com",
      "timeout": 120
    },
    "gitee-ai-chat-completions": {
      "args": {},
      "base-url": "https://ai.gitee.com/v1",
      "timeout": 120
    },
    "lmstudio-chat-completions": {
      "args": {},
      "base-url": "http://127.0.0.1:1234/v1",
      "timeout": 120
    },
    "modelscope-chat-completions": {
      "args": {},
      "base-url": "https://api-inference.modelscope.cn/v1",
      "timeout": 120
    },
    "moonshot-chat-completions": {
      "args": {},
      "base-url": "https://api.moonshot.cn/v1",
      "timeout": 120
    },
    "ollama-chat": {
      "args": {},
      "base-url": "http://127.0.0.1:11434",
      "timeout": 600
    },
    "openai-chat-completions": {
      "args": {},
      "base-url": "https://api.gptnb.ai",
      "timeout": 120
    },
    "ppio-chat-completions": {
      "args": {},
      "base-url": "https://api.ppinfra.com/v3/openai",
      "timeout": 120
    },
    "siliconflow-chat-completions": {
      "args": {},
      "base-url": "https://api.siliconflow.cn/v1",
      "timeout": 120
    },
    "volcark-chat-completions": {
      "args": {},
      "base-url": "https://ark.cn-beijing.volces.com/api/v3",
      "timeout": 120
    },
    "xai-chat-completions": {
      "args": {},
      "base-url": "https://api.x.ai/v1",
      "timeout": 120
    },
    "zhipuai-chat-completions": {
      "args": {},
      "base-url": "https://open.bigmodel.cn/api/paas/v4",
      "timeout": 120
    }
  },
  "runner": "local-agent"
}

最后的runner这里无论是local-agent对接普通的中转api还是使用dify-service-api对接dify都不行

RilesLee avatar May 06 '25 05:05 RilesLee

这个问题我这边没法复现,但从代码角度来看,你这里是 langbot 与 dify 的连接可能不正常,导致没有收到任何回复。现在我已经在 #1376 加了个针对这个问题的报错信息,你可以等新版发布之后再试试。

RockChinQ avatar May 09 '25 01:05 RockChinQ