修复
This commit is contained in:
@@ -77,15 +77,33 @@ export const chatApi = {
|
|||||||
eventSource.addEventListener('message', (event) => {
|
eventSource.addEventListener('message', (event) => {
|
||||||
try {
|
try {
|
||||||
// 解析JSON字符串,处理Unicode转义
|
// 解析JSON字符串,处理Unicode转义
|
||||||
const data = JSON.parse(event.data);
|
let data = JSON.parse(event.data);
|
||||||
|
// 过滤掉SSE格式残留的data:前缀、空行和思考标签
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
data = data
|
||||||
|
.replace(/^data:/gm, '')
|
||||||
|
.replace(/^\s*[\r\n]/gm, '')
|
||||||
|
.replace(/<\/?think>/gi, '');
|
||||||
|
}
|
||||||
|
if (data && data.trim()) {
|
||||||
fullMessage += data;
|
fullMessage += data;
|
||||||
callback?.onMessage?.(data);
|
callback?.onMessage?.(data);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// 如果不是JSON,直接使用原始数据
|
// 如果不是JSON,直接使用原始数据
|
||||||
const data = event.data;
|
let data = event.data;
|
||||||
|
// 过滤掉SSE格式残留的data:前缀、空行和思考标签
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
data = data
|
||||||
|
.replace(/^data:/gm, '')
|
||||||
|
.replace(/^\s*[\r\n]/gm, '')
|
||||||
|
.replace(/<\/?think>/gi, '');
|
||||||
|
}
|
||||||
|
if (data && data.trim()) {
|
||||||
fullMessage += data;
|
fullMessage += data;
|
||||||
callback?.onMessage?.(data);
|
callback?.onMessage?.(data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听结束事件
|
// 监听结束事件
|
||||||
@@ -345,15 +363,33 @@ export const chatApi = {
|
|||||||
eventSource.addEventListener('message', (event) => {
|
eventSource.addEventListener('message', (event) => {
|
||||||
try {
|
try {
|
||||||
// 解析JSON字符串,处理Unicode转义
|
// 解析JSON字符串,处理Unicode转义
|
||||||
const data = JSON.parse(event.data);
|
let data = JSON.parse(event.data);
|
||||||
|
// 过滤掉SSE格式残留的data:前缀、空行和思考标签
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
data = data
|
||||||
|
.replace(/^data:/gm, '')
|
||||||
|
.replace(/^\s*[\r\n]/gm, '')
|
||||||
|
.replace(/<\/?think>/gi, '');
|
||||||
|
}
|
||||||
|
if (data && data.trim()) {
|
||||||
fullMessage += data;
|
fullMessage += data;
|
||||||
callback?.onMessage?.(data);
|
callback?.onMessage?.(data);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// 如果不是JSON,直接使用原始数据
|
// 如果不是JSON,直接使用原始数据
|
||||||
const data = event.data;
|
let data = event.data;
|
||||||
|
// 过滤掉SSE格式残留的data:前缀、空行和思考标签
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
data = data
|
||||||
|
.replace(/^data:/gm, '')
|
||||||
|
.replace(/^\s*[\r\n]/gm, '')
|
||||||
|
.replace(/<\/?think>/gi, '');
|
||||||
|
}
|
||||||
|
if (data && data.trim()) {
|
||||||
fullMessage += data;
|
fullMessage += data;
|
||||||
callback?.onMessage?.(data);
|
callback?.onMessage?.(data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听结束事件
|
// 监听结束事件
|
||||||
|
|||||||
@@ -736,7 +736,6 @@ function formatTimestamp(timestamp: number): string {
|
|||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
color: #4A5565;
|
color: #4A5565;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
white-space: pre-wrap;
|
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
letter-spacing: -0.01em;
|
letter-spacing: -0.01em;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,13 +229,14 @@
|
|||||||
|
|
||||||
<!-- 文档分段对话框 -->
|
<!-- 文档分段对话框 -->
|
||||||
<DocumentSegmentDialog
|
<DocumentSegmentDialog
|
||||||
v-if="selectedDocument && selectedDocument.difyDocumentId && props.knowledge?.difyDatasetId"
|
v-if="segmentDialogVisible && selectedDocument && selectedDocument.difyDocumentId && props.knowledge?.difyDatasetId"
|
||||||
|
:key="selectedDocument.difyDocumentId"
|
||||||
:model-value="segmentDialogVisible"
|
:model-value="segmentDialogVisible"
|
||||||
:dataset-id="props.knowledge.difyDatasetId"
|
:dataset-id="props.knowledge.difyDatasetId"
|
||||||
:document-id="selectedDocument.difyDocumentId"
|
:document-id="selectedDocument.difyDocumentId"
|
||||||
:can-write="hasWritePermission"
|
:can-write="hasWritePermission"
|
||||||
:can-delete="hasDeletePermission"
|
:can-delete="hasDeletePermission"
|
||||||
@update:model-value="segmentDialogVisible = $event"
|
@update:model-value="handleSegmentDialogClose"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -407,13 +408,19 @@ function handleViewSegments(document: AiUploadFile) {
|
|||||||
segmentDialogVisible.value = true;
|
segmentDialogVisible.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭分段对话框
|
||||||
|
function handleSegmentDialogClose(val: boolean) {
|
||||||
|
segmentDialogVisible.value = val;
|
||||||
|
if (!val) {
|
||||||
|
selectedDocument.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 下载文件
|
// 下载文件
|
||||||
function handleDownload(document: AiUploadFile) {
|
function handleDownload(document: AiUploadFile) {
|
||||||
if (document.sysFileId) {
|
if (document.sysFileId) {
|
||||||
window.open(`/api/file/download/${document.sysFileId}`, '_blank');
|
window.open(`${FILE_DOWNLOAD_URL}${document.sysFileId}`, '_blank');
|
||||||
} else if (document.filePath) {
|
}else {
|
||||||
window.open(`/api/file/download/${document.filePath}`, '_blank');
|
|
||||||
} else {
|
|
||||||
ElMessage.warning('文件路径不存在');
|
ElMessage.warning('文件路径不存在');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -585,6 +585,9 @@ function formatMessageTime(dateStr: string | undefined) {
|
|||||||
|
|
||||||
function formatMarkdown(content: string) {
|
function formatMarkdown(content: string) {
|
||||||
let html = content;
|
let html = content;
|
||||||
|
// 过滤掉思考标签和data:前缀
|
||||||
|
html = html.replace(/<\/?think>/gi, '');
|
||||||
|
html = html.replace(/^data:/gm, '');
|
||||||
html = html.replace(/```([\s\S]*?)```/g, '<pre><code>$1</code></pre>');
|
html = html.replace(/```([\s\S]*?)```/g, '<pre><code>$1</code></pre>');
|
||||||
html = html.replace(/`([^`]+)`/g, '<code>$1</code>');
|
html = html.replace(/`([^`]+)`/g, '<code>$1</code>');
|
||||||
html = html.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
html = html.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
||||||
|
|||||||
@@ -1114,6 +1114,10 @@ function formatMarkdown(content: string) {
|
|||||||
// 简单的 Markdown 转换(可以使用 marked.js 等库进行更复杂的转换)
|
// 简单的 Markdown 转换(可以使用 marked.js 等库进行更复杂的转换)
|
||||||
let html = content;
|
let html = content;
|
||||||
|
|
||||||
|
// 过滤掉思考标签和data:前缀
|
||||||
|
html = html.replace(/<\/?think>/gi, '');
|
||||||
|
html = html.replace(/^data:/gm, '');
|
||||||
|
|
||||||
// 代码块
|
// 代码块
|
||||||
html = html.replace(/```(\w+)?\n([\s\S]*?)```/g, '<pre><code>$2</code></pre>');
|
html = html.replace(/```(\w+)?\n([\s\S]*?)```/g, '<pre><code>$2</code></pre>');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user