From 091ff8e04c545d5e1028479b7c7553589d886bd2 Mon Sep 17 00:00:00 2001 From: cc500 <2014434568@qq.com> Date: Wed, 9 Apr 2025 16:44:09 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=86=E5=89=B2?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/conversation.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/store/conversation.ts b/src/store/conversation.ts index 492821d9..b8b271dd 100644 --- a/src/store/conversation.ts +++ b/src/store/conversation.ts @@ -82,6 +82,19 @@ export const useSessionStore = defineStore('conversation', () => { const appList = ref(); // ai回复是否还在生成中 const isAnswerGenerating = ref(false); + + function splitDataString(input) { + if (input.includes('"data: ')) { + return [input]; + } + const parts = input.split(/data: /g).filter(part => part.trim() !== ''); + if (input.startsWith('data: ')) { + return parts.map(part => 'data: ' + part); + } else { + return [parts[0], ...parts.slice(1).map(part => 'data: ' + part)]; + } +} + /** * 请求流式数据 * @param params @@ -240,7 +253,6 @@ export const useSessionStore = defineStore('conversation', () => { } const { done, value } = await reader.read(); const decodedValue = addItem + decoder.decode(value, { stream: true }); - if (done) { if (excelPath.value.length > 0) { conversationItem.message[conversationItem.currentInd] += @@ -255,10 +267,12 @@ export const useSessionStore = defineStore('conversation', () => { } break; } + if (decodedValue.includes('data: [DONE]')) { + isEnd = true; + continue; + } // 同一时间戳传来的decodeValue是含有三条信息的合并,so需要分割 - const lines = decodedValue.split('data:'); - // 删除第一个空字符串 - lines.shift(); + const lines = splitDataString(decodedValue); lines.forEach((line) => { // 这里json解析 const message = Object( -- Gitee From c2a57452a3bc9dcd2823154fd8fd59e215839040 Mon Sep 17 00:00:00 2001 From: cc500 <2014434568@qq.com> Date: Thu, 10 Apr 2025 11:10:09 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9C=80=E5=B0=8F?= =?UTF-8?q?=E5=AE=BD=E5=BA=A6=E5=9C=A8=E7=AC=94=E7=94=B5=E4=B8=8A=E7=9A=84?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/conversation.ts | 12 ++++++++++-- src/views/styles/createApp.scss | 6 +++--- src/views/styles/workFlowArrange.scss | 2 +- src/views/styles/workFlowDebug.scss | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/store/conversation.ts b/src/store/conversation.ts index b8b271dd..e3058f20 100644 --- a/src/store/conversation.ts +++ b/src/store/conversation.ts @@ -82,7 +82,11 @@ export const useSessionStore = defineStore('conversation', () => { const appList = ref(); // ai回复是否还在生成中 const isAnswerGenerating = ref(false); - + /** + * 将所有获取的数据进行data: \n\n 分割只保留有效信息,更容易处理最后的状态码 + * @param input + * { + **/ function splitDataString(input) { if (input.includes('"data: ')) { return [input]; @@ -94,7 +98,6 @@ export const useSessionStore = defineStore('conversation', () => { return [parts[0], ...parts.slice(1).map(part => 'data: ' + part)]; } } - /** * 请求流式数据 * @param params @@ -245,6 +248,7 @@ export const useSessionStore = defineStore('conversation', () => { echartsObj.value = {}; txt2imgPath.value = ''; let addItem = ''; + // var bufferString = ''; while (isEnd) { if (isPaused.value) { // 手动暂停输出 @@ -253,6 +257,10 @@ export const useSessionStore = defineStore('conversation', () => { } const { done, value } = await reader.read(); const decodedValue = addItem + decoder.decode(value, { stream: true }); + console.log(value); + console.log(decodedValue); + // bufferString += decodedValue; + if (done) { if (excelPath.value.length > 0) { conversationItem.message[conversationItem.currentInd] += diff --git a/src/views/styles/createApp.scss b/src/views/styles/createApp.scss index f11e6f6a..15d735b2 100644 --- a/src/views/styles/createApp.scss +++ b/src/views/styles/createApp.scss @@ -11,7 +11,7 @@ display: flex; position: relative; align-items: center; - min-width: 1628px; + // min-width: 1628px; .createAppContainerMenu { display: flex; gap: 16px; @@ -81,7 +81,7 @@ } .createAppContainerMain { - min-width: 1200px; + // min-width: 1200px; margin-top: 16px; padding: 24px 24px 24px 16px; display: flex; @@ -94,7 +94,7 @@ display: flex; gap: 24px; flex: 1; - min-width: 1628px; + // min-width: 1628px; max-height: calc(100% - 112px); margin-top: 16px; } diff --git a/src/views/styles/workFlowArrange.scss b/src/views/styles/workFlowArrange.scss index f0c25be0..ce21161c 100644 --- a/src/views/styles/workFlowArrange.scss +++ b/src/views/styles/workFlowArrange.scss @@ -134,7 +134,7 @@ .workFlowContainerRight { flex: 1; - min-width: 1292px; + // min-width: 1292px; background-color: var(--flow-canvas-bg); border-radius: 8px; } diff --git a/src/views/styles/workFlowDebug.scss b/src/views/styles/workFlowDebug.scss index f1070ea1..0b5eea2c 100644 --- a/src/views/styles/workFlowDebug.scss +++ b/src/views/styles/workFlowDebug.scss @@ -1,5 +1,5 @@ .workFlowDebug { - width: 700px; + width: 40%; height: 100%; position: absolute; right: 0; -- Gitee From 04e117125381fc168cb26b1e1e59c249e3096956 Mon Sep 17 00:00:00 2001 From: cc500 <2014434568@qq.com> Date: Thu, 10 Apr 2025 11:14:09 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E5=92=8C=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/conversation.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/store/conversation.ts b/src/store/conversation.ts index e3058f20..ff90b6cb 100644 --- a/src/store/conversation.ts +++ b/src/store/conversation.ts @@ -248,7 +248,6 @@ export const useSessionStore = defineStore('conversation', () => { echartsObj.value = {}; txt2imgPath.value = ''; let addItem = ''; - // var bufferString = ''; while (isEnd) { if (isPaused.value) { // 手动暂停输出 @@ -257,10 +256,6 @@ export const useSessionStore = defineStore('conversation', () => { } const { done, value } = await reader.read(); const decodedValue = addItem + decoder.decode(value, { stream: true }); - console.log(value); - console.log(decodedValue); - // bufferString += decodedValue; - if (done) { if (excelPath.value.length > 0) { conversationItem.message[conversationItem.currentInd] += -- Gitee From a9a9a9fc3dea710336847181ff83b660518452f2 Mon Sep 17 00:00:00 2001 From: cc500 <2014434568@qq.com> Date: Thu, 10 Apr 2025 11:15:47 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=8E=BB=E9=99=A4css=E4=B8=AD=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/styles/createApp.scss | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/views/styles/createApp.scss b/src/views/styles/createApp.scss index 15d735b2..e8f94c45 100644 --- a/src/views/styles/createApp.scss +++ b/src/views/styles/createApp.scss @@ -11,7 +11,6 @@ display: flex; position: relative; align-items: center; - // min-width: 1628px; .createAppContainerMenu { display: flex; gap: 16px; @@ -81,7 +80,6 @@ } .createAppContainerMain { - // min-width: 1200px; margin-top: 16px; padding: 24px 24px 24px 16px; display: flex; @@ -94,7 +92,6 @@ display: flex; gap: 24px; flex: 1; - // min-width: 1628px; max-height: calc(100% - 112px); margin-top: 16px; } -- Gitee