|
@@ -13,6 +13,7 @@ import {
|
|
|
} from './format-dialog-answer-custom-markdown-str';
|
|
} from './format-dialog-answer-custom-markdown-str';
|
|
|
|
|
|
|
|
import formatDialogAnswerAttachedHtmlBeforeRender from './format-dialog-answer-attached-html-before-render';
|
|
import formatDialogAnswerAttachedHtmlBeforeRender from './format-dialog-answer-attached-html-before-render';
|
|
|
|
|
+import { isDate } from 'lodash-es';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 格式化sse发送消息的参数
|
|
* 格式化sse发送消息的参数
|
|
@@ -25,10 +26,14 @@ import formatDialogAnswerAttachedHtmlBeforeRender from './format-dialog-answer-a
|
|
|
* @param {object} preMsg - 前一次的消息,如果是流式消息,则需要上一次的Content进行拼接,从而形成新的消息
|
|
* @param {object} preMsg - 前一次的消息,如果是流式消息,则需要上一次的Content进行拼接,从而形成新的消息
|
|
|
* @returns
|
|
* @returns
|
|
|
*/
|
|
*/
|
|
|
|
|
+let fountThink = false;
|
|
|
|
|
+let message_id = '';
|
|
|
export default function formatDialogAnswerFromSseReceiveMessage(message_obj, preMsg, agentInfo, mixAnswer) {
|
|
export default function formatDialogAnswerFromSseReceiveMessage(message_obj, preMsg, agentInfo, mixAnswer) {
|
|
|
- console.log(message_obj, 2222);
|
|
|
|
|
const res_content = message_obj.data;
|
|
const res_content = message_obj.data;
|
|
|
-
|
|
|
|
|
|
|
+ if (message_id !== message_obj?.message_id) {
|
|
|
|
|
+ fountThink = false;
|
|
|
|
|
+ message_id = message_obj?.message_id;
|
|
|
|
|
+ }
|
|
|
// 复制一份原消息内容
|
|
// 复制一份原消息内容
|
|
|
const copyPreMsg = jsonParse(jsonStringify(preMsg));
|
|
const copyPreMsg = jsonParse(jsonStringify(preMsg));
|
|
|
|
|
|
|
@@ -107,7 +112,8 @@ export default function formatDialogAnswerFromSseReceiveMessage(message_obj, pre
|
|
|
// sql: '',
|
|
// sql: '',
|
|
|
// reference: ''
|
|
// reference: ''
|
|
|
// 会话的message_id
|
|
// 会话的message_id
|
|
|
- client_custom_chat_message_id: ''
|
|
|
|
|
|
|
+ client_custom_chat_message_id: '',
|
|
|
|
|
+ deep_answer: ''
|
|
|
// client_custom_item_think: false, // 是否有思考
|
|
// client_custom_item_think: false, // 是否有思考
|
|
|
// client_custom_item_think_content: '', //思考内容
|
|
// client_custom_item_think_content: '', //思考内容
|
|
|
// client_custom_item_internet: false, //是否联网
|
|
// client_custom_item_internet: false, //是否联网
|
|
@@ -126,12 +132,9 @@ export default function formatDialogAnswerFromSseReceiveMessage(message_obj, pre
|
|
|
currentMsg.client_custom_item_internet_list = res_content.outputs.json;
|
|
currentMsg.client_custom_item_internet_list = res_content.outputs.json;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- console.log(message_obj.message_id, 3333);
|
|
|
|
|
- if (message_obj.message_id) {
|
|
|
|
|
- currentMsg.client_custom_chat_message_id = message_obj.message_id;
|
|
|
|
|
- }
|
|
|
|
|
- currentMsg.client_custom_chat_message_id = message_obj.message_id || '';
|
|
|
|
|
- console.log(currentMsg.client_custom_chat_message_id, 444);
|
|
|
|
|
|
|
+ // console.log(message_obj.message_id, 3333);
|
|
|
|
|
+
|
|
|
|
|
+ // console.log(currentMsg.client_custom_chat_message_id, 444);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 将前面websocket发来的数据,合并到当前的消息中
|
|
* 将前面websocket发来的数据,合并到当前的消息中
|
|
@@ -257,9 +260,26 @@ export default function formatDialogAnswerFromSseReceiveMessage(message_obj, pre
|
|
|
if (resType === 'stream') {
|
|
if (resType === 'stream') {
|
|
|
// 流消息
|
|
// 流消息
|
|
|
chat_status = 1;
|
|
chat_status = 1;
|
|
|
- currentMsg.answer = currentMsg.answer += res_content.answer;
|
|
|
|
|
-
|
|
|
|
|
- // // 拼接数据
|
|
|
|
|
|
|
+ if (message_obj.isDeep) {
|
|
|
|
|
+ if (!fountThink) {
|
|
|
|
|
+ currentMsg.client_custom_chat_deep_loading = true;
|
|
|
|
|
+ currentMsg.deep_answer = currentMsg.deep_answer += res_content.answer;
|
|
|
|
|
+ if (res_content.answer == '</think>') {
|
|
|
|
|
+ currentMsg.client_custom_chat_deep_loading = false;
|
|
|
|
|
+ fountThink = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ currentMsg.answer = currentMsg.answer += res_content.answer;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ currentMsg.answer = currentMsg.answer += res_content.answer;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 测试代码
|
|
|
|
|
+ // if (!message_obj.isDeep) {
|
|
|
|
|
+ // currentMsg.client_custom_chat_deep_loading = true;
|
|
|
|
|
+ // currentMsg.deep_answer = currentMsg.deep_answer += res_content.answer;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // // // 拼接数据
|
|
|
// if (preMsg && preMsg.answer) {
|
|
// if (preMsg && preMsg.answer) {
|
|
|
// currentMsg.answer = preMsg.answer + image + resMessage;
|
|
// currentMsg.answer = preMsg.answer + image + resMessage;
|
|
|
// } else {
|
|
// } else {
|
|
@@ -447,9 +467,13 @@ export default function formatDialogAnswerFromSseReceiveMessage(message_obj, pre
|
|
|
// * 在answer字符串渲染到界面之前,在answer后拼接的html字符串
|
|
// * 在answer字符串渲染到界面之前,在answer后拼接的html字符串
|
|
|
// */
|
|
// */
|
|
|
// currentMsg.client_custom_attached_html_before_render = temp_html_str;
|
|
// currentMsg.client_custom_attached_html_before_render = temp_html_str;
|
|
|
- console.log(currentMsg.client_custom_chat_message_id, 6666);
|
|
|
|
|
|
|
+
|
|
|
formatDialogAnswerAttachedHtmlBeforeRender(currentMsg);
|
|
formatDialogAnswerAttachedHtmlBeforeRender(currentMsg);
|
|
|
- console.log(currentMsg.client_custom_chat_message_id, 8888);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (message_obj.message_id) {
|
|
|
|
|
+ currentMsg.client_custom_chat_message_id = message_obj.message_id;
|
|
|
|
|
+ }
|
|
|
|
|
+ currentMsg.client_custom_chat_message_id = message_obj.message_id || '';
|
|
|
return {
|
|
return {
|
|
|
status: chat_status, // 本轮会话的状态:0 未开始 1 进行中 2 已结束 3 错误
|
|
status: chat_status, // 本轮会话的状态:0 未开始 1 进行中 2 已结束 3 错误
|
|
|
message: chat_msg,
|
|
message: chat_msg,
|