Commit b61b4e32 authored by 赵灿灿's avatar 赵灿灿

修改配置信息

parent 05b75a64
Pipeline #21037 passed with stages
in 3 minutes and 2 seconds
......@@ -110,7 +110,8 @@ require(['jquery', 'vue', 'utils', 'echarts', 'global'], function ($, Vue, utils
// 会话相关方法
async getSessionId() {
try {
const response = await fetch('../../api/langchain/getSessionId');
//const response = await fetch('../../api/langchain/getSessionId');
const response = await fetch('../../api/langchain/getDialogId');
const dataJson = await response.json();
this.sessionId = dataJson.data;
} catch (error) {
......@@ -172,12 +173,12 @@ require(['jquery', 'vue', 'utils', 'echarts', 'global'], function ($, Vue, utils
}
});
},
connectSSE(chatMessage) {
// 在消息列表中添加一个带"正在输入"指示器的AI消息
const aiMessageIndex = this.messages.length;
this.messages.push({ role: 'ai', content: '', typing: true });
// 自动滚动到底部
this.$nextTick(() => {
const messagesDiv = document.getElementById('chat-messages');
......@@ -185,16 +186,14 @@ require(['jquery', 'vue', 'utils', 'echarts', 'global'], function ($, Vue, utils
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}
});
// 连接SSE
this.currentEventSource = new EventSource('../../api/langchain/sseBigTwo?chatMessage=' + encodeURIComponent(chatMessage) + "&sessionId=" + this.sessionId);
this.currentEventSource = new EventSource('../../api/langchain/sseIntelligent?chatMessage=' + encodeURIComponent(chatMessage) + "&dialogId=" + this.sessionId);
let responseText = '';
this.currentEventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
const content = data.dataToSend[1].data;
if (content !== "stop") {
responseText += content;
this.messages[aiMessageIndex].content = responseText;
......@@ -202,15 +201,15 @@ require(['jquery', 'vue', 'utils', 'echarts', 'global'], function ($, Vue, utils
// 移除输入指示器
this.messages[aiMessageIndex].typing = false;
this.chatHistory.push({ role: 'ai', content: responseText });
// 切换回发送按钮
this.isResponding = false;
// 关闭事件源
this.currentEventSource.close();
this.currentEventSource = null;
}
// 自动滚动到底部
this.$nextTick(() => {
const messagesDiv = document.getElementById('chat-messages');
......@@ -219,17 +218,17 @@ require(['jquery', 'vue', 'utils', 'echarts', 'global'], function ($, Vue, utils
}
});
};
this.currentEventSource.onerror = () => {
console.error('SSE连接异常');
// 移除输入指示器,显示错误信息
this.messages[aiMessageIndex].typing = false;
this.messages[aiMessageIndex].content = responseText || '抱歉,连接出现问题,请稍后再试。';
// 切换回发送按钮
this.isResponding = false;
// 关闭事件源
this.currentEventSource.close();
this.currentEventSource = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment