RockChinQ / QChatGPT

😎高稳定性、🧩支持扩展、🦄多模态的 ChatGPT QQ / QQ频道 / One Bot 机器人🤖 | 支持 OpenAI GPT、GPT 4o、Claude、Gemini Pro、DeepSeek、Moonshot(Kimi)、gpt4free、One API、Ollama 的 QQ / QQ频道 / OneBot 机器人 / Agent 平台
https://q.rkcn.top
GNU Affero General Public License v3.0
4.22k stars 327 forks source link

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

Open the-lazy-me opened 1 month ago

the-lazy-me commented 1 month ago

消息平台适配器

aiocqhttp(使用 OneBot 协议接入的)

运行环境

Win 11,python 3.10.9

QChatGPT版本

v3.3.0.1

异常情况

情况

用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

Tigrex-Dai commented 1 month ago

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

netgfx commented 1 week ago

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