feat: suporte para provedor OpenRouter
This commit is contained in:
@@ -26,6 +26,8 @@ export const testApiKey = async (provider: AIProvider, apiKey: string, endpoint?
|
||||
return await testAzure(apiKey, endpoint);
|
||||
case 'ollama':
|
||||
return await testOllama(endpoint);
|
||||
case 'openrouter':
|
||||
return await testOpenRouter(apiKey);
|
||||
default:
|
||||
return { success: false, error: 'Provedor não suportado' };
|
||||
}
|
||||
@@ -229,4 +231,30 @@ const testAzure = async (apiKey: string, endpoint: string): Promise<TestResult>
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message || 'Erro ao conectar com Azure' };
|
||||
}
|
||||
};
|
||||
|
||||
const testOpenRouter = async (apiKey: string): Promise<TestResult> => {
|
||||
try {
|
||||
const response = await fetch('https://openrouter.ai/api/v1/models', {
|
||||
headers: { 'Authorization': `Bearer ${apiKey}` }
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
return { success: false, error: error.error?.message || 'Chave de API inválida' };
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
models: [
|
||||
{ id: 'google/gemini-2.5-flash', name: 'Gemini 2.5 Flash' },
|
||||
{ id: 'google/gemini-2.5-pro', name: 'Gemini 2.5 Pro' },
|
||||
{ id: 'anthropic/claude-3.5-sonnet', name: 'Claude 3.5 Sonnet' },
|
||||
{ id: 'openai/gpt-4o', name: 'GPT-4o' },
|
||||
{ id: 'meta-llama/llama-3.1-70b-instruct', name: 'Llama 3.1 70B' }
|
||||
]
|
||||
};
|
||||
} catch (error: any) {
|
||||
return { success: false, error: error.message || 'Erro ao conectar com OpenRouter' };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user