dify icon indicating copy to clipboard operation
dify copied to clipboard

The suggested interface is reporting error 400 in some large models

Open beardog6 opened this issue 1 year ago • 2 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.9

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When setting the global default model to GLM-4, the suggested interface returns a 400 error when calling large models, because the GLM-4 large model does not support setting the temperature parameter to 0.0

The problematic code is in dify\api\core\llm_generator\llm_generator.py line:83

            response = model_instance.invoke_llm(
                prompt_messages=prompt_messages,
                model_parameters={
                    "max_tokens": 256,
                    "temperature": 0
                },
                stream=False
            )

It is recommended to set the default temperature to 0.1.

✔️ Expected Behavior

Correct suggestions returned

❌ Actual Behavior

The exception in the large model of the interface was caught, and an empty suggestion was returned.

beardog6 avatar May 29 '24 08:05 beardog6

@beardog6 Hello there! I'm here to help you with any bugs, questions, or contributions you might have while waiting for a human maintainer.

To resolve the 400 error in Dify version 0.6.9 when using the GLM-4 large model, you need to ensure that the temperature parameter is set within the valid range for the model. The GLM-4 large model does not support setting the temperature parameter to 0.0. Instead, the temperature parameter must be a positive number within the range (0.0, 1.0], and it cannot be equal to 0. The default value is 0.95.

You can modify the problematic code in dify/api/core/llm_generator/llm_generator.py to set the temperature to a valid value, such as 0.1 or 0.95. Here is the corrected code:

response = model_instance.invoke_llm(
    prompt_messages=prompt_messages,
    model_parameters={
        "max_tokens": 256,
        "temperature": 0.1  # Set to a valid value within the range (0.0, 1.0]
    },
    stream=False
)

This adjustment should resolve the error and allow the model to return correct suggestions [1][2].

Details

About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

dosubot[bot] avatar May 29 '24 08:05 dosubot[bot]

See this https://github.com/langgenius/dify/pull/4269

crazywoola avatar May 29 '24 09:05 crazywoola