Chat with DeepSeek-R1 API through Azure AI Studio get unexpected end alert
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] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- [x] Please do not modify this template :) and fill in all the required fields.
Dify version
0.15.3
Cloud or Self Hosted
Cloud
Steps to reproduce
When chat with DeepSeek-R1 through Azure AI Studio model, will get following alert and stop response streaming. Alert message: [azure_ai_studio] Error: 'utf-8' codec can't decode byte 0xe4 in position 5: unexpected end of data"
Possible solution: Fix bug in api/core/model_runtime/model_providers/azure_ai_studio/llm/llm.py , adding decode handling method.
✔️ Expected Behavior
Process respond until end successful.
❌ Actual Behavior
data: {"event": "agent_message", "conversation_id": "32ff1015-7cbf-4557-92be-33a147a461f1", "message_id": "c7734cb8-5ead-41c5-92d0-9474b8308a24", "created_at": 1739456925, "task_id": "13027371-7921-48fc-a8c2-749db4330487", "id": "c7734cb8-5ead-41c5-92d0-9474b8308a24", "answer": "\u4ef7"}
data: {"event": "error", "conversation_id": "32ff1015-7cbf-4557-92be-33a147a461f1", "message_id": "c7734cb8-5ead-41c5-92d0-9474b8308a24", "created_at": 1739456925, "code": "completion_request_error", "status": 400, "message": "[azure_ai_studio] Error: 'utf-8' codec can't decode byte 0xe4 in position 5: unexpected end of data"}
Hello, @EdwinDigital! I'm here to assist you with bug fixes, answer your questions, and guide you on how to become a contributor. Let's tackle this issue together!
The error you're encountering, "'utf-8' codec can't decode byte 0xe4 in position 5: unexpected end of data," suggests that there is an issue with the encoding of the response data from Azure AI Studio. This typically occurs when the data being processed is not properly encoded in UTF-8, or when there is a mismatch between the expected and actual encoding formats.
To address this issue, you can consider the following steps:
-
Check Data Encoding: Ensure that the data being sent and received is correctly encoded in UTF-8. This includes verifying that any input data to the Azure AI Studio model is properly encoded.
-
Modify
llm.pyfor Encoding Handling: You may need to modify thellm.pyfile to handle encoding issues more gracefully. This could involve adding try-except blocks around the decoding process to catch and handle encoding errors. You might also consider using a different error handling strategy, such as replacing problematic characters or ignoring errors. -
Review Response Handling: Examine the
_handle_stream_responseand_handle_non_stream_responsemethods inllm.pyto ensure they are correctly processing the response data. These methods are responsible for handling streamed and non-streamed responses, respectively [1].
By implementing these changes, you should be able to mitigate the UTF-8 decoding error and ensure that the response processing completes successfully.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other | Bug Report
I want to work on this issue, Please assign me?
I‘m facing the same issue on my end.
Hi, @EdwinDigital. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.
Issue Summary:
- You reported a UTF-8 decoding error with the DeepSeek-R1 API via Azure AI Studio.
- Suggested a fix by adding a decode handling method in the Python file.
- I recommended checking data encoding and modifying
llm.pyfor better handling. - User abhishek-kumar-91 showed interest in working on the issue.
- tonyhql also reported experiencing the same problem.
Next Steps:
- Please confirm if this issue is still relevant to the latest version of the Dify repository by commenting here.
- If there is no further activity, this issue will be automatically closed in 15 days.
Thank you for your understanding and contribution!