Skip to content

Commit 5cd5fa9

Browse files
Merge remote-tracking branch 'origin/v2' into v2
2 parents be13ce5 + 3f9049a commit 5cd5fa9

File tree

14 files changed

+511
-533
lines changed

14 files changed

+511
-533
lines changed

ui/src/components/ai-chat/index.vue

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ import bus from '@/bus'
195195
import { throttle } from 'lodash-es'
196196
import { copyClick } from '@/utils/clipboard'
197197
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
198+
import { getWrite } from '@/utils/chat'
198199
199200
provide('upload', (file: any, loading?: Ref<boolean>) => {
200201
return props.type === 'debug-ai-chat'
@@ -560,86 +561,7 @@ function getChartOpenId(chat?: any, problem?: string, re_chat?: boolean, other_p
560561
})
561562
}
562563
563-
/**
564-
* 获取一个递归函数,处理流式数据
565-
* @param chat 每一条对话记录
566-
* @param reader 流数据
567-
* @param stream 是否是流式数据
568-
*/
569-
const getWrite = (chat: any, reader: any, stream: boolean) => {
570-
let tempResult = ''
571-
572-
const write_stream = async () => {
573-
try {
574-
while (true) {
575-
const { done, value } = await reader.read()
576-
577-
if (done) {
578-
ChatManagement.close(chat.id)
579-
return
580-
}
581-
582-
const decoder = new TextDecoder('utf-8')
583-
let str = decoder.decode(value, { stream: true })
584-
585-
tempResult += str
586-
const split = tempResult.match(/data:.*?}\n\n/g)
587-
if (split) {
588-
str = split.join('')
589-
tempResult = tempResult.replace(str, '')
590-
591-
// 批量处理所有 chunk
592-
for (const item of split) {
593-
const chunk = JSON.parse(item.replace('data:', ''))
594-
chat.chat_id = chunk.chat_id
595-
chat.record_id = chunk.chat_record_id
596-
597-
if (!chunk.is_end) {
598-
ChatManagement.appendChunk(chat.id, chunk)
599-
}
600-
601-
if (chunk.is_end) {
602-
return Promise.resolve()
603-
}
604-
}
605-
}
606-
// 如果没有匹配到完整chunk,继续读取下一块
607-
}
608-
} catch (e) {
609-
return Promise.reject(e)
610-
}
611-
}
612-
613-
const write_json = async () => {
614-
try {
615-
while (true) {
616-
const { done, value } = await reader.read()
617-
618-
if (done) {
619-
const result_block = JSON.parse(tempResult)
620-
if (result_block.code === 500) {
621-
return Promise.reject(result_block.message)
622-
} else {
623-
if (result_block.content) {
624-
ChatManagement.append(chat.id, result_block.content)
625-
}
626-
}
627-
ChatManagement.close(chat.id)
628-
return
629-
}
630564
631-
if (value) {
632-
const decoder = new TextDecoder('utf-8')
633-
tempResult += decoder.decode(value)
634-
}
635-
}
636-
} catch (e) {
637-
return Promise.reject(e)
638-
}
639-
}
640-
641-
return stream ? write_stream : write_json
642-
}
643565
const errorWrite = (chat: any, message?: string) => {
644566
ChatManagement.addChatRecord(chat, 50, loading)
645567
ChatManagement.write(chat.id)

ui/src/locales/lang/en-US/views/tool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default {
1010
toolWorkflow: {
1111
creatToolWorkflow: 'Create Workflow',
1212
toActiveTip: 'Unable to enable. Please publish the workflow first.',
13+
debugResult: 'Debug results',
1314
},
1415
dataSource: {
1516
title: 'Data Source',

ui/src/locales/lang/zh-CN/views/tool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default {
99
toolWorkflow: {
1010
creatToolWorkflow: '创建工作流',
1111
toActiveTip: '无法启用,请先发布工作流。',
12+
debugResult:'调试结果'
1213
},
1314
dataSource: {
1415
title: '数据源',

ui/src/locales/lang/zh-Hant/views/tool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default {
99
toolWorkflow: {
1010
creatToolWorkflow: '創建工作流',
1111
toActiveTip: '無法啓用,請先發布工作流。',
12+
debugResult: '調試結果',
1213
},
1314
dataSource: {
1415
title: '數據源',

ui/src/styles/app.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ h5 {
255255
padding-bottom: 0;
256256
}
257257

258+
.pr-8 {
259+
padding-right: 8px;
260+
}
261+
258262
.float-right {
259263
float: right;
260264
}

ui/src/utils/chat.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { ChatManagement, type chatType } from '@/api/type/application'
2+
/**
3+
* 获取一个递归函数,处理流式数据
4+
* @param chat 每一条对话记录
5+
* @param reader 流数据
6+
* @param stream 是否是流式数据
7+
*/
8+
export const getWrite = (chat: any, reader: any, stream: boolean) => {
9+
let tempResult = ''
10+
11+
const write_stream = async () => {
12+
try {
13+
while (true) {
14+
const { done, value } = await reader.read()
15+
16+
if (done) {
17+
ChatManagement.close(chat.id)
18+
return
19+
}
20+
21+
const decoder = new TextDecoder('utf-8')
22+
let str = decoder.decode(value, { stream: true })
23+
24+
tempResult += str
25+
const split = tempResult.match(/data:.*?}\n\n/g)
26+
if (split) {
27+
str = split.join('')
28+
tempResult = tempResult.replace(str, '')
29+
30+
// 批量处理所有 chunk
31+
for (const item of split) {
32+
const chunk = JSON.parse(item.replace('data:', ''))
33+
chat.chat_id = chunk.chat_id
34+
chat.record_id = chunk.chat_record_id
35+
36+
if (!chunk.is_end) {
37+
ChatManagement.appendChunk(chat.id, chunk)
38+
}
39+
40+
if (chunk.is_end) {
41+
return Promise.resolve()
42+
}
43+
}
44+
}
45+
// 如果没有匹配到完整chunk,继续读取下一块
46+
}
47+
} catch (e) {
48+
return Promise.reject(e)
49+
}
50+
}
51+
52+
const write_json = async () => {
53+
try {
54+
while (true) {
55+
const { done, value } = await reader.read()
56+
57+
if (done) {
58+
const result_block = JSON.parse(tempResult)
59+
if (result_block.code === 500) {
60+
return Promise.reject(result_block.message)
61+
} else {
62+
if (result_block.content) {
63+
ChatManagement.append(chat.id, result_block.content)
64+
}
65+
}
66+
ChatManagement.close(chat.id)
67+
return
68+
}
69+
70+
if (value) {
71+
const decoder = new TextDecoder('utf-8')
72+
tempResult += decoder.decode(value)
73+
}
74+
}
75+
} catch (e) {
76+
return Promise.reject(e)
77+
}
78+
}
79+
80+
return stream ? write_stream : write_json
81+
}

ui/src/views/tool-workflow/component/debug-drawer/index.vue

Lines changed: 0 additions & 86 deletions
This file was deleted.

ui/src/views/tool-workflow/component/debug/index.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

ui/src/views/tool-workflow/component/debug/parameters/index.vue

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)