fix(ai-chat): respect max_tokens parameter and model limit in MoonshotProvider#3410
Open
Rajeev91691 wants to merge 1 commit into
Open
fix(ai-chat): respect max_tokens parameter and model limit in MoonshotProvider#3410Rajeev91691 wants to merge 1 commit into
Rajeev91691 wants to merge 1 commit into
Conversation
…tProvider Fixes HeyPuter#3408 by destructuring max_tokens from ICompleteArguments in MoonshotProvider.complete() and passing max_tokens || modelUsed.max_tokens || 1000 instead of hardcoding 1000. This ensures thinking models such as Kimi K3 have sufficient output token budget and do not hit early length truncation.
|
|
Member
|
hi @Rajeev91691 could you sign the CLA? |
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 #3408
Summary
In
MoonshotProvider.ts,complete()hardcodedmax_tokens: 1000when invoking the Moonshot API and ignored themax_tokensargument inICompleteArguments.Because thinking models like Kimi K3 perform internal reasoning steps before generating output text, they consume tokens during reasoning. With a hardcoded 1000-token limit, Kimi K3 exhausts its token budget during thinking and returns
finish_reason: "length"with no output text.Changes
max_tokensfromICompleteArgumentsinMoonshotProvider.complete().max_tokens: max_tokens || modelUsed.max_tokens || 1000to allow caller-specifiedmax_tokenswhile defaulting to the model's configured max token limit (modelUsed.max_tokens).MoonshotProvider.test.tsto verifymax_tokenspass-through and fallback behavior.Testing
Ran unit test suite via
npm run test:backend:✓ src/backend/drivers/ai-chat/providers/moonshot/MoonshotProvider.test.ts (22 tests passed)