Skip to content

Commit 96441c5

Browse files
authored
Merge branch 'main' into christiaan/costPerRequest
2 parents c2c0e16 + 471ce3c commit 96441c5

File tree

7 files changed

+40
-232
lines changed

7 files changed

+40
-232
lines changed

.changeset/angry-fans-mix.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+
Kilo Code provider now falls back to the default model when the selected model no longer exists

src/api/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import {
4545
} from "./providers"
4646
// kilocode_change start
4747
import { KilocodeOpenrouterHandler } from "./providers/kilocode-openrouter"
48-
import { KilocodeOllamaHandler } from "./providers/kilocode-ollama"
4948
// kilocode_change end
5049
import { NativeOllamaHandler } from "./providers/native-ollama"
5150

@@ -116,7 +115,7 @@ export function buildApiHandler(configuration: ProviderSettings): ApiHandler {
116115
case "openai":
117116
return new OpenAiHandler(options)
118117
case "ollama":
119-
return new KilocodeOllamaHandler(options)
118+
return new NativeOllamaHandler(options)
120119
case "lmstudio":
121120
return new LmStudioHandler(options)
122121
case "gemini":

src/api/providers/kilocode-ollama.ts

Lines changed: 0 additions & 223 deletions
This file was deleted.

src/api/providers/kilocode-openrouter.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,17 @@ export class KilocodeOpenrouterHandler extends OpenRouterHandler {
6262
let info = this.models[id]
6363
let defaultTemperature = 0
6464

65-
if (!this.models[id]) {
66-
id = openRouterDefaultModelId
67-
info = openRouterDefaultModelInfo
65+
if (!info) {
66+
const defaultInfo = this.models[this.defaultModel]
67+
if (defaultInfo) {
68+
console.warn(`${id} no longer exists, falling back to ${this.defaultModel}`)
69+
id = this.defaultModel
70+
info = defaultInfo
71+
} else {
72+
console.warn(`${id} no longer exists, falling back to ${openRouterDefaultModelId}`)
73+
id = openRouterDefaultModelId
74+
info = openRouterDefaultModelInfo
75+
}
6876
}
6977

7078
// If a specific provider is requested, use the endpoint for that provider.

src/api/providers/native-ollama.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { getOllamaModels } from "./fetchers/ollama"
88
import { XmlMatcher } from "../../utils/xml-matcher"
99
import type { SingleCompletionHandler, ApiHandlerCreateMessageMetadata } from "../index"
1010

11+
// kilocode_change start
12+
import { fetchWithTimeout } from "./kilocode/fetchWithTimeout"
13+
const OLLAMA_TIMEOUT_MS = 3_600_000
14+
// kilocode_change end
15+
1116
function convertToOllamaMessages(anthropicMessages: Anthropic.Messages.MessageParam[]): Message[] {
1217
const ollamaMessages: Message[] = []
1318

@@ -140,9 +145,18 @@ export class NativeOllamaHandler extends BaseProvider implements SingleCompletio
140145
private ensureClient(): Ollama {
141146
if (!this.client) {
142147
try {
148+
// kilocode_change start
149+
const headers = this.options.ollamaApiKey
150+
? { Authorization: this.options.ollamaApiKey } //Yes, this is weird, its not a Bearer token
151+
: undefined
152+
// kilocode_change end
153+
143154
this.client = new Ollama({
144155
host: this.options.ollamaBaseUrl || "http://localhost:11434",
145-
// Note: The ollama npm package handles timeouts internally
156+
// kilocode_change start
157+
fetch: fetchWithTimeout(OLLAMA_TIMEOUT_MS, headers),
158+
headers: headers,
159+
// kilocode_change end
146160
})
147161
} catch (error: any) {
148162
throw new Error(`Error creating Ollama client: ${error.message}`)

src/core/environment/getEnvironmentDetails.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { formatReminderSection } from "./reminder"
2525
import { OpenRouterHandler } from "../../api/providers/openrouter"
2626
import { TelemetryService } from "@roo-code/telemetry"
2727
import { t } from "../../i18n"
28-
import { KilocodeOllamaHandler } from "../../api/providers/kilocode-ollama"
28+
import { NativeOllamaHandler } from "../../api/providers/native-ollama"
2929
// kilocode_change end
3030

3131
export async function getEnvironmentDetails(cline: Task, includeFileDetails: boolean = false) {
@@ -212,7 +212,7 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
212212

213213
// kilocode_change start
214214
// Be sure to fetch the model information before we need it.
215-
if (cline.api instanceof OpenRouterHandler || cline.api instanceof KilocodeOllamaHandler) {
215+
if (cline.api instanceof OpenRouterHandler || cline.api instanceof NativeOllamaHandler) {
216216
try {
217217
await cline.api.fetchModel()
218218
} catch (e) {

webview-ui/src/components/kilocode/chat/ModelSelector.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@ export const ModelSelector = ({ currentApiConfigName, apiConfiguration, fallback
6565
return <span className="text-xs text-vscode-descriptionForeground opacity-70 truncate">{fallbackText}</span>
6666
}
6767

68+
const selectedModelNoLongerExistsButDefaultDoes =
69+
modelsIds.indexOf(selectedModelId) < 0 && modelsIds.indexOf(providerDefaultModel) >= 0
70+
71+
const currentValue = selectedModelNoLongerExistsButDefaultDoes ? providerDefaultModel : selectedModelId
72+
6873
return (
6974
<SelectDropdown
70-
value={selectedModelId}
75+
value={currentValue}
7176
disabled={disabled}
7277
title={t("chat:selectApiConfig")}
7378
options={options}

0 commit comments

Comments
 (0)