fix: handle Ollama model names case-insensitively

- Store Ollama models with both original and lowercase keys in getOllamaModels
- Update useSelectedModel hook to try case-insensitive lookup for Ollama
- Update NativeOllamaHandler to handle case-insensitive model lookups
- Fixes issue where models like "GPT-OSS:120B" were rejected due to case mismatch

Fixes #9608
This commit is contained in:
Roo Code 2025-11-26 12:15:09 +00:00
parent 3806b3d27d
commit eeefecb7c3
3 changed files with 23 additions and 3 deletions

View file

@ -89,7 +89,14 @@ export async function getOllamaModels(
{ headers },
)
.then((ollamaModelInfo) => {
models[ollamaModel.name] = parseOllamaModel(ollamaModelInfo.data)
const modelInfo = parseOllamaModel(ollamaModelInfo.data)
// Store with original name
models[ollamaModel.name] = modelInfo
// Also store with lowercase name for case-insensitive lookup
const lowerName = ollamaModel.name.toLowerCase()
if (lowerName !== ollamaModel.name) {
models[lowerName] = modelInfo
}
}),
)
}

View file

@ -274,9 +274,16 @@ export class NativeOllamaHandler extends BaseProvider implements SingleCompletio
override getModel(): { id: string; info: ModelInfo } {
const modelId = this.options.ollamaModelId || ""
// Try exact match first, then lowercase for case-insensitive lookup
let modelInfo = this.models[modelId]
if (!modelInfo && modelId) {
// Try case-insensitive lookup
const lowerModelId = modelId.toLowerCase()
modelInfo = this.models[lowerModelId]
}
return {
id: modelId,
info: this.models[modelId] || openAiModelInfoSaneDefaults,
info: modelInfo || openAiModelInfoSaneDefaults,
}
}

View file

@ -281,7 +281,13 @@ function getSelectedModel({
}
case "ollama": {
const id = apiConfiguration.ollamaModelId ?? ""
const info = ollamaModels && ollamaModels[apiConfiguration.ollamaModelId!]
// Try exact match first, then lowercase for case-insensitive lookup
let info = ollamaModels && ollamaModels[apiConfiguration.ollamaModelId!]
if (!info && ollamaModels && apiConfiguration.ollamaModelId) {
// Try case-insensitive lookup
const lowerModelId = apiConfiguration.ollamaModelId.toLowerCase()
info = ollamaModels[lowerModelId]
}
const adjustedInfo =
info?.contextWindow &&