Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/kosong/src/providers/kimi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,12 @@ export class KimiChatProvider implements ChatProvider {
reasoningEffort = 'high';
break;
}
return this._withGenerationKwargs({ reasoning_effort: reasoningEffort }).withExtraBody({
// Moonshot API requires temperature=1.0 when thinking is enabled and
// temperature=0.6 when thinking is disabled. Set a default here so users
// don't hit 400 errors after toggling thinking off; KIMI_MODEL_TEMPERATURE
// env var (applied later via applyKimiEnvSamplingParams) can still override.
const temperature = effort === 'off' ? 0.6 : 1.0;
return this._withGenerationKwargs({ reasoning_effort: reasoningEffort, temperature }).withExtraBody({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve configured Kimi temperatures across thinking setup

When a Kimi provider is constructed with generationKwargs.temperature, this call overwrites it because ConfigState.provider builds providers as createProvider(this.providerConfig).withThinking(...). That means any caller using the public ProviderConfig/KimiOptions temperature setting loses their explicit sampling value unless they also reapply it later via the env override path; previously withThinking only touched thinking fields. Please only apply this auto temperature when no explicit temperature has already been configured, or otherwise preserve an explicit override consistently with the env-var override behavior.

Useful? React with 👍 / 👎.

thinking,
});
}
Expand Down
31 changes: 23 additions & 8 deletions packages/kosong/test/kimi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ describe('KimiChatProvider', () => {
thinking: { type: 'enabled' },
},
max_tokens: 512,
temperature: 1.0,
});
});

Expand Down Expand Up @@ -736,15 +737,29 @@ describe('KimiChatProvider', () => {
expect(withLow.thinkingEffort).toBe('low');
});

it('replaces the previous thinking effort when called again', () => {
const provider = createProvider().withThinking('high').withThinking('off');
it('sets temperature=1.0 when thinking is on and temperature=0.6 when off', async () => {
const onProvider = createProvider().withThinking('high');
const offProvider = createProvider().withThinking('off');

expect(getGenerationState(provider)).toEqual({
reasoning_effort: undefined,
extra_body: {
thinking: { type: 'disabled' },
},
});
const history: Message[] = [
{ role: 'user', content: [{ type: 'text', text: 'Hi' }], toolCalls: [] },
];

const onBody = await captureRequestBody(onProvider, '', [], history);
expect(onBody['temperature']).toBe(1.0);

const offBody = await captureRequestBody(offProvider, '', [], history);
expect(offBody['temperature']).toBe(0.6);
});

it('preserves explicit temperature via env var override after withThinking', () => {
// Simulates applyKimiEnvSamplingParams overriding the default:
// withThinking('off') sets 0.6, then env param sets 0.8.
const provider = createProvider()
.withThinking('off')
.withGenerationKwargs({ temperature: 0.8 });

expect(getGenerationState(provider).temperature).toBe(0.8);
});
});

Expand Down
Loading