fix(audit): remover response_format para openrouter e melhorar placeholder
This commit is contained in:
@@ -161,7 +161,7 @@ export default function AuditPanel() {
|
|||||||
<Input
|
<Input
|
||||||
value={config.baseUrl ?? ''}
|
value={config.baseUrl ?? ''}
|
||||||
onChange={(e) => setConfig((c) => ({ ...c, baseUrl: e.target.value || undefined }))}
|
onChange={(e) => setConfig((c) => ({ ...c, baseUrl: e.target.value || undefined }))}
|
||||||
placeholder="https://api.openai.com/v1"
|
placeholder={config.provider === 'openrouter' ? 'https://openrouter.ai/api/v1 (padrão)' : config.provider === 'ollama' ? 'http://localhost:11434 (padrão)' : 'https://api.openai.com/v1'}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -147,23 +147,28 @@ async function callOpenRouter(
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
onProgress?.('Enviando para OpenRouter...');
|
onProgress?.('Enviando para OpenRouter...');
|
||||||
const url = config.baseUrl ?? 'https://openrouter.ai/api/v1/chat/completions';
|
const url = config.baseUrl ?? 'https://openrouter.ai/api/v1/chat/completions';
|
||||||
const body: OpenAIRequest = {
|
const body = {
|
||||||
model: config.model,
|
model: config.model,
|
||||||
messages: [
|
messages: [
|
||||||
{ role: 'system', content: systemPrompt },
|
{ role: 'system' as const, content: systemPrompt },
|
||||||
{ role: 'user', content: userPrompt },
|
{ role: 'user' as const, content: userPrompt },
|
||||||
],
|
],
|
||||||
temperature: 0,
|
temperature: 0,
|
||||||
response_format: { type: 'json_object' },
|
|
||||||
};
|
};
|
||||||
const response = await fetchWithTimeout(url, {
|
const response = await fetchWithTimeout(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': `Bearer ${config.apiKey}`,
|
'Authorization': `Bearer ${config.apiKey}`,
|
||||||
|
'HTTP-Referer': 'https://brainwind.app',
|
||||||
|
'X-Title': 'BrainWind NBR 6123',
|
||||||
},
|
},
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
}, 180000);
|
}, 180000);
|
||||||
|
if (!response.ok) {
|
||||||
|
const errText = await response.text();
|
||||||
|
throw new Error(`OpenRouter HTTP ${response.status}: ${errText}`);
|
||||||
|
}
|
||||||
const data = await response.json() as { choices?: { message?: { content?: string } }[]; error?: { message?: string } };
|
const data = await response.json() as { choices?: { message?: { content?: string } }[]; error?: { message?: string } };
|
||||||
if (data.error) throw new Error(`OpenRouter error: ${data.error.message}`);
|
if (data.error) throw new Error(`OpenRouter error: ${data.error.message}`);
|
||||||
const content = data.choices?.[0]?.message?.content;
|
const content = data.choices?.[0]?.message?.content;
|
||||||
|
|||||||
Reference in New Issue
Block a user