fixed ollama

This commit is contained in:
Arjun 2026-02-12 11:40:55 +05:30
parent c3e0184167
commit 6c9ccc0f95

View file

@ -39,11 +39,17 @@ export function createProvider(config: z.infer<typeof Provider>): ProviderV2 {
baseURL, baseURL,
headers, headers,
}); });
case "ollama": case "ollama": {
// ollama-ai-provider-v2 expects baseURL to include /api
let ollamaURL = baseURL;
if (ollamaURL && !ollamaURL.replace(/\/+$/, '').endsWith('/api')) {
ollamaURL = ollamaURL.replace(/\/+$/, '') + '/api';
}
return createOllama({ return createOllama({
baseURL, baseURL: ollamaURL,
headers, headers,
}); });
}
case "openai-compatible": case "openai-compatible":
return createOpenAICompatible({ return createOpenAICompatible({
name: "openai-compatible", name: "openai-compatible",
@ -65,10 +71,12 @@ export function createProvider(config: z.infer<typeof Provider>): ProviderV2 {
export async function testModelConnection( export async function testModelConnection(
providerConfig: z.infer<typeof Provider>, providerConfig: z.infer<typeof Provider>,
model: string, model: string,
timeoutMs: number = 8000, timeoutMs?: number,
): Promise<{ success: boolean; error?: string }> { ): Promise<{ success: boolean; error?: string }> {
const isLocal = providerConfig.flavor === "ollama" || providerConfig.flavor === "openai-compatible";
const effectiveTimeout = timeoutMs ?? (isLocal ? 60000 : 8000);
const controller = new AbortController(); const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), timeoutMs); const timeout = setTimeout(() => controller.abort(), effectiveTimeout);
try { try {
const provider = createProvider(providerConfig); const provider = createProvider(providerConfig);
const languageModel = provider.languageModel(model); const languageModel = provider.languageModel(model);