From 98ddf2bd816abe50ac291b5810da753624192167 Mon Sep 17 00:00:00 2001
From: liudong <liudong>
Date: 星期四, 08 八月 2024 19:08:50 +0800
Subject: [PATCH] 解析方法页面bug修改
---
src/views/session/sessionRecordsManager/index.vue | 63 +++++++++++++++++++++----------
1 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/src/views/session/sessionRecordsManager/index.vue b/src/views/session/sessionRecordsManager/index.vue
index d64b2df..4b22809 100644
--- a/src/views/session/sessionRecordsManager/index.vue
+++ b/src/views/session/sessionRecordsManager/index.vue
@@ -306,6 +306,7 @@
import { useAppStore } from '@/store';
import { computed, nextTick, onMounted, reactive, ref } from 'vue';
import { Message } from '@arco-design/web-vue';
+ import { EventSourceParserStream } from 'eventsource-parser/stream';
import moment from 'moment';
import AddSession from '@/views/session/sessionManager/components/addSession.vue';
import {
@@ -314,6 +315,8 @@
getSessionDetailsApi,
sessionListApi,
} from '@/api/session';
+ import { getAuthorization } from "@/utils/auth";
+
const sessionDetailList = ref([]); //鏍规嵁浼氳瘽id鍑烘潵鐨勪細璇濊鎯�
const sessionList = ref([]); //浼氳瘽鍒楄〃
@@ -353,30 +356,49 @@
return;
}
if (inputMsg.value) {
- const data = await chatApi({
- conversation_id: activeSessionId.value,
- messages: inputMsg.value,
+ sessionDetailList.value.push({ "content": inputMsg.value, "role": "user" });
+ sessionDetailList.value.push({ "role": "last" });
+ refreshScroll();
+ const response = await fetch("/api/tech/cloudminds/query?modeltype=localragflow", {
+ method: 'POST',
+ headers: {
+ 'Authorization': getAuthorization(),
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ conversation_id: activeSessionId.value,
+ messages: inputMsg.value,
+ }),
});
- if (data) {
- chatDis.value = false;
- // inputMsg.value = '';
- // querySessionDetail({ id: activeSessionId.value });
- }
- const res = await getSessionDetailsApi(activeSessionId.value);
- if (res.code === 200) {
- sessionDetailList.value = res.data.message.map((item, index) => {
- if (index === res.data.message.length - 1) {
- item.role = 'last';
- displayedText.value = '';
- currIndex.value = 0;
- streamStr.value = item.content;
- startDisplayStr();
+ const reader = response?.body
+ ?.pipeThrough(new TextDecoderStream())
+ .pipeThrough(new EventSourceParserStream())
+ .getReader();
+ currIndex.value = 0;
+ while (true) {
+ const x = await reader?.read();
+ if (x) {
+ const { done, value } = x;
+ try {
+ const val = JSON.parse(value?.data || '');
+ const d = val?.data;
+ if (typeof d !== "boolean") {
+
+ console.info("data:", d);
+ streamStr.value = d.content;
+ startDisplayStr();
+ }
+ } catch (e) {
+ console.warn(e);
}
- return item;
- });
- refreshScroll();
+ if (done) {
+ console.info('done');
+ break;
+ }
+ }
}
+ chatDis.value=false;
inputMsg.value = '';
} else {
Message.warning('娑堟伅涓嶈兘涓虹┖');
@@ -428,6 +450,7 @@
displayedText.value += res[currIndex.value];
currIndex.value++;
setTimeout(startDisplayStr, 100);
+ refreshScroll();
} else {
clearTimeout(timer!);
timer = null;
--
Gitblit v1.8.0