From f6329aab73a06faa9582853ea5c40a4319e775c6 Mon Sep 17 00:00:00 2001 From: perf3ct Date: Thu, 29 May 2025 20:45:27 +0000 Subject: [PATCH] fix(llm): fix provider error checking --- .../client/src/widgets/llm_chat/validation.ts | 77 +++++++++--------- .../src/services/llm/ai_service_manager.ts | 81 ++++++++++++------- 2 files changed, 92 insertions(+), 66 deletions(-) diff --git a/apps/client/src/widgets/llm_chat/validation.ts b/apps/client/src/widgets/llm_chat/validation.ts index 294ae8018..e39b07012 100644 --- a/apps/client/src/widgets/llm_chat/validation.ts +++ b/apps/client/src/widgets/llm_chat/validation.ts @@ -16,49 +16,53 @@ export async function validateEmbeddingProviders(validationWarning: HTMLElement) return; } - // Get provider precedence + // Get precedence list from options const precedenceStr = options.get('aiProviderPrecedence') || 'openai,anthropic,ollama'; let precedenceList: string[] = []; if (precedenceStr) { if (precedenceStr.startsWith('[') && precedenceStr.endsWith(']')) { - precedenceList = JSON.parse(precedenceStr); + try { + precedenceList = JSON.parse(precedenceStr); + } catch (e) { + console.error('Error parsing precedence list:', e); + precedenceList = ['openai']; // Default if parsing fails + } } else if (precedenceStr.includes(',')) { precedenceList = precedenceStr.split(',').map(p => p.trim()); } else { precedenceList = [precedenceStr]; } } - - // Get enabled providers - this is a simplification since we don't have direct DB access - // We'll determine enabled status based on the presence of keys or settings - const enabledProviders: string[] = []; - - // OpenAI is enabled if API key is set - const openaiKey = options.get('openaiApiKey'); - if (openaiKey) { - enabledProviders.push('openai'); + + // Check for configuration issues with providers in the precedence list + const configIssues: string[] = []; + + // Check each provider in the precedence list for proper configuration + for (const provider of precedenceList) { + if (provider === 'openai') { + // Check OpenAI configuration + const apiKey = options.get('openaiApiKey'); + if (!apiKey) { + configIssues.push(`OpenAI API key is missing`); + } + } else if (provider === 'anthropic') { + // Check Anthropic configuration + const apiKey = options.get('anthropicApiKey'); + if (!apiKey) { + configIssues.push(`Anthropic API key is missing`); + } + } else if (provider === 'ollama') { + // Check Ollama configuration + const baseUrl = options.get('ollamaBaseUrl'); + if (!baseUrl) { + configIssues.push(`Ollama Base URL is missing`); + } + } + // Add checks for other providers as needed } - // Anthropic is enabled if API key is set - const anthropicKey = options.get('anthropicApiKey'); - if (anthropicKey) { - enabledProviders.push('anthropic'); - } - - // Ollama is enabled if base URL is set - const ollamaBaseUrl = options.get('ollamaBaseUrl'); - if (ollamaBaseUrl) { - enabledProviders.push('ollama'); - } - - // Local is always available - enabledProviders.push('local'); - - // Perform validation checks - const allPrecedenceEnabled = precedenceList.every((p: string) => enabledProviders.includes(p)); - - // Get embedding queue status + // Fetch embedding stats to check if there are any notes being processed const embeddingStats = await getEmbeddingStats() as { success: boolean, stats: { @@ -73,17 +77,18 @@ export async function validateEmbeddingProviders(validationWarning: HTMLElement) const queuedNotes = embeddingStats?.stats?.queuedNotesCount || 0; const hasEmbeddingsInQueue = queuedNotes > 0; - // Show warning if there are issues - if (!allPrecedenceEnabled || hasEmbeddingsInQueue) { + // Show warning if there are configuration issues or embeddings in queue + if (configIssues.length > 0 || hasEmbeddingsInQueue) { let message = 'AI Provider Configuration Issues'; message += '