mirror of
https://github.com/yangjian102621/geekai.git
synced 2026-02-15 10:54:24 +08:00
重写重新生成的逻辑
This commit is contained in:
@@ -269,8 +269,6 @@ func (h *ChatHandler) sendMessage(ctx context.Context, input ChatInput, c *gin.C
|
||||
tokens += tks
|
||||
chatCtx = append(chatCtx, v)
|
||||
}
|
||||
|
||||
logger.Debugf("聊天上下文:%+v", chatCtx)
|
||||
}
|
||||
reqMgs := make([]any, 0)
|
||||
|
||||
@@ -332,8 +330,6 @@ func (h *ChatHandler) sendMessage(ctx context.Context, input ChatInput, c *gin.C
|
||||
})
|
||||
}
|
||||
|
||||
logger.Debugf("请求消息: %+v", req.Messages)
|
||||
|
||||
return h.sendOpenAiMessage(req, userVo, ctx, input, c)
|
||||
}
|
||||
|
||||
|
||||
@@ -152,9 +152,9 @@ func (h *ChatHandler) History(c *gin.Context) {
|
||||
content.Text = item.Content
|
||||
}
|
||||
v.Content = content
|
||||
messages = append(messages, v)
|
||||
v.CreatedAt = item.CreatedAt.Unix()
|
||||
v.UpdatedAt = item.UpdatedAt.Unix()
|
||||
messages = append(messages, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
type ChatMessage struct {
|
||||
Id int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
UserId uint `gorm:"column:user_id;type:int;not null;comment:用户 ID" json:"user_id"`
|
||||
ChatId string `gorm:"column:chat_id;type:char(40);not null;index;comment:会话 ID" json:"chat_id"`
|
||||
Type string `gorm:"column:type;type:varchar(10);not null;comment:类型:prompt|reply" json:"type"`
|
||||
|
||||
@@ -6,7 +6,9 @@ type MsgContent struct {
|
||||
}
|
||||
|
||||
type ChatMessage struct {
|
||||
BaseVo
|
||||
Id uint `json:"id"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
ChatId string `json:"chat_id"`
|
||||
UserId uint `json:"user_id"`
|
||||
RoleId uint `json:"role_id"`
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<span v-if="!readOnly" class="flex">
|
||||
<span class="bar-item" @click="reGenerate()">
|
||||
<span class="bar-item" @click="reGenerate(data.id)">
|
||||
<el-tooltip class="box-item" effect="dark" content="重新生成" placement="bottom">
|
||||
<el-icon><Refresh /></el-icon>
|
||||
</el-tooltip>
|
||||
@@ -79,7 +79,7 @@
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<span v-if="!readOnly" class="flex">
|
||||
<span class="bar-item bg" @click="reGenerate()">
|
||||
<span class="bar-item bg" @click="reGenerate(data.id)">
|
||||
<el-tooltip class="box-item" effect="dark" content="重新生成" placement="bottom">
|
||||
<el-icon><Refresh /></el-icon>
|
||||
</el-tooltip>
|
||||
@@ -223,8 +223,8 @@ const stopSynthesis = () => {
|
||||
}
|
||||
|
||||
// 重新生成
|
||||
const reGenerate = () => {
|
||||
emits('regen')
|
||||
const reGenerate = (messageId) => {
|
||||
emits('regen', messageId)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -60,9 +60,7 @@ const props = defineProps({
|
||||
show: Boolean,
|
||||
})
|
||||
|
||||
const showDialog = computed(() => {
|
||||
return props.show
|
||||
})
|
||||
const showDialog = ref(props.show)
|
||||
const emits = defineEmits(['hide'])
|
||||
const close = function () {
|
||||
emits('hide', false)
|
||||
|
||||
@@ -845,7 +845,7 @@ const sendSSERequest = async (message) => {
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
const sendMessage = () => {
|
||||
const sendMessage = (messageId) => {
|
||||
if (!isLogin.value) {
|
||||
console.log('未登录')
|
||||
store.setShowLoginDialog(true)
|
||||
@@ -873,6 +873,7 @@ const sendMessage = () => {
|
||||
},
|
||||
model: getModelValue(modelID.value),
|
||||
created_at: new Date().getTime() / 1000,
|
||||
message_id: messageId,
|
||||
})
|
||||
|
||||
// 添加空回复消息
|
||||
@@ -1185,33 +1186,20 @@ const stopGenerate = function () {
|
||||
}
|
||||
|
||||
// 重新生成
|
||||
const reGenerate = function () {
|
||||
const reGenerate = function (messageId) {
|
||||
// 恢复发送按钮状态
|
||||
canSend.value = true
|
||||
showStopGenerate.value = false
|
||||
console.log(messageId)
|
||||
|
||||
// 查找最后的用户消息和AI回复并删除
|
||||
if (chatData.value.length >= 2) {
|
||||
// 从后往前找,如果最后一条是AI回复,再往前一条是用户消息
|
||||
if (chatData.value[chatData.value.length - 1].type === 'reply') {
|
||||
// 删除AI回复
|
||||
chatData.value.pop()
|
||||
|
||||
// 如果此时最后一条是用户消息,也删除它
|
||||
if (
|
||||
chatData.value.length > 0 &&
|
||||
chatData.value[chatData.value.length - 1].type === 'prompt'
|
||||
) {
|
||||
// 保存用户消息内容,填入输入框
|
||||
const userPrompt = chatData.value[chatData.value.length - 1].content
|
||||
// 删除用户消息
|
||||
chatData.value.pop()
|
||||
// 填入输入框
|
||||
prompt.value = userPrompt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
chatData.value = chatData.value.filter((item) => item.id < messageId)
|
||||
// 保存用户消息内容,填入输入框
|
||||
const userPrompt = chatData.value[chatData.value.length - 1].content.text
|
||||
// 删除用户消息
|
||||
chatData.value.pop()
|
||||
// 填入输入框
|
||||
prompt.value = userPrompt
|
||||
sendMessage(messageId)
|
||||
// 将光标定位到输入框并聚焦
|
||||
nextTick(() => {
|
||||
if (inputRef.value) {
|
||||
|
||||
Reference in New Issue
Block a user