Skip to content

Commit bbb7166

Browse files
authored
fix(ollama): handle showModelInfo errors to prevent empty model list (#1277)
1 parent 5421dce commit bbb7166

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

src/main/presenter/llmProviderPresenter/providers/ollamaProvider.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,37 @@ export class OllamaProvider extends BaseLLMProvider {
323323
}
324324

325325
private async attachModelInfo(model: OllamaModel): Promise<OllamaModel> {
326-
const showResponse = await this.showModelInfo(model.name)
327-
const info = showResponse.model_info
328-
const family = model.details.family
329-
const context_length = info?.[family + '.context_length'] ?? 4096
330-
const embedding_length = info?.[family + '.embedding_length'] ?? 512
331-
const capabilities = showResponse.capabilities ?? ['chat']
332-
333-
// Merge customConfig properties to model
334-
return {
335-
...model,
336-
model_info: {
337-
context_length,
338-
embedding_length
339-
},
340-
capabilities
326+
try {
327+
const showResponse = await this.showModelInfo(model.name)
328+
const info = showResponse.model_info
329+
const family = model.details.family
330+
const context_length = info?.[family + '.context_length'] ?? 4096
331+
const embedding_length = info?.[family + '.embedding_length'] ?? 512
332+
const capabilities = showResponse.capabilities ?? ['chat']
333+
334+
// Merge customConfig properties to model
335+
return {
336+
...model,
337+
model_info: {
338+
context_length,
339+
embedding_length
340+
},
341+
capabilities
342+
}
343+
} catch (error) {
344+
// If showModelInfo fails, return the model with default info
345+
console.warn(
346+
`Failed to get info for model ${model.name}, using defaults:`,
347+
(error as Error).message
348+
)
349+
return {
350+
...model,
351+
model_info: {
352+
context_length: 4096,
353+
embedding_length: 512
354+
},
355+
capabilities: ['chat']
356+
}
341357
}
342358
}
343359

0 commit comments

Comments
 (0)