Spaces:
Sleeping
Sleeping
Upload index.js
Browse files
index.js
CHANGED
@@ -403,6 +403,19 @@ class MessageProcessor {
|
|
403 |
model: model
|
404 |
};
|
405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
return {
|
407 |
...baseResponse,
|
408 |
object: 'chat.completion',
|
@@ -410,7 +423,7 @@ class MessageProcessor {
|
|
410 |
index: 0,
|
411 |
message: {
|
412 |
role: 'assistant',
|
413 |
-
content: message
|
414 |
},
|
415 |
finish_reason: 'stop'
|
416 |
}],
|
@@ -615,7 +628,11 @@ async function handleImageResponse(imageUrl) {
|
|
615 |
const imageContentType = imageBase64Response.headers.get('content-type');
|
616 |
|
617 |
// 修改返回结构,确保返回Markdown格式的图片标签
|
618 |
-
return
|
|
|
|
|
|
|
|
|
619 |
} catch (error) {
|
620 |
console.error('图片处理失败:', error);
|
621 |
return '图片生成失败';
|
|
|
403 |
model: model
|
404 |
};
|
405 |
|
406 |
+
// 处理图片响应
|
407 |
+
const processContent = (content) => {
|
408 |
+
if (content?.image_url?.url) {
|
409 |
+
return [{
|
410 |
+
type: "image_url",
|
411 |
+
image_url: {
|
412 |
+
url: content.image_url.url
|
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 |
}],
|
|
|
628 |
const imageContentType = imageBase64Response.headers.get('content-type');
|
629 |
|
630 |
// 修改返回结构,确保返回Markdown格式的图片标签
|
631 |
+
return {
|
632 |
+
image_url: {
|
633 |
+
url: `data:image/jpg;base64,${base64String}`
|
634 |
+
}
|
635 |
+
};
|
636 |
} catch (error) {
|
637 |
console.error('图片处理失败:', error);
|
638 |
return '图片生成失败';
|