Skip to content

fix(model)!: validate completion input and correct fallback usage - #411

Merged
WH-2099 merged 3 commits into
mainfrom
fix/validate-completion-content
Oct 31, 2026
Merged

WH-2099 merged 3 commits into
mainfrom
fix/validate-completion-content

Conversation

@WH-2099

@WH-2099 WH-2099 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

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 world followed by Answer now 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 InvokeError before HTTP; direct private _generate() calls receive ValueError.
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 optional tools parameter.
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.
  • SDK CI at c378d255ea6155d5dcdd91f31ded9bd24ad9d446: 1750 tests passed on both Python 3.12 and Python 3.13, including coverage gates.
  • Static checks, title validation, and CodeQL passed for the code update.
  • Tests exercise public invocation through a local HTTP server, text and media boundaries, independent input snapshots, complete history, tool definitions and outputs, missing/partial/zero usage, calculated prices, and explicit tool choice.
  • The companion plugin draft passes 320 targeted tests against the pinned SDK build, retaining three existing expected failures for ambiguous Tokener fragments.
  • No live model inference, Marketplace publication, or reporter-installed package verification was performed.

Pull Request Checklist

  • Compatibility impact and the target SDK version are documented in README and this description.
  • Affected official provider overrides have a coordinated migration draft.
  • Required static and test checks pass.
  • Relevant documentation is updated.
  • SDK publication and plugin deployment verification are complete.

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.

@WH-2099 WH-2099 self-assigned this Oct 29, 2026
@WH-2099 WH-2099 changed the title fix(model): validate completion prompt content fix(model)!: validate completion input and correct fallback usage Oct 31, 2026
@WH-2099
WH-2099 marked this pull request as ready for review October 31, 2026 10:19
@WH-2099
WH-2099 requested review from Mairuis and a balanced review from Copilot October 31, 2026 10:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@WH-2099
WH-2099 removed the request for review from Mairuis October 31, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants