LangBot icon indicating copy to clipboard operation
LangBot copied to clipboard

[Bug]: Claude API报错,first message must use the "user" role

Open the-lazy-me opened this issue 1 year ago • 2 comments

消息平台适配器

aiocqhttp(使用 OneBot 协议接入的)

运行环境

Win 11,python 3.10.9

QChatGPT版本

v3.3.0.1

异常情况

情况

  • 预设模式:full-scenario
  • 预设内容:默认生成的default

用Claude的时候,会出现如下报错

[2024-08-12 23:06:08.310] F:\QChatGPT\pkg\pipeline\controller.py (94) - [ERROR] :
    模型请求失败: 请求参数错误: Error code: 400 - {'error': {'message': 'messages: first message must use the "user" role (request id: ) (request id: ) (request id: ) (request id: 20240812230606897709001qmTtjTcX) (request id: 20240812230544538712316GEJr6bUZ) (request id: 20240812230544459516921rjxz99RP)', 'type': 'invalid_request_error', 'param': '', 'code': None}}

原因

原因:像 anthropic 这样的模型只接受轮流的消息,即:它必须后面跟着 user 或 ai,一个接一个,所以你不能有 2 个具有相同用户或 ai 角色的连续消息。 来自https://github.com/FlowiseAI/Flowise/issues/2516的解释

修改意见

修改templates的default.json为

{
    "prompt": [
        {
            "role": "system",
            "content": "You are a helpful assistant. 如果我需要帮助,你要说“输入!help获得帮助”"
        },
        {
            "role": "user",
            "content": "你好"
        },
        {
            "role": "assistant",
            "content": "你好!我是一个能干的AI助手。 如果你需要帮助,我会说“输入!help获得帮助”"
        }
    ]
}

启用的插件

No response

the-lazy-me avatar Aug 12 '24 15:08 the-lazy-me

我用的也是claude,在full-scenario中好像不吃system所以我就用user给出system的内容后用assistant回应会严格遵从以上内容,也许可以当做是一个临时解决方法?

Tigrex-Dai avatar Aug 13 '24 01:08 Tigrex-Dai

can someone post the solution (temporary or not) in English and give a simple explanation?

netgfx avatar Sep 03 '24 10:09 netgfx

现在应该会自动删除的,无法复现。

RockChinQ avatar Mar 30 '25 15:03 RockChinQ