chd 4 months ago
parent
commit
4e2164fe19
2 changed files with 19 additions and 3 deletions
  1. 1 1
      .env
  2. 18 2
      src/entrypoints/sidepanel/Chat.vue

+ 1 - 1
.env

@@ -1,6 +1,6 @@
 VITE_OPENAI_API_KEY_TONG=sk-e9855234f47346049809ce23ed3ebe3f
 VITE_MAX_FILE_NUMBER=10
-VITE_APP_BASE_API='http://192.168.1.166:7777'
+VITE_APP_BASE_API='http://192.168.1.202:13088'
 
 # 接口地址 (WebSocket)
 VITE_API_WS_URL = 'ws://192.168.1.166:7777'

+ 18 - 2
src/entrypoints/sidepanel/Chat.vue

@@ -484,6 +484,7 @@ async function handleAsk(value) {
   // 使用 WebSocket 替代 EventSource
   try {
     // 创建 WebSocket 连接
+
     const res =  await askQues({
     conversationId: msgUuid.value,
     modelName: '通义千问-Max',
@@ -491,8 +492,23 @@ async function handleAsk(value) {
     id: '699637194561691650',
     redisKey:msg.redisKey
     })
-     obj.content = formatMessage(res.data[res.data.length - 1].content)
-    obj.rawContent = res.data[res.data.length - 1].content;
+        const   eventSource = new EventSource(`${import.meta.env.VITE_APP_BASE_API}/ai/model/createSse?uid=${msgUuid.value}`);
+        eventSource.onopen = function (event) {
+            console.log('SSE链接成功');
+        }
+    eventSource.onmessage = function (event) {
+          console.log(event);
+          
+            if(event.data){
+                chat.innerHTML += event.data + '<br/>';
+                //console.log('后端返回的数据:', data.value);
+            }
+        }
+        eventSource.onerror = (error) => {
+            console.log('SSE链接失败',error);
+        };
+    //  obj.content = formatMessage(res.data[res.data.length - 1].content)
+    // obj.rawContent = res.data[res.data.length - 1].content;
     // const wsUrl = `${import.meta.env.VITE_API_WS_URL}/webSocket/${msgUuid.value}`;
     // console.log(wsUrl,12312);