fix: preserve extra request fields when model name is remapped#2384
Open
octo-patch wants to merge 1 commit into
Open
fix: preserve extra request fields when model name is remapped#2384octo-patch wants to merge 1 commit into
octo-patch wants to merge 1 commit into
Conversation
…ongquanpeng#2295) When a channel has model mapping configured, the relay controller was re-serialising the request from the parsed GeneralOpenAIRequest struct. Any unknown fields sent by the client (e.g. enable_search, thinking, or other provider-specific params added via the OpenAI SDK extra_body mechanism) were silently dropped in that round-trip. Fix: for OpenAI-type channels where the only required transformation is a model name substitution, patch the model field directly in the raw request body instead of going through a full parse→marshal cycle. This preserves all extra fields so they reach the upstream provider unchanged. Co-Authored-By: Octopus <liyuan851277048@icloud.com>
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.
Fixes #2295
Problem
When a channel has model mapping configured (e.g.
{"hy-dsc": "deepseek-v3-0324"}), relay/controller/text.go was re-serialising the request from the parsedGeneralOpenAIRequeststruct. Any unknown fields sent by the client — such asenable_search,enable_thinking, or other provider-specific params added via the OpenAI Python SDK'sextra_bodymechanism — were silently dropped in that struct → JSON round-trip, so they never reached the upstream provider.Without the fix, a call like:
would strip
enable_searchfrom the forwarded body, breaking Tencent Cloud DeepSeek's web-search feature and similar provider extensions.Solution
For OpenAI-type channels where the only transformation needed is a model name substitution (no forced system prompt, no
EnforceIncludeUsage, not Baichuan), patch themodelfield directly in the cached raw request body instead of going through a full parse → marshal cycle. This preserves all extra/unknown fields so they reach the upstream provider unchanged. The code falls back to the existing full-conversion path if the raw body is unavailable or unparseable.Testing
{"alias-model": "real-model"}.model=alias-modeland an extra fieldenable_search=truein the body.model=real-modelandenable_search=true.EnforceIncludeUsage) still use the full conversion path.