🚀 Auto-deploy: BrainWind atualizado em 15/07/2026 12:15:51

This commit is contained in:
2026-07-15 12:15:51 +00:00
parent 10f666bc51
commit 310a19c001
+28 -5
View File
@@ -130,6 +130,7 @@ async function callMinimax(
{ role: 'user', content: userPrompt }, { role: 'user', content: userPrompt },
], ],
temperature: 0, temperature: 0,
stream: true,
response_format: { type: 'json_object' }, response_format: { type: 'json_object' },
}; };
const response = await fetchWithTimeout(url, { const response = await fetchWithTimeout(url, {
@@ -144,11 +145,33 @@ async function callMinimax(
const errText = await response.text(); const errText = await response.text();
throw new Error(`MiniMax HTTP ${response.status}: ${errText.substring(0, 100)}...`); throw new Error(`MiniMax HTTP ${response.status}: ${errText.substring(0, 100)}...`);
} }
const data = await response.json() as { choices?: { message?: { content?: string } }[]; error?: { message?: string } };
if (data.error) throw new Error(`MiniMax error: ${data.error.message}`); if (!response.body) throw new Error('MiniMax response body is null');
const content = data.choices?.[0]?.message?.content;
if (!content) throw new Error('MiniMax returned empty response'); const reader = response.body.getReader();
return content; const decoder = new TextDecoder('utf-8');
let fullText = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value, { stream: true });
const lines = chunk.split('\n').filter(l => l.trim().startsWith('data: '));
for (const line of lines) {
const jsonStr = line.replace(/^data: /, '').trim();
if (jsonStr === '[DONE]') continue;
try {
const parsed = JSON.parse(jsonStr);
const content = parsed.choices?.[0]?.delta?.content || '';
fullText += content;
} catch (e) {
// ignore incomplete JSON
}
}
}
if (!fullText) throw new Error('MiniMax returned empty streaming response');
return fullText;
} }
async function callOpenRouter( async function callOpenRouter(