Skip to content

fix(ai-chat): respect max_tokens parameter and model limit in MoonshotProvider#3410

Open
Rajeev91691 wants to merge 1 commit into
HeyPuter:mainfrom
Rajeev91691:fix/moonshot-max-tokens
Open

fix(ai-chat): respect max_tokens parameter and model limit in MoonshotProvider#3410
Rajeev91691 wants to merge 1 commit into
HeyPuter:mainfrom
Rajeev91691:fix/moonshot-max-tokens

Conversation

@Rajeev91691

Copy link
Copy Markdown

Fixes #3408

Summary

In MoonshotProvider.ts, complete() hardcoded max_tokens: 1000 when invoking the Moonshot API and ignored the max_tokens argument in ICompleteArguments.

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

  • Destructured max_tokens from ICompleteArguments in MoonshotProvider.complete().
  • Passed max_tokens: max_tokens || modelUsed.max_tokens || 1000 to allow caller-specified max_tokens while defaulting to the model's configured max token limit (modelUsed.max_tokens).
  • Updated unit tests in MoonshotProvider.test.ts to verify max_tokens pass-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)

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

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Salazareo

Copy link
Copy Markdown
Member

hi @Rajeev91691 could you sign the CLA?

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.

kimi k3 stops responding with finish_reason: length

3 participants