mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-06 17:23:42 +08:00
optimize the code for change chat session
This commit is contained in:
@@ -61,18 +61,18 @@ func (s *Server) ChatHandle(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
logger.Info("Receive a message: ", string(message))
|
||||
replyMessage(client, "当前 TOKEN 无效,请使用合法的 TOKEN 登录!", false)
|
||||
//replyMessage(client, "当前 TOKEN 无效,请使用合法的 TOKEN 登录!", false)
|
||||
//replyMessage(client, "", true)
|
||||
//ctx, cancel := context.WithCancel(context.Background())
|
||||
//s.ReqCancelFunc[sessionId] = cancel
|
||||
//// 回复消息
|
||||
//err = s.sendMessage(ctx, session, chatRole, string(message), client, false)
|
||||
//if err != nil {
|
||||
// logger.Error(err)
|
||||
//} else {
|
||||
// replyChunkMessage(client, types.WsMessage{Type: types.WsEnd, IsHelloMsg: false})
|
||||
// logger.Info("回答完毕: " + string(message))
|
||||
//}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
s.ReqCancelFunc[sessionId] = cancel
|
||||
// 回复消息
|
||||
err = s.sendMessage(ctx, session, chatRole, string(message), client, false)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
} else {
|
||||
replyChunkMessage(client, types.WsMessage{Type: types.WsEnd, IsHelloMsg: false})
|
||||
logger.Info("回答完毕: " + string(message))
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -111,7 +111,8 @@
|
||||
|
||||
<div class="btn-container">
|
||||
<el-row>
|
||||
<el-button type="success" class="send" :disabled="sending" v-on:click="sendMessage">发送</el-button>
|
||||
<el-button type="success" class="send" :disabled="sending" v-on:click="sendMessage">发送
|
||||
</el-button>
|
||||
</el-row>
|
||||
</div>
|
||||
</div>
|
||||
@@ -286,8 +287,11 @@ export default defineComponent({
|
||||
this.errorMessage.close(); // 关闭错误提示信息
|
||||
}
|
||||
this.activelyClose = false;
|
||||
// 加载聊天记录
|
||||
this.fetchChatHistory();
|
||||
// 加载聊天列表
|
||||
const chatList = getChatList();
|
||||
if (chatList) {
|
||||
this.chatList = chatList;
|
||||
}
|
||||
});
|
||||
|
||||
socket.addEventListener('message', event => {
|
||||
@@ -387,14 +391,11 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
// 从后端获取聊天历史记录
|
||||
fetchChatHistory: function () {
|
||||
const chatList = getChatList();
|
||||
if (chatList) {
|
||||
this.chatList = chatList;
|
||||
|
||||
const list = getChatHistory(this.curChat.id);
|
||||
fetchChatHistory: function (chatId) {
|
||||
const list = getChatHistory(chatId);
|
||||
if (list) {
|
||||
const md = require('markdown-it')();
|
||||
console.log(list)
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
if (list[i].type === "prompt") {
|
||||
this.chatData.push(list[i]);
|
||||
@@ -413,9 +414,6 @@ export default defineComponent({
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
inputKeyDown: function (e) {
|
||||
@@ -589,6 +587,9 @@ export default defineComponent({
|
||||
setChat(chat)
|
||||
} else if (this.curOpt === 'remove') {
|
||||
delete this.chatList[chat.id];
|
||||
if (this.curChat.id === chat.id) {
|
||||
this.chatData = [];
|
||||
}
|
||||
removeChat(chat.id);
|
||||
chat.removing = false;
|
||||
}
|
||||
@@ -613,11 +614,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
this.curChat = chat;
|
||||
const chatHistory = getChatHistory(chat.id);
|
||||
if (!chatHistory) {
|
||||
return;
|
||||
}
|
||||
this.chatData = chatHistory;
|
||||
this.fetchChatHistory(chat.id);
|
||||
},
|
||||
|
||||
// 退出登录
|
||||
|
||||
Reference in New Issue
Block a user