All files / src/models/adapters kimi.ts

100% Statements 19/19
100% Branches 9/9
100% Functions 2/2
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38  10x   10x 10x 10x 10x   10x       73x 94x 88x   6x 6x   73x     10x 10x     10x     73x 73x 71x   2x        
import { NimChatMessage } from "../../types";
import { BaseModelAdapter } from "./base";
 
export class KimiAdapter extends BaseModelAdapter {
  readonly idPattern = /(^|[\/_-])kimi([\/_-]|$)/i;
  readonly defaultTemperature = 0.2;
  readonly toolTemperature = 0.1;
  readonly toolSystemMessage =
    "You are an expert AI programming assistant. Provide correct, concise, production-ready code. When tools are available, answer with concise user-facing text or a native tool call. Only emit tool calls through the designated tool_calls field; never write JSON arguments inline as markdown, backtick fences, or plain text. Every tool call must include ALL required arguments with correct types. Do not reveal chain-of-thought, reasoning scratchpads, or internal reasoning markers in the user-visible response.";
 
  applyMessagesWorkaround(messages: NimChatMessage[]): NimChatMessage[] {
    let patchedMessages: NimChatMessage[] | undefined;
    for (const [index, msg] of messages.entries()) {
      if (msg.role !== "assistant" || msg.reasoning_content) {
        continue;
      }
      patchedMessages ??= [...messages];
      patchedMessages[index] = { ...msg, reasoning_content: " " };
    }
    return patchedMessages ?? messages;
  }
 
  readonly supportedReasoningModes = ["none", "on"];
  readonly reasoningParameterFormat = "chat_template_kwargs" as const;
  // Native tool_calls are preferred, while OpenAI-style text control tokens
  // remain accepted as a compatibility/recovery fallback.
  readonly toolCallProtocol = "native-and-text" as const;
 
  applyReasoningMode(request: import("../../types").NimChatRequest, mode: string): void {
    request.chat_template_kwargs = request.chat_template_kwargs || {};
    if (mode === "none") {
      request.chat_template_kwargs.thinking = false;
    } else {
      request.chat_template_kwargs.thinking = true;
    }
  }
}