Skip to content

Commit 0ff6960

Browse files
committed
Add Kimi K2 model to Grok along with fixes to context condensing math
Cherry picked RooCodeInc/Roo-Code#5717
1 parent ab1e965 commit 0ff6960

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

.changeset/lovely-carpets-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"kilo-code": patch
3+
---
4+
5+
Add Kimi K2 model to Grok (thanks @mrubens)

packages/types/src/providers/groq.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type GroqModelId =
1010
| "qwen-qwq-32b"
1111
| "qwen/qwen3-32b"
1212
| "deepseek-r1-distill-llama-70b"
13+
| "moonshotai/kimi-k2-instruct"
1314

1415
export const groqDefaultModelId: GroqModelId = "llama-3.3-70b-versatile" // Defaulting to Llama3 70B Versatile
1516

@@ -87,4 +88,13 @@ export const groqModels = {
8788
outputPrice: 0.99,
8889
description: "DeepSeek R1 Distill Llama 70B model, 128K context.",
8990
},
91+
"moonshotai/kimi-k2-instruct": {
92+
maxTokens: 131072,
93+
contextWindow: 131072,
94+
supportsImages: false,
95+
supportsPromptCache: false,
96+
inputPrice: 1.0,
97+
outputPrice: 3.0,
98+
description: "Moonshot AI Kimi K2 Instruct 1T model, 128K context.",
99+
},
90100
} as const satisfies Record<string, ModelInfo>

src/core/task/Task.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { ClineAskResponse } from "../../shared/WebviewMessage"
4242
import { defaultModeSlug } from "../../shared/modes"
4343
import { DiffStrategy } from "../../shared/tools"
4444
import { EXPERIMENT_IDS, experiments } from "../../shared/experiments"
45+
import { getModelMaxOutputTokens } from "../../shared/api"
4546

4647
// services
4748
import { UrlContentFetcher } from "../../services/browser/UrlContentFetcher"
@@ -1824,15 +1825,13 @@ export class Task extends EventEmitter<ClineEvents> {
18241825
const { contextTokens } = this.getTokenUsage()
18251826

18261827
if (contextTokens) {
1827-
// Default max tokens value for thinking models when no specific
1828-
// value is set.
1829-
const DEFAULT_THINKING_MODEL_MAX_TOKENS = 16_384
1830-
18311828
const modelInfo = this.api.getModel().info
18321829

1833-
const maxTokens = modelInfo.supportsReasoningBudget
1834-
? this.apiConfiguration.modelMaxTokens || DEFAULT_THINKING_MODEL_MAX_TOKENS
1835-
: modelInfo.maxTokens
1830+
const maxTokens = getModelMaxOutputTokens({
1831+
modelId: this.api.getModel().id,
1832+
model: modelInfo,
1833+
settings: this.apiConfiguration,
1834+
})
18361835

18371836
const contextWindow = modelInfo.contextWindow
18381837

src/shared/api.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,12 @@ export const getModelMaxOutputTokens = ({
182182
return ANTHROPIC_DEFAULT_MAX_TOKENS
183183
}
184184

185-
// If maxTokens is 0 or undefined, fall back to 20% of context window
186-
// This matches the sliding window logic
187-
return model.maxTokens || Math.ceil(model.contextWindow * 0.2)
185+
// If maxTokens is 0 or undefined or the full context window, fall back to 20% of context window
186+
if (model.maxTokens && model.maxTokens !== model.contextWindow) {
187+
return model.maxTokens
188+
} else {
189+
return Math.ceil(model.contextWindow * 0.2)
190+
}
188191
}
189192

190193
// GetModelsOptions

0 commit comments

Comments
 (0)