diff --git a/.changeset/kimi-thinking-off-temperature.md b/.changeset/kimi-thinking-off-temperature.md new file mode 100644 index 000000000..50409163f --- /dev/null +++ b/.changeset/kimi-thinking-off-temperature.md @@ -0,0 +1,6 @@ +--- +"@moonshot-ai/kosong": patch +"@moonshot-ai/kimi-code": patch +--- + +Set Kimi requests to temperature 0.6 when thinking is disabled. diff --git a/packages/kosong/src/providers/kimi.ts b/packages/kosong/src/providers/kimi.ts index ef53eca7c..54fe56aff 100644 --- a/packages/kosong/src/providers/kimi.ts +++ b/packages/kosong/src/providers/kimi.ts @@ -82,6 +82,19 @@ export interface ExtraBody { thinking?: ThinkingConfig; [key: string]: unknown; } + +function isRecord(value: unknown): value is Record { + return typeof value === 'object' && value !== null && !Array.isArray(value); +} + +function applyDisabledThinkingTemperatureDefault(params: Record): void { + if (params['temperature'] !== undefined) return; + const thinking = params['thinking']; + if (isRecord(thinking) && thinking['type'] === 'disabled') { + params['temperature'] = 0.6; + } +} + const KIMI_TOOL_CALL_ID_POLICY: ToolCallIdPolicy = { normalize: (id) => sanitizeToolCallId(id, 64), maxLength: 64, @@ -475,6 +488,7 @@ export class KimiChatProvider implements ChatProvider { ...requestKwargs, ...(extraBody as Record | undefined), }; + applyDisabledThinkingTemperatureDefault(createParams); if (tools.length > 0) { createParams['tools'] = tools.map((t) => convertTool(t)); diff --git a/packages/kosong/test/kimi.test.ts b/packages/kosong/test/kimi.test.ts index f309b2030..f12647ee7 100644 --- a/packages/kosong/test/kimi.test.ts +++ b/packages/kosong/test/kimi.test.ts @@ -722,9 +722,24 @@ describe('KimiChatProvider', () => { expect(body['reasoning_effort']).toBeUndefined(); expect(body['thinking']).toEqual({ type: 'disabled' }); + expect(body['temperature']).toBe(0.6); expect(body['extra_body']).toBeUndefined(); }); + it('does not overwrite an explicit temperature when thinking is off', async () => { + const provider = createProvider() + .withGenerationKwargs({ temperature: 0.7 }) + .withThinking('off'); + const history: Message[] = [ + { role: 'user', content: [{ type: 'text', text: 'Think' }], toolCalls: [] }, + ]; + const body = await captureRequestBody(provider, '', [], history); + + expect(body['reasoning_effort']).toBeUndefined(); + expect(body['thinking']).toEqual({ type: 'disabled' }); + expect(body['temperature']).toBe(0.7); + }); + it('thinkingEffort property reflects current state', () => { const provider = createProvider(); expect(provider.thinkingEffort).toBeNull();