|
@@ -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);
|
|
|
|