[Bug] alter model from gpt3 to wenxin api, the flow fails at first node requires model #6547

Closed
opened 2026-02-21 18:16:14 -05:00 by yindo · 14 comments
Owner

Originally created by @zydmtaichi on GitHub (Nov 5, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.10.2

Cloud or Self Hosted

Cloud

Steps to reproduce

create app by using Question Classifier + Knowledge + Chatbot template and alter the model in workflow to wenxin api(e.g. ERNIE4.0-8K).And we always get err info [wenxin] Bad Request Error, The number of messages should be odd.
I check the node input as below:

{
  "sys.query": "你好",
  "sys.files": [],
  "sys.conversation_id": "f3320b50-61b4-4fdf-bad5-2ee354e86463",
  "sys.user_id": "f5addcf4-d00e-447b-b47e-aee3976c7e9e",
  "sys.dialogue_count": 0,
  "sys.app_id": "afde1bfb-2044-4677-b711-2a806aaa2eec",
  "sys.workflow_id": "efaefd1c-9ba6-40a5-9238-9d063616d0cc",
  "sys.workflow_run_id": "b8c8f58c-fa57-439c-80d1-c92103f77423"
}

And the node output is empty for the request to wenxin is failed

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @zydmtaichi on GitHub (Nov 5, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.10.2 ### Cloud or Self Hosted Cloud ### Steps to reproduce create app by using `Question Classifier + Knowledge + Chatbot` template and alter the model in workflow to wenxin api(e.g. ERNIE4.0-8K).And we always get err info `[wenxin] Bad Request Error, The number of messages should be odd.` I check the node input as below: ``` { "sys.query": "你好", "sys.files": [], "sys.conversation_id": "f3320b50-61b4-4fdf-bad5-2ee354e86463", "sys.user_id": "f5addcf4-d00e-447b-b47e-aee3976c7e9e", "sys.dialogue_count": 0, "sys.app_id": "afde1bfb-2044-4677-b711-2a806aaa2eec", "sys.workflow_id": "efaefd1c-9ba6-40a5-9238-9d063616d0cc", "sys.workflow_run_id": "b8c8f58c-fa57-439c-80d1-c92103f77423" } ``` And the node output is empty for the request to wenxin is failed ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bugstale labels 2026-02-21 18:16:14 -05:00
yindo closed this issue 2026-02-21 18:16:15 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 5, 2024):

The error you're encountering is due to the Wenxin API's ErnieBotModel requirement that the number of messages in the request body be odd. This is enforced in the _build_chat_request_body method, which raises a BadRequestError if the number of messages is even. To resolve this issue, ensure that the number of messages you are sending in the request is odd [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Nov 5, 2024): <!-- Answer --> The error you're encountering is due to the Wenxin API's `ErnieBotModel` requirement that the number of messages in the request body be odd. This is enforced in the `_build_chat_request_body` method, which raises a `BadRequestError` if the number of messages is even. To resolve this issue, ensure that the number of messages you are sending in the request is odd <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/wenxin/llm/ernie_bot.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@zydmtaichi commented on GitHub (Nov 5, 2024):

The error you're encountering is due to the Wenxin API's ErnieBotModel requirement that the number of messages in the request body be odd. This is enforced in the _build_chat_request_body method, which raises a BadRequestError if the number of messages is even. To resolve this issue, ensure that the number of messages you are sending in the request is odd [1].

To continue talking to Dosu, mention @dosu.

I only input one message, the num of message is certainly odd, but the err still exists

@zydmtaichi commented on GitHub (Nov 5, 2024): > The error you're encountering is due to the Wenxin API's `ErnieBotModel` requirement that the number of messages in the request body be odd. This is enforced in the `_build_chat_request_body` method, which raises a `BadRequestError` if the number of messages is even. To resolve this issue, ensure that the number of messages you are sending in the request is odd [[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/wenxin/llm/ernie_bot.py). > > _To continue talking to [Dosu](https://dosu.dev), mention @dosu._ I only input one message, the num of message is certainly odd, but the err still exists
Author
Owner

@dosubot[bot] commented on GitHub (Nov 5, 2024):

If you're inputting only one message and still encountering the BadRequestError for an odd number of messages, it suggests that there might be an additional message being added or not removed correctly. This could happen if a system message is being added automatically or if the initial message is not correctly identified as a "user" message.

Ensure that the message list contains only the intended single message and that it is correctly formatted as a "user" message. Additionally, check if there is any default behavior or configuration in the Dify platform that might add an extra message to the message list before it is processed by the _build_chat_request_body method [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Nov 5, 2024): <!-- Answer --> If you're inputting only one message and still encountering the `BadRequestError` for an odd number of messages, it suggests that there might be an additional message being added or not removed correctly. This could happen if a system message is being added automatically or if the initial message is not correctly identified as a "user" message. Ensure that the message list contains only the intended single message and that it is correctly formatted as a "user" message. Additionally, check if there is any default behavior or configuration in the Dify platform that might add an extra message to the message list before it is processed by the `_build_chat_request_body` method <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/wenxin/llm/ernie_bot.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@zydmtaichi commented on GitHub (Nov 5, 2024):

If you're inputting only one message and still encountering the BadRequestError for an odd number of messages, it suggests that there might be an additional message being added or not removed correctly. This could happen if a system message is being added automatically or if the initial message is not correctly identified as a "user" message.

Ensure that the message list contains only the intended single message and that it is correctly formatted as a "user" message. Additionally, check if there is any default behavior or configuration in the Dify platform that might add an extra message to the message list before it is processed by the _build_chat_request_body method [1].

To continue talking to Dosu, mention @dosu.

It's impossible. the workflow fails at Question Classifier node. There is no such thing like system message.

@zydmtaichi commented on GitHub (Nov 5, 2024): > If you're inputting only one message and still encountering the `BadRequestError` for an odd number of messages, it suggests that there might be an additional message being added or not removed correctly. This could happen if a system message is being added automatically or if the initial message is not correctly identified as a "user" message. > > Ensure that the message list contains only the intended single message and that it is correctly formatted as a "user" message. Additionally, check if there is any default behavior or configuration in the Dify platform that might add an extra message to the message list before it is processed by the `_build_chat_request_body` method [[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/wenxin/llm/ernie_bot.py). > > _To continue talking to [Dosu](https://dosu.dev), mention @dosu._ It's impossible. the workflow fails at Question Classifier node. There is no such thing like system message.
Author
Owner

@zydmtaichi commented on GitHub (Nov 5, 2024):

image

@zydmtaichi commented on GitHub (Nov 5, 2024): ![image](https://github.com/user-attachments/assets/15789609-cea7-4eac-a20c-5878084e476a)
Author
Owner

@crazywoola commented on GitHub (Nov 5, 2024):

Please provide a minimal DSL

@crazywoola commented on GitHub (Nov 5, 2024): Please provide a minimal DSL
Author
Owner

@zydmtaichi commented on GitHub (Nov 5, 2024):

Please provide a minimal DSL

Question Classifier + Knowledge + Chatbot .txt

@zydmtaichi commented on GitHub (Nov 5, 2024): > Please provide a minimal DSL [Question Classifier + Knowledge + Chatbot .txt](https://github.com/user-attachments/files/17627936/Question.Classifier.%2B.Knowledge.%2B.Chatbot.txt)
Author
Owner

@zydmtaichi commented on GitHub (Nov 5, 2024):

Please provide a minimal DSL

hi @crazywoola ,
I double check the flow per node and find only the Question Classifier node always fails on model wenxin while the pure llm node works fine. pls refer the img below.

image

image

@zydmtaichi commented on GitHub (Nov 5, 2024): > Please provide a minimal DSL hi @crazywoola , I double check the flow per node and find only the Question Classifier node always fails on model wenxin while the pure llm node works fine. pls refer the img below. ![image](https://github.com/user-attachments/assets/8d365fbd-2117-45af-ac50-7dc6ad99ff52) ![image](https://github.com/user-attachments/assets/8b069ce4-1816-4c48-8768-e91bc20711a0)
Author
Owner

@zydmtaichi commented on GitHub (Nov 7, 2024):

Please provide a minimal DSL

Question Classifier + Knowledge + Chatbot .txt

hi @crazywoola ,
any update for this issue?

@zydmtaichi commented on GitHub (Nov 7, 2024): > > Please provide a minimal DSL > > [Question Classifier + Knowledge + Chatbot .txt](https://github.com/user-attachments/files/17627936/Question.Classifier.%2B.Knowledge.%2B.Chatbot.txt) hi @crazywoola , any update for this issue?
Author
Owner

@svcvit commented on GitHub (Nov 11, 2024):

The reason is that Wenxin's messages parameter requires an alternating format of user and assistant messages. However, the classifier currently outputs two consecutive user messages, which causes an error.

@svcvit commented on GitHub (Nov 11, 2024): The reason is that Wenxin's `messages` parameter requires an alternating format of `user` and `assistant` messages. However, the classifier currently outputs two consecutive `user` messages, which causes an error.
Author
Owner

@zydmtaichi commented on GitHub (Nov 13, 2024):

The reason is that Wenxin's messages parameter requires an alternating format of user and assistant messages. However, the classifier currently outputs two consecutive user messages, which causes an error.

hi @svcvit ,
Most models following the openai api standard all require an alternating format of user and assistant messages. The classifier is not compatible with too much models in provider list. I think we need to modify the classifier input to match the model.

@zydmtaichi commented on GitHub (Nov 13, 2024): > The reason is that Wenxin's `messages` parameter requires an alternating format of `user` and `assistant` messages. However, the classifier currently outputs two consecutive `user` messages, which causes an error. hi @svcvit , Most models following the openai api standard all require an alternating format of `user` and `assistant` messages. The classifier is not compatible with too much models in provider list. I think we need to modify the classifier input to match the model.
Author
Owner

@zydmtaichi commented on GitHub (Nov 21, 2024):

hi @crazywoola ,
Any commit or fix for this issue?

@zydmtaichi commented on GitHub (Nov 21, 2024): hi @crazywoola , Any commit or fix for this issue?
Author
Owner

@crazywoola commented on GitHub (Dec 18, 2024):

Not yet.

@crazywoola commented on GitHub (Dec 18, 2024): Not yet.
Author
Owner

@dosubot[bot] commented on GitHub (Jan 22, 2025):

Hi, @zydmtaichi. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • The issue involves a bug when switching from GPT-3 to the Wenxin API in a specific workflow template.
  • The workflow fails due to a "Bad Request Error" caused by an odd number of messages.
  • The problem is identified as the classifier outputting two consecutive user messages, which is incompatible with Wenxin's requirements.
  • You suggested modifying the classifier input to align with model requirements, but no fix has been implemented yet.

Next Steps:

  • Please let us know if this issue is still relevant to the latest version of the Dify repository by commenting on this issue.
  • If there is no further activity, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jan 22, 2025): Hi, @zydmtaichi. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - The issue involves a bug when switching from GPT-3 to the Wenxin API in a specific workflow template. - The workflow fails due to a "Bad Request Error" caused by an odd number of messages. - The problem is identified as the classifier outputting two consecutive `user` messages, which is incompatible with Wenxin's requirements. - You suggested modifying the classifier input to align with model requirements, but no fix has been implemented yet. **Next Steps:** - Please let us know if this issue is still relevant to the latest version of the Dify repository by commenting on this issue. - If there is no further activity, this issue will be automatically closed in 15 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6547