mirror of
https://github.com/yangjian102621/geekai.git
synced 2026-04-26 04:54:28 +08:00
优化重新生成的逻辑,删除重新生成之后的聊天记录
This commit is contained in:
@@ -220,8 +220,8 @@ func (h *ChatHandler) sendMessage(ctx context.Context, input ChatInput, c *gin.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 加载聊天上下文
|
// 加载聊天上下文
|
||||||
chatCtx := make([]interface{}, 0)
|
chatCtx := make([]any, 0)
|
||||||
messages := make([]interface{}, 0)
|
messages := make([]any, 0)
|
||||||
if h.App.SysConfig.EnableContext {
|
if h.App.SysConfig.EnableContext {
|
||||||
if h.ChatContexts.Has(input.ChatId) {
|
if h.ChatContexts.Has(input.ChatId) {
|
||||||
messages = h.ChatContexts.Get(input.ChatId)
|
messages = h.ChatContexts.Get(input.ChatId)
|
||||||
@@ -232,6 +232,8 @@ func (h *ChatHandler) sendMessage(ctx context.Context, input ChatInput, c *gin.C
|
|||||||
dbSession := h.DB.Session(&gorm.Session{}).Where("chat_id", input.ChatId)
|
dbSession := h.DB.Session(&gorm.Session{}).Where("chat_id", input.ChatId)
|
||||||
if input.LastMsgId > 0 { // 重新生成逻辑
|
if input.LastMsgId > 0 { // 重新生成逻辑
|
||||||
dbSession = dbSession.Where("id < ?", input.LastMsgId)
|
dbSession = dbSession.Where("id < ?", input.LastMsgId)
|
||||||
|
// 删除对应的聊天记录
|
||||||
|
h.DB.Where("chat_id", input.ChatId).Where("id >= ?", input.LastMsgId).Delete(&model.ChatMessage{})
|
||||||
}
|
}
|
||||||
err = dbSession.Limit(h.App.SysConfig.ContextDeep).Order("id DESC").Find(&historyMessages).Error
|
err = dbSession.Limit(h.App.SysConfig.ContextDeep).Order("id DESC").Find(&historyMessages).Error
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -265,16 +265,18 @@ const fetchData = () => {
|
|||||||
httpGet('/api/admin/model/list', query.value)
|
httpGet('/api/admin/model/list', query.value)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
// 初始化数据
|
res.data.forEach((item) => {
|
||||||
const arr = res.data
|
if (!item.options) {
|
||||||
for (let i = 0; i < arr.length; i++) {
|
item.options = {}
|
||||||
arr[i].last_used_at = dateFormat(arr[i].last_used_at)
|
}
|
||||||
}
|
item.last_used_at = dateFormat(item.last_used_at)
|
||||||
items.value = arr
|
})
|
||||||
|
items.value = res.data
|
||||||
}
|
}
|
||||||
loading.value = false
|
loading.value = false
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((e) => {
|
||||||
|
console.error(e)
|
||||||
ElMessage.error('获取数据失败')
|
ElMessage.error('获取数据失败')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user