Implement streaming output for Dify provider #3584
Draft
+159
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #TBD
Motivation / 动机
Dify provider previously faked streaming by yielding the complete response twice. This caused poor UX as users waited for the entire response before seeing any output, unlike OpenAI/Gemini providers which stream incrementally.
Modifications / 改动点
Modified:
astrbot/core/provider/sources/dify_source.pyRewrote
text_chat_stream()to yield chunks progressively:chunk["answer"]immediately asLLMResponse(is_chunk=True), accumulates text, then yields final complete response withis_chunk=Falseworkflow_finishedevent receivedVerification Steps / 验证步骤
api_type: "chat"or"workflow"Screenshots or Test Results / 运行截图或测试结果
Compatibility & Breaking Changes / 兼容性与破坏性变更
No breaking changes. Implementation maintains identical behavior for:
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.