yxmiler commited on
Commit
871bf53
·
verified ·
1 Parent(s): 2c66a64

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +20 -14
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
- if (linejosn.response === "token" && model == "grok-latest") {
494
- const token = linejosn.token;
495
- if (token && token.length > 0) {
496
- const responseData = MessageProcessor.createChatResponse(token, model, true);
497
- res.write(`data: ${JSON.stringify(responseData)}\n\n`);
498
- }
499
- } else if (linejosn.response === "modelResponse" && model === 'grok-latest-image') {
500
- if (linejosn?.modelResponse?.generatedImageUrls?.length > 0) {
501
- imageUrl = linejosn.modelResponse.generatedImageUrls[0]; // 获取第一个URL
502
- const dataImage = await handleImageResponse(imageUrl);
503
- const responseData = MessageProcessor.createChatResponse(dataImage, model, true);
504
- res.write(`data: ${JSON.stringify(responseData)}\n\n`);
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