Update index.js
Browse files
index.js
CHANGED
@@ -488,21 +488,27 @@ async function handleStreamResponse(response, model, res) {
|
|
488 |
res.write('data: [DONE]\n\n');
|
489 |
continue;
|
490 |
}
|
491 |
-
console.log("data", data);
|
492 |
let linejosn = JSON.parse(data);
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
}
|
507 |
}
|
508 |
|
|
|
488 |
res.write('data: [DONE]\n\n');
|
489 |
continue;
|
490 |
}
|
|
|
491 |
let linejosn = JSON.parse(data);
|
492 |
+
switch (model) {
|
493 |
+
case "grok-latest":
|
494 |
+
if (linejosn.response === "token") {
|
495 |
+
const token = linejosn.token;
|
496 |
+
if (token && token.length > 0) {
|
497 |
+
const responseData = MessageProcessor.createChatResponse(token, model, true);
|
498 |
+
res.write(`data: ${JSON.stringify(responseData)}\n\n`);
|
499 |
+
}
|
500 |
+
}
|
501 |
+
break;
|
502 |
+
case "grok-latest-image":
|
503 |
+
if (linejosn.response === "modelResponse") {
|
504 |
+
if (linejosn?.modelResponse?.generatedImageUrls?.length > 0) {
|
505 |
+
let imageUrl = linejosn.modelResponse.generatedImageUrls[0]; // 获取第一个URL
|
506 |
+
const dataImage = await handleImageResponse(imageUrl);
|
507 |
+
const responseData = MessageProcessor.createChatResponse(dataImage, model, true);
|
508 |
+
res.write(`data: ${JSON.stringify(responseData)}\n\n`);
|
509 |
+
}
|
510 |
+
}
|
511 |
+
break;
|
512 |
}
|
513 |
}
|
514 |
|