Fix NVIDIA requests missing max_tokens#9207
Conversation
There was a problem hiding this comment.
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.
Summary
max_tokens=8192max_tokensvalueRoot cause
Some NVIDIA NIM models, including MiniMax M3, return an empty
choiceslist whenmax_tokensis omitted. AstrBot's prepared payload only containedmessagesandmodel, so both provider connectivity checks and regular requests could fail unless users manually added the field throughcustom_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_tokensfor 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.pygit diff --checkFixes #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:
Enhancements:
Tests: