diff --git a/internal/biz/do/ctx.go b/internal/biz/do/ctx.go index b4f8a73..62b259f 100644 --- a/internal/biz/do/ctx.go +++ b/internal/biz/do/ctx.go @@ -253,12 +253,7 @@ func (d *Do) startMessageHandler( requireData *entitys.RequireData, ) <-chan struct{} { done := make(chan struct{}) - type chatType struct { - Ans string `json:"ans"` - AnsType entitys.ResponseType `json:"ans_type"` - TaskIndex string `json:"task_index"` - } - var chat []chatType + var chat []entitys.Response go func() { defer func() { @@ -268,23 +263,13 @@ 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 - } + // 合并所有回答-转json字符串 + ans, _ := json.Marshal(chat) AiRes := &model.AiChatHi{ SessionID: requireData.Session, Ques: requireData.Req.Text, - Ans: ans.String(), - AnsType: string(ansType), - TaskIndex: chat[len(chat)-1].TaskIndex, // 取最后一个任务索引 + Ans: string(ans), Files: requireData.Req.Img, TaskID: requireData.Task.TaskID, } @@ -305,11 +290,7 @@ func (d *Do) startMessageHandler( return } 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, - }) + chat = append(chat, v) } } }() diff --git a/internal/data/model/ai_chat_his.gen.go b/internal/data/model/ai_chat_his.gen.go index 39263e4..f4108ae 100644 --- a/internal/data/model/ai_chat_his.gen.go +++ b/internal/data/model/ai_chat_his.gen.go @@ -16,14 +16,12 @@ 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"` UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_at"` - TaskID int32 `gorm:"column:task_id;comment:任务id" json:"task_id"` // 任务id - TaskIndex string `gorm:"column:task_index;comment:任务索引" json:"task_index"` // 任务索引 - Content string `gorm:"column:content;comment:前端回传数据" json:"content"` // 前端回传数据 + TaskID int32 `gorm:"column:task_id;comment:任务id" json:"task_id"` // 任务id + Content string `gorm:"column:content;comment:前端回传数据" json:"content"` // 前端回传数据 } // TableName AiChatHi's table name diff --git a/internal/entitys/chat_history.go b/internal/entitys/chat_history.go index 092be7d..b50148e 100644 --- a/internal/entitys/chat_history.go +++ b/internal/entitys/chat_history.go @@ -30,13 +30,11 @@ type ChatHisQueryResponse 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 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"` // 任务名称 - TaskIndex string `gorm:"column:task_index" json:"task_index"` // 任务索引 Contents []string `gorm:"column:contents" json:"contents"` // 前端回传数据 } @@ -45,13 +43,11 @@ 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") c.TaskID = chat.TaskID c.TaskName = task.Name - c.TaskIndex = chat.TaskIndex c.Contents = make([]string, 0) // 解析Content