dan92 commited on
Commit
fe6da88
·
verified ·
1 Parent(s): 7f6c773

Upload index.js

Browse files
Files changed (1) hide show
  1. index.js +20 -4
index.js CHANGED
@@ -403,6 +403,19 @@ class MessageProcessor {
403
  model: model
404
  };
405
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  return {
407
  ...baseResponse,
408
  object: 'chat.completion',
@@ -410,9 +423,7 @@ class MessageProcessor {
410
  index: 0,
411
  message: {
412
  role: 'assistant',
413
- content: Array.isArray(message) ?
414
- message.map(item => item.image_url?.url || item) : // 提取图片URL
415
- message
416
  },
417
  finish_reason: 'stop'
418
  }],
@@ -591,7 +602,12 @@ async function handleImageResponse(imageUrl) {
591
  const imageContentType = imageBase64Response.headers.get('content-type');
592
 
593
  // 修改返回结构,确保返回Markdown格式的图片标签
594
- return `data:image/jpg;base64,${base64String}`; // 直接返回Data URL字符串
 
 
 
 
 
595
  } catch (error) {
596
  console.error('图片处理失败:', error);
597
  return '图片生成失败';
 
403
  model: model
404
  };
405
 
406
+ // 处理图片响应
407
+ const processContent = (content) => {
408
+ if (typeof content === 'string' && content.startsWith('data:image')) {
409
+ return [{
410
+ type: "image_url",
411
+ image_url: {
412
+ url: content
413
+ }
414
+ }];
415
+ }
416
+ return content;
417
+ };
418
+
419
  return {
420
  ...baseResponse,
421
  object: 'chat.completion',
 
423
  index: 0,
424
  message: {
425
  role: 'assistant',
426
+ content: processContent(message)
 
 
427
  },
428
  finish_reason: 'stop'
429
  }],
 
602
  const imageContentType = imageBase64Response.headers.get('content-type');
603
 
604
  // 修改返回结构,确保返回Markdown格式的图片标签
605
+ return {
606
+ type: "image_url",
607
+ image_url: {
608
+ url: `data:image/jpg;base64,${base64String}`
609
+ }
610
+ };
611
  } catch (error) {
612
  console.error('图片处理失败:', error);
613
  return '图片生成失败';