Spaces:
Sleeping
Sleeping
Upload index.js
Browse files
index.js
CHANGED
@@ -399,23 +399,10 @@ class MessageProcessor {
|
|
399 |
static createChatResponse(message, model, isStream = false) {
|
400 |
const baseResponse = {
|
401 |
id: `chatcmpl-${uuidv4()}`,
|
402 |
-
created: Math.floor(Date.now()
|
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,7 +410,7 @@ class MessageProcessor {
|
|
423 |
index: 0,
|
424 |
message: {
|
425 |
role: 'assistant',
|
426 |
-
content:
|
427 |
},
|
428 |
finish_reason: 'stop'
|
429 |
}],
|
@@ -539,7 +526,7 @@ async function handleNormalResponse(response, model, res) {
|
|
539 |
const dataImage = await handleImageResponse(imageUrl);
|
540 |
console.log('处理后的图片数据:', JSON.stringify(dataImage, null, 2));
|
541 |
|
542 |
-
const responseData = MessageProcessor.createChatResponse(
|
543 |
console.log('最终的响应对象:', JSON.stringify(responseData, null, 2));
|
544 |
res.json(responseData);
|
545 |
} else {
|
@@ -602,12 +589,7 @@ async function handleImageResponse(imageUrl) {
|
|
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 '图片生成失败';
|
|
|
399 |
static createChatResponse(message, model, isStream = false) {
|
400 |
const baseResponse = {
|
401 |
id: `chatcmpl-${uuidv4()}`,
|
402 |
+
created: Math.floor(Date.now()/1000),
|
403 |
model: model
|
404 |
};
|
405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
return {
|
407 |
...baseResponse,
|
408 |
object: 'chat.completion',
|
|
|
410 |
index: 0,
|
411 |
message: {
|
412 |
role: 'assistant',
|
413 |
+
content: message // 直接返回原始消息
|
414 |
},
|
415 |
finish_reason: 'stop'
|
416 |
}],
|
|
|
526 |
const dataImage = await handleImageResponse(imageUrl);
|
527 |
console.log('处理后的图片数据:', JSON.stringify(dataImage, null, 2));
|
528 |
|
529 |
+
const responseData = MessageProcessor.createChatResponse(dataImage, model);
|
530 |
console.log('最终的响应对象:', JSON.stringify(responseData, null, 2));
|
531 |
res.json(responseData);
|
532 |
} else {
|
|
|
589 |
const imageContentType = imageBase64Response.headers.get('content-type');
|
590 |
|
591 |
// 修改返回结构,确保返回Markdown格式的图片标签
|
592 |
+
return ``; // Markdown格式
|
|
|
|
|
|
|
|
|
|
|
593 |
} catch (error) {
|
594 |
console.error('图片处理失败:', error);
|
595 |
return '图片生成失败';
|