Skip to content

Commit 471ce3c

Browse files
authored
Merge pull request #2089 from Kilo-Org/christiaan/ollama
Delete custom native Ollama implementation
2 parents 041a325 + ff21225 commit 471ce3c

File tree

4 files changed

+18
-228
lines changed

4 files changed

+18
-228
lines changed

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/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) {

0 commit comments

Comments
 (0)