Skip to content

Fix NVIDIA requests missing max_tokens#9207

Closed
Last-emo-boy wants to merge 1 commit into
AstrBotDevs:masterfrom
Last-emo-boy:agent/fix-nvidia-max-tokens
Closed

Fix NVIDIA requests missing max_tokens#9207
Last-emo-boy wants to merge 1 commit into
AstrBotDevs:masterfrom
Last-emo-boy:agent/fix-nvidia-max-tokens

Conversation

@Last-emo-boy

@Last-emo-boy Last-emo-boy commented Jul 11, 2026

Copy link
Copy Markdown

Summary

  • provide NVIDIA OpenAI-compatible providers with a default max_tokens=8192
  • preserve a user-supplied max_tokens value
  • add regression coverage for both the default and override behavior

Root cause

Some NVIDIA NIM models, including MiniMax M3, return an empty choices list when max_tokens is omitted. AstrBot's prepared payload only contained messages and model, so both provider connectivity checks and regular requests could fail unless users manually added the field through custom_extra_body.

The fix is limited to providers whose configured provider ID is nvidia, avoiding behavior changes for other OpenAI-compatible services.

User impact

NVIDIA users no longer need to manually configure max_tokens for affected models. Existing custom values still take precedence.

Validation

  • uv run --group dev pytest tests/test_openai_source.py -q — 60 passed
  • .venv/bin/ruff check astrbot/core/provider/sources/openai_source.py tests/test_openai_source.py
  • git diff --check

Fixes #9206

Summary by Sourcery

Ensure NVIDIA OpenAI-compatible providers send a sensible default max_tokens value while preserving user overrides, and add regression tests for this behavior.

Bug Fixes:

  • Prevent NVIDIA NIM requests from failing due to missing max_tokens by applying a provider-specific default.

Enhancements:

  • Introduce provider-specific extra body handling for NVIDIA to align request payloads with model expectations.

Tests:

  • Add async tests verifying that NVIDIA providers receive a default max_tokens value and that custom max_tokens settings are preserved.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a provider-specific override for NVIDIA NIM models in openai_source.py to set a default max_tokens value of 8192 when it is not explicitly configured. This prevents certain models, such as MiniMax M3, from returning empty choices lists. Additionally, corresponding unit tests have been added to verify that the default value is correctly applied and that custom values are preserved. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@Last-emo-boy Last-emo-boy deleted the agent/fix-nvidia-max-tokens branch July 11, 2026 08:04
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.

[Bug] NVIDIA Provider 测试连通性报错 "OpenAI completion has no choices" ——max_tokens 未正确写入请求 payload

1 participant