From 5f0329c4006a4c57aea050b9576ace970737446f Mon Sep 17 00:00:00 2001 From: Marcos Date: Wed, 15 Jul 2026 14:30:52 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Auto-deploy:=20BrainWind=20atual?= =?UTF-8?q?izado=20em=2015/07/2026=2014:30:52?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/lib/audit/runner.ts | 10 ++++-- test-minimax.js | 61 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 test-minimax.js diff --git a/app/src/lib/audit/runner.ts b/app/src/lib/audit/runner.ts index 72b5a10..c840979 100644 --- a/app/src/lib/audit/runner.ts +++ b/app/src/lib/audit/runner.ts @@ -151,13 +151,17 @@ async function callMinimax( const reader = response.body.getReader(); const decoder = new TextDecoder('utf-8'); let fullText = ''; + let buffer = ''; 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) { + buffer += decoder.decode(value, { stream: true }); + const lines = buffer.split('\n'); + buffer = lines.pop() || ''; + for (const rawLine of lines) { + const line = rawLine.trim(); + if (!line.startsWith('data: ')) continue; const jsonStr = line.replace(/^data: /, '').trim(); if (jsonStr === '[DONE]') continue; try { diff --git a/test-minimax.js b/test-minimax.js new file mode 100644 index 0000000..d1a352c --- /dev/null +++ b/test-minimax.js @@ -0,0 +1,61 @@ +async function testMinimaxStream() { + const url = 'https://api.minimax.io/v1/chat/completions'; + const apiKey = 'sk-cp-siEwoNh9WA3Prxe6frpJ2HsXPje-gjt5jObhHloqqoO0FX0i9yP54N3zhY492GKu18l9XiANDiCoECU3t0uMtRODvkzzi93A2Rmtco6MjATrKNOEDR_bxa4'; + const body = { + model: 'MiniMax-M3', + messages: [ + { role: 'system', content: 'You are a test agent. Output JSON format.' }, + { role: 'user', content: 'Ping' }, + ], + temperature: 0, + stream: true, + response_format: { type: 'json_object' }, + }; + + try { + const res = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${apiKey}`, + }, + body: JSON.stringify(body), + }); + + if (!res.ok) { + console.error('HTTP Error:', res.status, await res.text()); + return; + } + + const reader = res.body.getReader(); + const decoder = new TextDecoder('utf-8'); + let fullText = ''; + let buffer = ''; + + while (true) { + const { done, value } = await reader.read(); + if (done) break; + buffer += decoder.decode(value, { stream: true }); + const lines = buffer.split('\n'); + buffer = lines.pop() || ''; + for (const rawLine of lines) { + const line = rawLine.trim(); + if (!line.startsWith('data: ')) continue; + 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) { + console.error('Failed to parse:', jsonStr); + } + } + } + console.log('\n--- FINAL FULL TEXT ---'); + console.log(fullText); + } catch (err) { + console.error('Fetch error:', err); + } +} +testMinimaxStream();