(rawModel: OllamaModelInfoResponse)
| 38 | type OllamaModelInfoResponse = z.infer<typeof OllamaModelInfoResponseSchema> |
| 39 | |
| 40 | export const parseOllamaModel = (rawModel: OllamaModelInfoResponse): ModelInfo | null => { |
| 41 | const contextKey = Object.keys(rawModel.model_info).find((k) => k.includes("context_length")) |
| 42 | const contextWindow = |
| 43 | contextKey && typeof rawModel.model_info[contextKey] === "number" ? rawModel.model_info[contextKey] : undefined |
| 44 | |
| 45 | // Filter out models that don't support tools. Models without tool capability won't work. |
| 46 | const supportsTools = rawModel.capabilities?.includes("tools") ?? false |
| 47 | if (!supportsTools) { |
| 48 | return null |
| 49 | } |
| 50 | |
| 51 | const modelInfo: ModelInfo = Object.assign({}, ollamaDefaultModelInfo, { |
| 52 | description: `Family: ${rawModel.details.family}, Context: ${contextWindow}, Size: ${rawModel.details.parameter_size}`, |
| 53 | contextWindow: contextWindow || ollamaDefaultModelInfo.contextWindow, |
| 54 | supportsPromptCache: true, |
| 55 | supportsImages: rawModel.capabilities?.includes("vision"), |
| 56 | maxTokens: contextWindow || ollamaDefaultModelInfo.contextWindow, |
| 57 | }) |
| 58 | |
| 59 | return modelInfo |
| 60 | } |
| 61 | |
| 62 | export async function getOllamaModels( |
| 63 | baseUrl = "http://localhost:11434", |
no test coverage detected