Skip to content
Draft
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
6 changes: 6 additions & 0 deletions .changeset/kimi-thinking-off-temperature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@moonshot-ai/kosong": patch
"@moonshot-ai/kimi-code": patch
---

Set Kimi requests to temperature 0.6 when thinking is disabled.
14 changes: 14 additions & 0 deletions packages/kosong/src/providers/kimi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ export interface ExtraBody {
thinking?: ThinkingConfig;
[key: string]: unknown;
}

function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}

function applyDisabledThinkingTemperatureDefault(params: Record<string, unknown>): 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,
Expand Down Expand Up @@ -475,6 +488,7 @@ export class KimiChatProvider implements ChatProvider {
...requestKwargs,
...(extraBody as Record<string, unknown> | undefined),
};
applyDisabledThinkingTemperatureDefault(createParams);

if (tools.length > 0) {
createParams['tools'] = tools.map((t) => convertTool(t));
Expand Down
15 changes: 15 additions & 0 deletions packages/kosong/test/kimi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down