Spaces:
Sleeping
Sleeping
Upload index.js
Browse files
index.js
CHANGED
@@ -403,37 +403,6 @@ class MessageProcessor {
|
|
403 |
model: model
|
404 |
};
|
405 |
|
406 |
-
// 新增:处理图片对象
|
407 |
-
const processContent = (content) => {
|
408 |
-
if (Array.isArray(content)) {
|
409 |
-
return content.map(item => {
|
410 |
-
if (item?.image_url?.url) {
|
411 |
-
return {
|
412 |
-
type: "image_url",
|
413 |
-
image_url: {
|
414 |
-
url: item.image_url.url
|
415 |
-
}
|
416 |
-
};
|
417 |
-
}
|
418 |
-
return { type: "text", text: item };
|
419 |
-
});
|
420 |
-
}
|
421 |
-
return content;
|
422 |
-
};
|
423 |
-
|
424 |
-
if (isStream) {
|
425 |
-
return {
|
426 |
-
...baseResponse,
|
427 |
-
object: 'chat.completion.chunk',
|
428 |
-
choices: [{
|
429 |
-
index: 0,
|
430 |
-
delta: {
|
431 |
-
content: message
|
432 |
-
}
|
433 |
-
}]
|
434 |
-
};
|
435 |
-
}
|
436 |
-
|
437 |
return {
|
438 |
...baseResponse,
|
439 |
object: 'chat.completion',
|
@@ -441,7 +410,9 @@ class MessageProcessor {
|
|
441 |
index: 0,
|
442 |
message: {
|
443 |
role: 'assistant',
|
444 |
-
content:
|
|
|
|
|
445 |
},
|
446 |
finish_reason: 'stop'
|
447 |
}],
|
@@ -620,15 +591,7 @@ async function handleImageResponse(imageUrl) {
|
|
620 |
const imageContentType = imageBase64Response.headers.get('content-type');
|
621 |
|
622 |
// 修改返回结构,确保返回Markdown格式的图片标签
|
623 |
-
return {
|
624 |
-
type: "image_url",
|
625 |
-
image_url: {
|
626 |
-
url: `data:image/jpg;base64,${base64String}`
|
627 |
-
}
|
628 |
-
};
|
629 |
-
|
630 |
-
// 或者如果需要直接返回可显示的字符串
|
631 |
-
// return ``;
|
632 |
} catch (error) {
|
633 |
console.error('图片处理失败:', error);
|
634 |
return '图片生成失败';
|
|
|
403 |
model: model
|
404 |
};
|
405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
return {
|
407 |
...baseResponse,
|
408 |
object: 'chat.completion',
|
|
|
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 |
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 '图片生成失败';
|