mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-22 01:55:27 -04:00
[PR #1279] [MERGED] fix(openai_api_compatible): Ensure JSON schema compatibility #1813
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/langgenius/dify-official-plugins/pull/1279
Author: @xuzijie1995
Created: 7/14/2025
Status: ✅ Merged
Merged: 7/14/2025
Merged by: @crazywoola
Base:
main← Head:fix/openai-structured-output📝 Commits (1)
da10e93fix(openai_api_compatible): Ensure JSON schema compatibility📊 Changes
2 files changed (+26 additions, -3 deletions)
View changed files
📝
models/openai_api_compatible/manifest.yaml(+1 -1)📝
models/openai_api_compatible/models/llm/llm.py(+25 -2)📄 Description
Title:
fix(openai_api_compatible): Ensure structured output for 'json_schema' modeProblem:
OpenAI-compatible models (e.g., GPT-4o) were failing to produce correct structured output when Dify's
response_format: 'json_schema'mode was used. The root cause was twofold:OAICompatLargeLanguageModel) does not natively support the'json_schema'parameter and only recognizes'json_object'.Solution:
This commit introduces a compatibility adapter within the
_invokemethod to intercept and translate these requests correctly.response_formatfrom the internal'json_schema'to the standard'json_object', enabling the model's JSON mode.json_schemaparameter directly into the system prompt, providing explicit, actionable instructions to the model.json_schemaparameter is preserved (not popped) to ensure forward compatibility with other potential models that might have their own way of handling it.Result:
This fix ensures reliable structured output for all OpenAI-compatible models using this feature. It is fully backward-compatible, as the logic only activates when
'json_schema'is explicitly requested, leaving all other operations unaffected.Related Issues or Context
This change is needed to correctly support Dify's native structured output feature (
response_format: 'json_schema') with modern OpenAI-compatible models like GPT-4o, which were previously failing to adhere to the provided schema.Dify Issue:#21767
This PR contains Changes to Non-LLM Models Plugin
This PR contains Changes to LLM Models Plugin
Version Control (Any Changes to the Plugin Will Require Bumping the Version)
VersionField, Not in Meta Section)Dify Plugin SDK Version
dify_plugin>=0.3.0,<0.5.0is in requirements.txt (SDK docs)Environment Verification (If Any Code Changes)
Local Deployment Environment
1.6.0I have Tested My Changes on Local Deployment Dify with a Clean Environment That Matches the Production Configuration.SaaS Environment
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.