|
@@ -4,6 +4,65 @@ import { formatCodePython, formatCodeSql } from './format-code-string';
|
|
|
import generateClientUniqueId from '../../utils/generate-client-unique-id';
|
|
import generateClientUniqueId from '../../utils/generate-client-unique-id';
|
|
|
import { getIcon4Answer } from './get-icon-4-dialog';
|
|
import { getIcon4Answer } from './get-icon-4-dialog';
|
|
|
|
|
|
|
|
|
|
+import formatAnwserString from './format-anwser-string';
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 格式化文档引用的数据
|
|
|
|
|
+ * 将对象转换为字符串
|
|
|
|
|
+ * @param {object} refference
|
|
|
|
|
+ * @param {string} field_key - 数据中的相关字段
|
|
|
|
|
+ */
|
|
|
|
|
+function formatRefferenceString(refference, field_key) {
|
|
|
|
|
+ if (!refference) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const doc_aggs = refference.doc_aggs;
|
|
|
|
|
+
|
|
|
|
|
+ if (!doc_aggs) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const refs_markdown = [];
|
|
|
|
|
+ if (Array.isArray(doc_aggs)) {
|
|
|
|
|
+ doc_aggs.forEach((item, index) => {
|
|
|
|
|
+ refs_markdown.push(
|
|
|
|
|
+ `<li
|
|
|
|
|
+ class="client-formated-markdown-element-item client-formated-markdown-doc-refference-item"
|
|
|
|
|
+ data-doc-id="${item.doc_id}"
|
|
|
|
|
+ data-real-index="${index}"
|
|
|
|
|
+ data-ref-key="${field_key}"
|
|
|
|
|
+ >
|
|
|
|
|
+ <span class="refference-index">${index + 1}</span>
|
|
|
|
|
+ <span class="refference-label">${item.doc_name}</span>
|
|
|
|
|
+ </li>`
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const li_str = refs_markdown.join('');
|
|
|
|
|
+
|
|
|
|
|
+ return `<ul class="client-formated-markdown-element-item client-formated-markdown-doc-refference-container" data-ref-key="${field_key}">${li_str}</ul>`;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function formatRefferenceFlag(answer) {
|
|
|
|
|
+ let cur_text = answer;
|
|
|
|
|
+
|
|
|
|
|
+ cur_text = cur_text.replace(/##\d\$\$/g, function (match, index, full) {
|
|
|
|
|
+ // console.log(match, index, full);
|
|
|
|
|
+ // match示例数据 ##1$$ ##2$$
|
|
|
|
|
+ // 通过两次替换,字符串只剩下序号
|
|
|
|
|
+ const match_v1 = match.replace('##', '');
|
|
|
|
|
+ const match_v2 = match_v1.replace('$$', '');
|
|
|
|
|
+
|
|
|
|
|
+ const ref_idx = match_v2;
|
|
|
|
|
+
|
|
|
|
|
+ return `<span class="client-formated-markdown-element-item client-formated-markdown-doc-refference-flag" data-ref-index="${ref_idx}"></span>`;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return cur_text;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 格式化websocket发送消息的参数
|
|
* 格式化websocket发送消息的参数
|
|
|
* 此方法返回的数据项,为智能体返回的回答的数据
|
|
* 此方法返回的数据项,为智能体返回的回答的数据
|
|
@@ -101,15 +160,6 @@ export default function formatDialogAnswerFromWebsocketReceiveMessage(message_st
|
|
|
|
|
|
|
|
currentMsg.answer = resMessage;
|
|
currentMsg.answer = resMessage;
|
|
|
|
|
|
|
|
- if (resImageUrl) {
|
|
|
|
|
- // 智能数据可能会存在此值
|
|
|
|
|
- const port = window.location.port ? `:${window.location.port}` : '';
|
|
|
|
|
-
|
|
|
|
|
- const image_url = `http://${window.location.hostname}${port}${resImageUrl}`;
|
|
|
|
|
-
|
|
|
|
|
- currentMsg.image_url = image_url;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (resExcelUrl && resExcelName) {
|
|
if (resExcelUrl && resExcelName) {
|
|
|
// 智能数据需要用到的值
|
|
// 智能数据需要用到的值
|
|
|
const port = window.location.port ? `:${window.location.port}` : '';
|
|
const port = window.location.port ? `:${window.location.port}` : '';
|
|
@@ -136,36 +186,83 @@ export default function formatDialogAnswerFromWebsocketReceiveMessage(message_st
|
|
|
currentMsg.file = file;
|
|
currentMsg.file = file;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (resDownloadUrl) {
|
|
|
|
|
+ // 文档报告可能存在此数据(type document_report)
|
|
|
|
|
+ const file_url_arr = decodeURIComponent(resDownloadUrl).split('/');
|
|
|
|
|
+ const file_name = file_url_arr[file_url_arr.length - 1];
|
|
|
|
|
+
|
|
|
|
|
+ const file = {
|
|
|
|
|
+ file_type: 'word',
|
|
|
|
|
+ file_url: resDownloadUrl,
|
|
|
|
|
+ file_name: `${file_name}.docx` || '点击下载'
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ currentMsg.file = file;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // -------------------------------------------------------------
|
|
|
|
|
+ // -------------------------------------------------------------
|
|
|
|
|
+ // -------------------------------------------------------------
|
|
|
|
|
+ // -------------------------------------------------------------
|
|
|
|
|
+ // -------------------------------------------------------------
|
|
|
|
|
+ // -------------------------------------------------------------
|
|
|
|
|
+ // -------------------------------------------------------------
|
|
|
|
|
+ // 智能数据:代码和图片处理
|
|
|
|
|
+ // 上传一个excel,提问:生成一个饼状图
|
|
|
if (resCode) {
|
|
if (resCode) {
|
|
|
// 智能数据可能存在此字段
|
|
// 智能数据可能存在此字段
|
|
|
const code_formated = formatCodePython(resCode);
|
|
const code_formated = formatCodePython(resCode);
|
|
|
|
|
|
|
|
- currentMsg.code = code_formated;
|
|
|
|
|
|
|
+ currentMsg.client_custom_linked_code = code_formated;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (resSQL) {
|
|
if (resSQL) {
|
|
|
// 智能数据可能存在此字段
|
|
// 智能数据可能存在此字段
|
|
|
|
|
+ // 代码数据不能使用markdown解析器进行解析,否则会乱码
|
|
|
const sql_formated = formatCodeSql(resSQL);
|
|
const sql_formated = formatCodeSql(resSQL);
|
|
|
|
|
|
|
|
- currentMsg.sql = sql_formated;
|
|
|
|
|
|
|
+ currentMsg.client_custom_linked_sql = sql_formated;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (resDownloadUrl) {
|
|
|
|
|
- // 文档报告可能存在此数据(type document_report)
|
|
|
|
|
- const file_url_arr = decodeURIComponent(resDownloadUrl).split('/');
|
|
|
|
|
- const file_name = file_url_arr[file_url_arr.length - 1];
|
|
|
|
|
|
|
+ if (resImageUrl) {
|
|
|
|
|
+ // 智能数据可能会存在此值
|
|
|
|
|
+ // const port = window.location.port ? `:${window.location.port}` : '';
|
|
|
|
|
|
|
|
- const file = {
|
|
|
|
|
- file_type: 'word',
|
|
|
|
|
- file_url: resDownloadUrl,
|
|
|
|
|
- file_name: `${file_name}.docx` || '点击下载'
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ // const image_url = `http://${window.location.hostname}${port}${resImageUrl}`;
|
|
|
|
|
|
|
|
- currentMsg.file = file;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // currentMsg.image_url = image_url;
|
|
|
|
|
|
|
|
|
|
+ currentMsg.client_custom_linked_image = resImageUrl;
|
|
|
|
|
+ }
|
|
|
|
|
+ // ------------------------------------------------------
|
|
|
|
|
+ // ------------------------------------------------------
|
|
|
|
|
+ // ------------------------------------------------------
|
|
|
|
|
+ // ------------------------------------------------------
|
|
|
|
|
+ // ------------------------------------------------------
|
|
|
|
|
+ // 知识问答:文档引用
|
|
|
|
|
+
|
|
|
|
|
+ // 处理可能存在的文档引用效果
|
|
|
|
|
+ // 在知识问答板块中,正文存在文档引用效果
|
|
|
|
|
+ currentMsg.answer = formatRefferenceFlag(currentMsg.answer);
|
|
|
|
|
+
|
|
|
|
|
+ // 文档引用效果
|
|
|
if (resRefference) {
|
|
if (resRefference) {
|
|
|
- // 文档引用
|
|
|
|
|
|
|
+ // 文档引用,在知识问答板块中,存在一些文档引用内容
|
|
|
|
|
+ // 需要在对话的答案底部显示文档引用的节点
|
|
|
|
|
+ // 将文档引用相关的数据拼接到答案的底部
|
|
|
|
|
+ const ref_str = formatRefferenceString(resRefference, 'client_custom_linked_refference_full_content');
|
|
|
|
|
+
|
|
|
|
|
+ if (ref_str) {
|
|
|
|
|
+ currentMsg.answer =
|
|
|
|
|
+ currentMsg.answer +
|
|
|
|
|
+ `
|
|
|
|
|
+ ${ref_str}
|
|
|
|
|
+ `;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 添加字段:客户端自定义的相关字段,link完整数据
|
|
|
|
|
+ // 在答案展示部分,需要根据此数据展示文档引用效果
|
|
|
|
|
+ currentMsg.client_custom_linked_refference_full_content = resRefference;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -208,6 +305,8 @@ export default function formatDialogAnswerFromWebsocketReceiveMessage(message_st
|
|
|
if (resType === 'system') {
|
|
if (resType === 'system') {
|
|
|
// 系统消息
|
|
// 系统消息
|
|
|
chat_status = 1;
|
|
chat_status = 1;
|
|
|
|
|
+
|
|
|
|
|
+ currentMsg.answer = resMessage;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (resType === 'close') {
|
|
if (resType === 'close') {
|
|
@@ -245,7 +344,7 @@ export default function formatDialogAnswerFromWebsocketReceiveMessage(message_st
|
|
|
if (resType === 'error') {
|
|
if (resType === 'error') {
|
|
|
// 错误消息
|
|
// 错误消息
|
|
|
chat_status = 3;
|
|
chat_status = 3;
|
|
|
- currentMsg.client_custom_chat_status = 2; // 次轮会话已结束
|
|
|
|
|
|
|
+ currentMsg.client_custom_chat_status = 2; // 本轮会话已结束
|
|
|
currentMsg.client_custom_chat_type = 1; // 修改消息类型: 改为 结束
|
|
currentMsg.client_custom_chat_type = 1; // 修改消息类型: 改为 结束
|
|
|
|
|
|
|
|
currentMsg.answer = resMessage;
|
|
currentMsg.answer = resMessage;
|
|
@@ -257,8 +356,26 @@ export default function formatDialogAnswerFromWebsocketReceiveMessage(message_st
|
|
|
*/
|
|
*/
|
|
|
currentMsg.client_custom_unique_id = generateClientUniqueId(currentMsg.answer);
|
|
currentMsg.client_custom_unique_id = generateClientUniqueId(currentMsg.answer);
|
|
|
|
|
|
|
|
|
|
+ // if (currentMsg.answer) {
|
|
|
|
|
+ // // 将markdown转换为html文件
|
|
|
|
|
+ // currentMsg.answer = formatAnwserString(currentMsg.answer);
|
|
|
|
|
+
|
|
|
|
|
+ // if (currentMsg.client_custom_linked_code) {
|
|
|
|
|
+ // currentMsg.answer = currentMsg.answer + currentMsg.client_custom_linked_code;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // // 由于SQL和代码不能通过markdown解析,所以此处进行字符串的拼接
|
|
|
|
|
+ // if (currentMsg.client_custom_linked_sql) {
|
|
|
|
|
+ // currentMsg.answer = currentMsg.answer + currentMsg.client_custom_linked_sql;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ // if (currentMsg.client_custom_linked_image) {
|
|
|
|
|
+ // currentMsg.answer = currentMsg.answer + `<img src="${currentMsg.client_custom_linked_image}" />`;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
- status: chat_status, // 0 未开始 1 进行中 2 已结束 3 错误
|
|
|
|
|
|
|
+ status: chat_status, // 本轮会话的状态:0 未开始 1 进行中 2 已结束 3 错误
|
|
|
message: chat_msg,
|
|
message: chat_msg,
|
|
|
data: currentMsg
|
|
data: currentMsg
|
|
|
};
|
|
};
|