Skip to content

Commit 8ab7772

Browse files
Adjust contextWindow analysis to handle Ollama 40960 vs. 4096 goofiness
1 parent 75b9a47 commit 8ab7772

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/api/providers/fetchers/ollama.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ export const parseOllamaModel = (rawModel: OllamaModelInfoResponse): ModelInfo =
4848
const contextLengthFromModelInfo =
4949
contextKey && typeof rawModel.model_info[contextKey] === "number" ? rawModel.model_info[contextKey] : undefined
5050

51-
const contextWindow = contextLengthFromModelParameters ?? contextLengthFromModelInfo
51+
let contextWindow = contextLengthFromModelParameters ?? contextLengthFromModelInfo
52+
53+
if (contextWindow == 40960 && !contextLengthFromModelParameters) {
54+
contextWindow = 4096 // For some unknown reason, Ollama returns an undefind context as "40960" rather than 4096, which is what it actually enforces.
55+
}
5256
// kilocode_change end
5357

5458
const modelInfo: ModelInfo = Object.assign({}, ollamaDefaultModelInfo, {

src/api/providers/native-ollama.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class NativeOllamaHandler extends BaseProvider implements SingleCompletio
155155
if (this.isInitialized) {
156156
return
157157
}
158-
await this.fetchModels()
158+
await this.fetchModel()
159159
this.isInitialized = true
160160
}
161161

@@ -287,7 +287,7 @@ export class NativeOllamaHandler extends BaseProvider implements SingleCompletio
287287
}
288288
}
289289

290-
async fetchModels() {
290+
async fetchModel() {
291291
this.models = await getOllamaModels(this.options.ollamaBaseUrl)
292292
return this.models
293293
}

0 commit comments

Comments
 (0)