Skip to content

feat(providers): route non-standard generate_kwargs into extra_body#4689

Merged
lalaliat merged 3 commits into
agentscope-ai:mainfrom
leoleils:feat/extra-body-generate-kwargs
Jun 2, 2026
Merged

feat(providers): route non-standard generate_kwargs into extra_body#4689
lalaliat merged 3 commits into
agentscope-ai:mainfrom
leoleils:feat/extra-body-generate-kwargs

Conversation

@leoleils

@leoleils leoleils commented May 26, 2026

Copy link
Copy Markdown
Contributor

Description

Non-standard provider parameters (e.g. DashScope's enable_search) configured in generate_kwargs are silently rejected by the OpenAI Python SDK, because client.chat.completions.create() does not accept unknown keyword arguments.

This PR adds an __init__ override in OpenAIChatModelCompat that automatically moves unrecognized generate_kwargs keys into extra_body, so they are correctly included in the HTTP request body.

Users can now simply configure {"enable_search": true} in a model's generate_kwargs and DashScope web search will work.

Related Issue: Fixes #4688

Security Considerations: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Core / Backend (app, agents, config, providers, utils, local_models)
  • Console (frontend web UI)
  • Channels (DingTalk, Feishu, QQ, Discord, iMessage, etc.)
  • Skills
  • CLI
  • Documentation (website)
  • Tests
  • CI/CD
  • Scripts / Deploy

Checklist

  • I ran pre-commit run --all-files locally and it passes
  • If pre-commit auto-fixed files, I committed those changes and reran checks
  • I ran tests locally (pytest or as relevant) and they pass
  • Documentation updated (if needed)
  • Ready for review

Testing

  1. Configure {"enable_search": true} in a DashScope model's generate_kwargs via UI
  2. Send a query requiring real-time info (e.g. "今天的新闻")
  3. Verify model response includes web search results
  4. Verify standard params (temperature, max_tokens) still work as top-level kwargs
  5. Verify explicit {"extra_body": {"enable_search": true}} form also works

Local Verification Evidence

pre-commit run --all-files
# All passed

pytest
# Collection errors in unrelated test files (pre-existing)

Additional Notes

The _OPENAI_CREATE_PARAMS frozenset is derived from the OpenAI Python SDK's AsyncCompletions.create() method signature. If the SDK adds new parameters in future versions, they would simply remain as top-level kwargs (correct behavior) — no update needed unless a new SDK param name collides with a provider-specific param name (extremely unlikely).

DashScope's web search (enable_search) and other provider-specific
parameters must be passed via the OpenAI SDK's extra_body parameter,
not as top-level kwargs. The SDK's create() method rejects unknown
keyword arguments with TypeError.

This adds an __init__ override in OpenAIChatModelCompat that
automatically moves any generate_kwargs keys not recognized by the
OpenAI SDK into extra_body, so they are correctly included in the
HTTP request body. Users can now simply configure
{"enable_search": true} in generate_kwargs and it will work.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Welcome to QwenPaw! 🐾

Hi @leoleils, this is your 9th Pull Request.

📋 About PR Template

To help maintainers review your PR faster, please make sure to include:

  • Description - What this PR does and why
  • Type of Change - Bug fix / Feature / Breaking change / Documentation / Refactoring
  • Component(s) Affected - Core / Console / Channels / Skills / CLI / Documentation / Tests / CI/CD / Scripts
  • Checklist:
    • Run and pass pre-commit run --all-files
    • Run and pass relevant tests (pytest or as applicable)
    • Update documentation if needed
  • Testing - How to test these changes
  • Local Verification Evidence:
    pre-commit run --all-files
    # paste summary result
    
    pytest
    # paste summary result

Complete PR information helps speed up the review process. You can edit the PR description to add these details.

🙌 Join Developer Community

Thanks so much for your contribution! We'd love to invite you to join the official QwenPaw developer group! You can find the Discord and DingTalk group links under the "Developer Community" section on our docs page:
https://qwenpaw.agentscope.io/docs/community

We truly appreciate your enthusiasm—and look forward to your future contributions! 😊

We'll review your PR soon.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@leoleils leoleils temporarily deployed to maintainer-approved May 26, 2026 05:38 — with GitHub Actions Inactive
@leoleils leoleils changed the title feat(providers): route non-standard generate_kwargs into extra_body feat(providers): 支持非标准 generate_kwargs 参数自动路由到 extra_body May 26, 2026
@leoleils leoleils changed the title feat(providers): 支持非标准 generate_kwargs 参数自动路由到 extra_body feat(providers): route non-standard generate_kwargs into extra_body May 26, 2026
Comment thread src/qwenpaw/providers/openai_chat_model_compat.py
@leoleils leoleils requested a deployment to maintainer-approved May 30, 2026 12:29 — with GitHub Actions Waiting
@leoleils leoleils force-pushed the feat/extra-body-generate-kwargs branch from e70bb7b to 9262b25 Compare May 30, 2026 12:50
@leoleils leoleils requested a deployment to maintainer-approved May 30, 2026 12:50 — with GitHub Actions Waiting
@leoleils leoleils force-pushed the feat/extra-body-generate-kwargs branch from 9262b25 to 562a83b Compare May 30, 2026 12:52
@leoleils leoleils requested a deployment to maintainer-approved May 30, 2026 12:52 — with GitHub Actions Waiting
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@leoleils leoleils force-pushed the feat/extra-body-generate-kwargs branch from 562a83b to 73cd3f2 Compare May 30, 2026 13:02
@leoleils leoleils temporarily deployed to maintainer-approved May 30, 2026 13:02 — with GitHub Actions Inactive
@lalaliat lalaliat self-assigned this Jun 2, 2026

@lalaliat lalaliat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Feature]: Support non-standard provider params (e.g. DashScope enable_search) via extra_body

2 participants