🚀 Auto-deploy: BrainWind atualizado em 15/07/2026 14:30:52
This commit is contained in:
@@ -151,13 +151,17 @@ async function callMinimax(
|
|||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
const decoder = new TextDecoder('utf-8');
|
const decoder = new TextDecoder('utf-8');
|
||||||
let fullText = '';
|
let fullText = '';
|
||||||
|
let buffer = '';
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read();
|
const { done, value } = await reader.read();
|
||||||
if (done) break;
|
if (done) break;
|
||||||
const chunk = decoder.decode(value, { stream: true });
|
buffer += decoder.decode(value, { stream: true });
|
||||||
const lines = chunk.split('\n').filter(l => l.trim().startsWith('data: '));
|
const lines = buffer.split('\n');
|
||||||
for (const line of lines) {
|
buffer = lines.pop() || '';
|
||||||
|
for (const rawLine of lines) {
|
||||||
|
const line = rawLine.trim();
|
||||||
|
if (!line.startsWith('data: ')) continue;
|
||||||
const jsonStr = line.replace(/^data: /, '').trim();
|
const jsonStr = line.replace(/^data: /, '').trim();
|
||||||
if (jsonStr === '[DONE]') continue;
|
if (jsonStr === '[DONE]') continue;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -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();
|
||||||
Reference in New Issue
Block a user