Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/vast-carrots-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

The timeout for Ollama and LM Studio was increased from 5 minutes to 1 hour
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"overrides": {
"tar-fs": ">=2.1.3",
"esbuild": ">=0.25.0",
"undici": ">=5.29.0",
"brace-expansion": ">=2.0.2",
"form-data": ">=4.0.4",
"bluebird": ">=3.7.2"
Expand Down
12 changes: 10 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/api/providers/kilocode-ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ApiStream } from "../transform/stream"
import { BaseProvider } from "./base-provider"
import { ModelRecord } from "../../shared/api"
import { getModels } from "./fetchers/modelCache"
import { fetchWithTimeout } from "./kilocode/fetchWithTimeout"

function convertToOllamaMessages(anthropicMessages: Anthropic.Messages.MessageParam[]): Message[] {
const ollamaMessages: Message[] = []
Expand Down Expand Up @@ -119,6 +120,8 @@ function convertToOllamaMessages(anthropicMessages: Anthropic.Messages.MessagePa
return ollamaMessages
}

const OLLAMA_TIMEOUT_MS = 3_600_000

interface OllamaHandlerOptions {
ollamaBaseUrl?: string
ollamaModelId?: string
Expand All @@ -137,7 +140,10 @@ export class KilocodeOllamaHandler extends BaseProvider {
private ensureClient(): Ollama {
if (!this.client) {
try {
this.client = new Ollama({ host: this.options.ollamaBaseUrl || "http://localhost:11434" })
this.client = new Ollama({
host: this.options.ollamaBaseUrl || "http://localhost:11434",
fetch: fetchWithTimeout(OLLAMA_TIMEOUT_MS),
})
} catch (error) {
throw new Error(`Error creating Ollama client: ${error.message}`)
}
Expand Down
13 changes: 13 additions & 0 deletions src/api/providers/kilocode/fetchWithTimeout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as undici from "undici"

export function fetchWithTimeout(timeoutMs: number): typeof fetch {
const agent = new undici.Agent({ headersTimeout: timeoutMs, bodyTimeout: timeoutMs })
return (input, init) =>
undici.fetch(
input as undici.RequestInfo,
{
...init,
dispatcher: agent,
} as undici.RequestInit,
) as unknown as Promise<Response>
Comment on lines +9 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit is it possible to type this with official undici types?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, then you move the problem to the call site.

}
5 changes: 5 additions & 0 deletions src/api/providers/lm-studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { ApiStream } from "../transform/stream"

import { BaseProvider } from "./base-provider"
import type { SingleCompletionHandler, ApiHandlerCreateMessageMetadata } from "../index"
import { fetchWithTimeout } from "./kilocode/fetchWithTimeout"

const LMSTUDIO_TIMEOUT_MS = 3_600_000 // kilocode_change

export class LmStudioHandler extends BaseProvider implements SingleCompletionHandler {
protected options: ApiHandlerOptions
Expand All @@ -24,6 +27,8 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
this.client = new OpenAI({
baseURL: (this.options.lmStudioBaseUrl || "http://localhost:1234") + "/v1",
apiKey: "noop",
timeout: LMSTUDIO_TIMEOUT_MS, // kilocode_change
fetch: fetchWithTimeout(LMSTUDIO_TIMEOUT_MS), // kilocode_change
})
}

Expand Down
1 change: 1 addition & 0 deletions src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@
"tmp": "^0.2.3",
"tree-sitter-wasms": "^0.1.12",
"turndown": "^7.2.0",
"undici": "^7.13.0",
"uri-js": "^4.4.1",
"uuid": "^11.1.0",
"vscode-material-icons": "^0.1.1",
Expand Down
Loading