|
1 | | -import { LITELLM_PRESERVE_REASONING_PATTERN } from "../providers/lite-llm.js" |
| 1 | +import { isLiteLLMPreserveReasoningModel, LITELLM_PRESERVE_REASONING_MODEL_IDS } from "../providers/lite-llm.js" |
2 | 2 |
|
3 | | -describe("LITELLM_PRESERVE_REASONING_PATTERN", () => { |
4 | | - it("matches known DeepSeek reasoning aliases", () => { |
5 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("deepseek-v4-flash")).toBe(true) |
6 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("deepseek-v4-pro")).toBe(true) |
7 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("deepseek/deepseek-reasoner")).toBe(true) |
8 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("deepseek-v4-mini")).toBe(false) |
| 3 | +describe("LiteLLM preserveReasoning model detection", () => { |
| 4 | + it("matches every explicitly listed model id", () => { |
| 5 | + for (const modelId of LITELLM_PRESERVE_REASONING_MODEL_IDS) { |
| 6 | + expect(isLiteLLMPreserveReasoningModel(modelId)).toBe(true) |
| 7 | + } |
9 | 8 | }) |
10 | 9 |
|
11 | | - it("matches known MiMo reasoning aliases", () => { |
12 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("mimo-v2.5")).toBe(true) |
13 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("mimo-v2.5-pro")).toBe(true) |
14 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("mimo-v2.6")).toBe(false) |
| 10 | + it("does not contain duplicate model ids", () => { |
| 11 | + expect(new Set(LITELLM_PRESERVE_REASONING_MODEL_IDS).size).toBe(LITELLM_PRESERVE_REASONING_MODEL_IDS.length) |
15 | 12 | }) |
16 | 13 |
|
17 | | - it("matches known Kimi K2 reasoning aliases across routed providers", () => { |
18 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("bedrock/moonshot.kimi-k2-thinking")).toBe(true) |
19 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("fireworks_ai/accounts/fireworks/models/kimi-k2p7-code")).toBe( |
20 | | - true, |
21 | | - ) |
22 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("kimi-k2.7-code")).toBe(true) |
23 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("kimi-k2.6")).toBe(false) |
| 14 | + it("matches provider-prefixed routed model names by their final segment", () => { |
| 15 | + expect(isLiteLLMPreserveReasoningModel("deepseek/deepseek-reasoner")).toBe(true) |
| 16 | + expect(isLiteLLMPreserveReasoningModel("bedrock/moonshot.kimi-k2-thinking")).toBe(true) |
| 17 | + expect(isLiteLLMPreserveReasoningModel("fireworks_ai/accounts/fireworks/models/kimi-k2p7-code")).toBe(true) |
24 | 18 | }) |
25 | 19 |
|
26 | | - it("matches MiniMax M2/M3 aliases but not other MiniMax generations", () => { |
27 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("minimax-m2")).toBe(true) |
28 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("minimax.m3")).toBe(true) |
29 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("minimax-m2.5")).toBe(true) |
30 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("minimax-m2-highspeed")).toBe(true) |
31 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("minimax-m2-stable")).toBe(true) |
32 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("minimax-m4")).toBe(false) |
33 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("minimax-m1")).toBe(false) |
| 20 | + it("matches case-insensitively", () => { |
| 21 | + expect(isLiteLLMPreserveReasoningModel("MiniMax-M2.7-Highspeed")).toBe(true) |
| 22 | + expect(isLiteLLMPreserveReasoningModel("GLM-5.2")).toBe(true) |
34 | 23 | }) |
35 | 24 |
|
36 | | - it("matches GLM-4.7 but excludes the flash variants", () => { |
37 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("glm-4.7")).toBe(true) |
38 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("glm-4.7-flash")).toBe(false) |
39 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("glm-4.7-flashx")).toBe(false) |
40 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("glm-4.8")).toBe(false) |
41 | | - }) |
42 | | - |
43 | | - it("matches GLM-5 variants but excludes the flash variant", () => { |
44 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("glm-5")).toBe(true) |
45 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("glm-5.1")).toBe(true) |
46 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("glm-5.2")).toBe(true) |
47 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("glm-5-turbo")).toBe(true) |
48 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("glm-5.1-turbo")).toBe(true) |
49 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("glm-5-flash")).toBe(false) |
50 | | - }) |
51 | | - |
52 | | - it("matches curated Qwen3 plus/max aliases used by opencode-go", () => { |
53 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("qwen3.7-plus")).toBe(true) |
54 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("qwen3.6-max")).toBe(true) |
55 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("qwen3.5-plus")).toBe(false) |
56 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("qwen3.7-mini")).toBe(false) |
| 25 | + it("does not match model ids that merely contain a known family as a substring", () => { |
| 26 | + expect(isLiteLLMPreserveReasoningModel("deepseek-v4-mini")).toBe(false) |
| 27 | + expect(isLiteLLMPreserveReasoningModel("mimo-v2.6")).toBe(false) |
| 28 | + expect(isLiteLLMPreserveReasoningModel("kimi-k2.6")).toBe(false) |
| 29 | + expect(isLiteLLMPreserveReasoningModel("kimi-k2.7-code")).toBe(false) |
| 30 | + expect(isLiteLLMPreserveReasoningModel("minimax-m4")).toBe(false) |
| 31 | + expect(isLiteLLMPreserveReasoningModel("minimax-m1")).toBe(false) |
| 32 | + expect(isLiteLLMPreserveReasoningModel("glm-4.7-flash")).toBe(false) |
| 33 | + expect(isLiteLLMPreserveReasoningModel("glm-4.7-flashx")).toBe(false) |
| 34 | + expect(isLiteLLMPreserveReasoningModel("glm-5-flash")).toBe(false) |
| 35 | + expect(isLiteLLMPreserveReasoningModel("glm-4.8")).toBe(false) |
| 36 | + expect(isLiteLLMPreserveReasoningModel("qwen3.5-plus")).toBe(false) |
| 37 | + expect(isLiteLLMPreserveReasoningModel("qwen3.7-mini")).toBe(false) |
| 38 | + expect(isLiteLLMPreserveReasoningModel("qwen3.6-max")).toBe(false) |
57 | 39 | }) |
58 | 40 |
|
59 | 41 | it("does not match unrelated model names", () => { |
60 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("gpt-4")).toBe(false) |
61 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("claude-3-opus")).toBe(false) |
62 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("")).toBe(false) |
63 | | - }) |
64 | | - |
65 | | - it("matches when the fragment appears anywhere in a combined alias/routed-model string", () => { |
66 | | - // Mirrors how litellm.ts calls it: `${modelName} ${litellmModelName}` |
67 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("my-deepseek-alias deepseek/deepseek-reasoner")).toBe(true) |
68 | | - expect(LITELLM_PRESERVE_REASONING_PATTERN.test("my-gpt4-alias openai/gpt-4")).toBe(false) |
| 42 | + expect(isLiteLLMPreserveReasoningModel("gpt-4")).toBe(false) |
| 43 | + expect(isLiteLLMPreserveReasoningModel("claude-3-opus")).toBe(false) |
| 44 | + expect(isLiteLLMPreserveReasoningModel("")).toBe(false) |
| 45 | + expect(isLiteLLMPreserveReasoningModel(undefined)).toBe(false) |
69 | 46 | }) |
70 | 47 | }) |
0 commit comments