diff --git a/internal/biz/do/ctx.go b/internal/biz/do/ctx.go index 28e4454..b4f8a73 100644 --- a/internal/biz/do/ctx.go +++ b/internal/biz/do/ctx.go @@ -254,8 +254,9 @@ func (d *Do) startMessageHandler( ) <-chan struct{} { done := make(chan struct{}) type chatType struct { - Ans string `json:"ans"` - TaskIndex string `json:"task_index"` + Ans string `json:"ans"` + AnsType entitys.ResponseType `json:"ans_type"` + TaskIndex string `json:"task_index"` } var chat []chatType @@ -267,14 +268,22 @@ func (d *Do) startMessageHandler( hisLog = &entitys.ChatHisLog{} ) if len(chat) > 0 { + // 合并所有回答 var ans strings.Builder for _, v := range chat { ans.WriteString(v.Ans) } + // 若chat长度大于1,使用文本类型 + ansType := chat[0].AnsType + if len(chat) > 1 { + ansType = entitys.ResponseText + } + AiRes := &model.AiChatHi{ SessionID: requireData.Session, Ques: requireData.Req.Text, - Ans: ans.String(), // 合并所有回答 + Ans: ans.String(), + AnsType: string(ansType), TaskIndex: chat[len(chat)-1].TaskIndex, // 取最后一个任务索引 Files: requireData.Req.Img, TaskID: requireData.Task.TaskID, @@ -298,6 +307,7 @@ func (d *Do) startMessageHandler( if v.Type == entitys.ResponseText || v.Type == entitys.ResponseStream || v.Type == entitys.ResponseJson { chat = append(chat, chatType{ Ans: v.Content, + AnsType: v.Type, TaskIndex: v.Index, }) } diff --git a/internal/data/model/ai_chat_his.gen.go b/internal/data/model/ai_chat_his.gen.go index d429eba..39263e4 100644 --- a/internal/data/model/ai_chat_his.gen.go +++ b/internal/data/model/ai_chat_his.gen.go @@ -16,6 +16,7 @@ type AiChatHi struct { SessionID string `gorm:"column:session_id;not null" json:"session_id"` Ques string `gorm:"column:ques;not null" json:"ques"` Ans string `gorm:"column:ans;not null" json:"ans"` + AnsType string `gorm:"column:ans_type;not null;comment:回复类型(json、text等)" json:"ans_type"` // 回复类型(json、text等) Files string `gorm:"column:files;not null" json:"files"` Useful int32 `gorm:"column:useful;not null;comment:0不评价,1有用,其他为无用" json:"useful"` // 0不评价,1有用,其他为无用 CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"` diff --git a/internal/entitys/chat_history.go b/internal/entitys/chat_history.go index 7b7a975..a95854c 100644 --- a/internal/entitys/chat_history.go +++ b/internal/entitys/chat_history.go @@ -26,17 +26,18 @@ type ChatHistQuery struct { } type ChatHisQueryResponse struct { - HisID int64 `gorm:"column:his_id;primaryKey;autoIncrement:true" json:"his_id"` + HisID int64 `gorm:"column:his_id;primaryKey;autoIncrement:true" json:"his_id"` SessionID string `gorm:"column:session_id;not null" json:"session_id"` Ques string `gorm:"column:ques;not null" json:"ques"` Ans string `gorm:"column:ans;not null" json:"ans"` + AnsType string `gorm:"column:ans_type;not null;comment:回复类型(json、text等)" json:"ans_type"` // 回复类型(json、text等) Files string `gorm:"column:files;not null" json:"files"` Useful int32 `gorm:"column:useful;not null;comment:0不评价,1有用,其他为无用" json:"useful"` // 0不评价,1有用,其他为无用 CreateAt string `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"` TaskID int32 `gorm:"column:task_id;not null" json:"task_id"` // 任务ID TaskName string `gorm:"column:task_name;not null" json:"task_name"` // 任务名称 - Contents []string `gorm:"column:contents" json:"contents"` // 前端回传数据 TaskIndex string `gorm:"column:task_index" json:"task_index"` // 任务索引 + Contents []string `gorm:"column:contents" json:"contents"` // 前端回传数据 } func (c *ChatHisQueryResponse) FromModel(chat model.AiChatHi, task model.AiTask) { @@ -44,6 +45,7 @@ func (c *ChatHisQueryResponse) FromModel(chat model.AiChatHi, task model.AiTask) c.SessionID = chat.SessionID c.Ques = chat.Ques c.Ans = chat.Ans + c.AnsType = chat.AnsType c.Files = chat.Files c.Useful = chat.Useful c.CreateAt = chat.CreateAt.Format("2006-01-02 15:04:05")