Closed totsukash closed 4 days ago
Hey there, @totsukash! I'm here to help you with bugs, questions, and becoming a contributor. Let me know how I can assist you while you wait for a human maintainer.
To resolve the "Bad Request Error, 400" related to the restricted HarmBlockThreshold setting BLOCK_NONE
when using Vertex AI with Dify, you need to adjust the HarmBlockThreshold
settings in the safety_settings
dictionary. The current settings are:
safety_settings = {
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
}
To resolve the error, you should change the HarmBlockThreshold
values to a less restrictive setting. For example, you can use HarmBlockThreshold.BLOCK_LOW
:
safety_settings = {
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_LOW,
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_LOW,
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_LOW,
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_LOW,
}
This adjustment should help in resolving the "Bad Request Error, 400" [1].
To continue talking to Dosu, mention @dosu.
Since we can't change that in the Cloud version, I'm thinking of modifying the default settings. https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/configure-safety-filters
I will set HARM_BLOCK_THRESHOLD_UNSPECIFIED
or remove these configs.
Self Checks
Dify version
v0.8.3
Cloud or Self Hosted
Cloud
Steps to reproduce
After completing the Vertex AI setup, an error occurs when calling the LLM.
I know the source of the problem.
https://github.com/langgenius/dify/blob/64baedb48429bf7332feab61d7a83cf1b7c91cda/api/core/model_runtime/model_providers/vertex_ai/llm/llm.py#L506-L511
✔️ Expected Behavior
To be able to perform inference without errors, just like other LLMs.
❌ Actual Behavior
Errors are occurring.