feat(ai): improve model fetching and error handling

- Add server-side model fetching endpoint with flexible provider support
- Refactor client-side AI settings component to use new API query
- Implement dynamic header generation for different AI providers
- Enhance error handling and toast notifications
- Remove local model fetching logic in favor of server-side implementation
This commit is contained in:
Mauricio Siu
2025-03-07 00:55:11 -06:00
parent efd176451f
commit b8e5cae88f
4 changed files with 112 additions and 46 deletions

View File

@@ -74,8 +74,39 @@ export function selectAIProvider(config: { apiUrl: string; apiKey: string }) {
headers: {
Authorization: `Bearer ${config.apiKey}`,
},
)};
});
default:
throw new Error(`Unsupported AI provider: ${providerName}`);
}
}
export const getProviderHeaders = (
apiUrl: string,
apiKey: string,
): Record<string, string> => {
// Anthropic
if (apiUrl.includes("anthropic")) {
return {
"x-api-key": apiKey,
"anthropic-version": "2023-06-01",
};
}
// Mistral
if (apiUrl.includes("mistral")) {
return {
Authorization: apiKey,
};
}
// Default (OpenAI style)
return {
Authorization: `Bearer ${apiKey}`,
};
};
export interface Model {
id: string;
object: string;
created: number;
owned_by: string;
}