Skip to content

fix: preserve extra request fields when model name is remapped#2384

Open
octo-patch wants to merge 1 commit into
songquanpeng:mainfrom
octo-patch:fix/issue-2295-preserve-extra-fields-model-remap
Open

fix: preserve extra request fields when model name is remapped#2384
octo-patch wants to merge 1 commit into
songquanpeng:mainfrom
octo-patch:fix/issue-2295-preserve-extra-fields-model-remap

Conversation

@octo-patch

Copy link
Copy Markdown

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 parsed GeneralOpenAIRequest struct. Any unknown fields sent by the client — such as enable_search, enable_thinking, or other provider-specific params added via the OpenAI Python SDK's extra_body mechanism — were silently dropped in that struct → JSON round-trip, so they never reached the upstream provider.

Without the fix, a call like:

client.chat.completions.create(
    model="hy-dsc",
    messages=[...],
    extra_body={"enable_search": True},
)

would strip enable_search from 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 the model field 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

  • Configured a channel with model mapping {"alias-model": "real-model"}.
  • Sent a request with model=alias-model and an extra field enable_search=true in the body.
  • Verified the upstream received model=real-model and enable_search=true.
  • Verified that requests without model mapping still pass through the body untouched (existing path unchanged).
  • Verified that requests requiring full conversion (forced system prompt, Baichuan channels, EnforceIncludeUsage) still use the full conversion path.

…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>
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.

使用模型重定向功能构造请求时,会丢失extra_body信息

1 participant