Repository navigation
fix(model)!: validate completion input and correct fallback usage - #411
Merged
Merged
Conversation
1 task done
WH-2099
marked this pull request as ready for review
October 31, 2026 10:19
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
hjlarry
approved these changes
Oct 31, 2026
This was referenced Nov 2, 2026
Draft
7 of 13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Refs #387.
Provider migration: langgenius/dify-official-plugins#4156.
Completion mode previously passed SDK content objects into the JSON request, and successful responses without usage could count the model name as text and the actual content as tools.
Concatenate text blocks from the first prompt message and reject media before sending HTTP.
Use one usage calculator for streaming and non-streaming responses: estimate each missing or null count independently, preserve reported values including zero, count complete chat history and sent tool definitions, and include output tool calls.
Completion usage and its public token budget count the first prompt message.
For example,
Hello worldfollowed byAnswernow estimates 2 input tokens and 1 output token in completion mode, independent of text-block boundaries and streaming mode.Preserve explicit tool choices while forwarding tool definitions to the response handlers.
Strengthen input-preservation assertions with independent deep copies.
Merged on October 31.
SDK 0.11.0 publication for Dify 1.19.0 is tracked in #413; plugin delivery and the original reporter's acceptance remain in #387.
#412 is the draft follow-up for complete tool schemas, empty finish markers, and tool-only response text.
Compatibility
This targets SDK 0.11.0, which is unreleased.
Completion string and null payloads retain their existing representation; text blocks are joined in order and an empty list becomes an empty string.
Media input raises the public
InvokeErrorbefore HTTP; direct private_generate()calls receiveValueError.Tool-only chat replies can omit text content, while replies missing both content and tool calls still fail.
Provider overrides of
_handle_generate_response(),_handle_generate_stream_response(), and_create_final_llm_result_chunk()must accept and forward the optionaltoolsparameter.Text-counter overrides must implement
_num_tokens_from_string(text, tools=None).The companion draft migrates all nine affected providers found in the official plugin inheritance tree, including Yi's incompatible counter signature.
README documents the behavior and migration for 0.11.0; no additional SDK version bump is included.
Local token and price estimates are SDK records and do not represent provider billing.
Validation
just check: passed.c378d255ea6155d5dcdd91f31ded9bd24ad9d446: 1750 tests passed on both Python 3.12 and Python 3.13, including coverage gates.Pull Request Checklist
Publication remains in #413; plugin and deployment verification remain in #387.
langgenius/dify-official-plugins#4156 must be reconciled with langgenius/dify-official-plugins#4034 before those candidates adopt the final SDK 0.11 release.