mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
fix(llm): fix provider error checking
This commit is contained in:
parent
ef581b181f
commit
f6329aab73
@ -16,13 +16,18 @@ 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 {
|
||||
@ -30,35 +35,34 @@ export async function validateEmbeddingProviders(validationWarning: HTMLElement)
|
||||
}
|
||||
}
|
||||
|
||||
// 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[] = [];
|
||||
// Check for configuration issues with providers in the precedence list
|
||||
const configIssues: string[] = [];
|
||||
|
||||
// OpenAI is enabled if API key is set
|
||||
const openaiKey = options.get('openaiApiKey');
|
||||
if (openaiKey) {
|
||||
enabledProviders.push('openai');
|
||||
// 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 = '<i class="bx bx-error-circle me-2"></i><strong>AI Provider Configuration Issues</strong>';
|
||||
|
||||
message += '<ul class="mb-1 ps-4">';
|
||||
|
||||
if (!allPrecedenceEnabled) {
|
||||
const disabledProviders = precedenceList.filter((p: string) => !enabledProviders.includes(p));
|
||||
message += `<li>The following providers in your precedence list are not enabled: ${disabledProviders.join(', ')}.</li>`;
|
||||
// Show configuration issues
|
||||
for (const issue of configIssues) {
|
||||
message += `<li>${issue}</li>`;
|
||||
}
|
||||
|
||||
// Show warning about embeddings queue if applicable
|
||||
if (hasEmbeddingsInQueue) {
|
||||
message += `<li>Currently processing embeddings for ${queuedNotes} notes. Some AI features may produce incomplete results until processing completes.</li>`;
|
||||
}
|
||||
|
@ -152,38 +152,59 @@ export class AIServiceManager implements IAIServiceManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Parse provider precedence list (similar to updateProviderOrder)
|
||||
let precedenceList: string[] = [];
|
||||
// Get precedence list from options
|
||||
let precedenceList: string[] = ['openai']; // Default to openai if not set
|
||||
const precedenceOption = await options.getOption('aiProviderPrecedence');
|
||||
|
||||
if (precedenceOption) {
|
||||
if (precedenceOption.startsWith('[') && precedenceOption.endsWith(']')) {
|
||||
precedenceList = JSON.parse(precedenceOption);
|
||||
} else if (typeof precedenceOption === 'string') {
|
||||
if (precedenceOption.includes(',')) {
|
||||
precedenceList = precedenceOption.split(',').map(p => p.trim());
|
||||
} else {
|
||||
precedenceList = [precedenceOption];
|
||||
try {
|
||||
if (precedenceOption.startsWith('[') && precedenceOption.endsWith(']')) {
|
||||
precedenceList = JSON.parse(precedenceOption);
|
||||
} else if (typeof precedenceOption === 'string') {
|
||||
if (precedenceOption.includes(',')) {
|
||||
precedenceList = precedenceOption.split(',').map(p => p.trim());
|
||||
} else {
|
||||
precedenceList = [precedenceOption];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log.error(`Error parsing precedence list: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Get enabled providers
|
||||
const enabledProviders = await getEnabledEmbeddingProviders();
|
||||
const enabledProviderNames = enabledProviders.map(p => p.name);
|
||||
// Check for configuration issues with providers in the precedence list
|
||||
const configIssues: string[] = [];
|
||||
|
||||
// Check if all providers in precedence list are enabled
|
||||
const allPrecedenceEnabled = precedenceList.every(p =>
|
||||
enabledProviderNames.includes(p) || p === 'local');
|
||||
// Check each provider in the precedence list for proper configuration
|
||||
for (const provider of precedenceList) {
|
||||
if (provider === 'openai') {
|
||||
// Check OpenAI configuration
|
||||
const apiKey = await options.getOption('openaiApiKey');
|
||||
if (!apiKey) {
|
||||
configIssues.push(`OpenAI API key is missing`);
|
||||
}
|
||||
} else if (provider === 'anthropic') {
|
||||
// Check Anthropic configuration
|
||||
const apiKey = await options.getOption('anthropicApiKey');
|
||||
if (!apiKey) {
|
||||
configIssues.push(`Anthropic API key is missing`);
|
||||
}
|
||||
} else if (provider === 'ollama') {
|
||||
// Check Ollama configuration
|
||||
const baseUrl = await options.getOption('ollamaBaseUrl');
|
||||
if (!baseUrl) {
|
||||
configIssues.push(`Ollama Base URL is missing`);
|
||||
}
|
||||
}
|
||||
// Add checks for other providers as needed
|
||||
}
|
||||
|
||||
// Return warning message if there are issues
|
||||
if (!allPrecedenceEnabled) {
|
||||
// Return warning message if there are configuration issues
|
||||
if (configIssues.length > 0) {
|
||||
let message = 'There are issues with your AI provider configuration:';
|
||||
|
||||
if (!allPrecedenceEnabled) {
|
||||
const disabledProviders = precedenceList.filter(p =>
|
||||
!enabledProviderNames.includes(p) && p !== 'local');
|
||||
message += `\n• The following providers in your precedence list are not enabled: ${disabledProviders.join(', ')}.`;
|
||||
for (const issue of configIssues) {
|
||||
message += `\n• ${issue}`;
|
||||
}
|
||||
|
||||
message += '\n\nPlease check your AI settings.';
|
||||
|
Loading…
x
Reference in New Issue
Block a user