fix: 增加ans_type用来解析回答
This commit is contained in:
parent
2187057b7b
commit
618909ea18
|
|
@ -255,6 +255,7 @@ func (d *Do) startMessageHandler(
|
|||
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
|
||||
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
|
|
|
|||
|
|
@ -30,13 +30,14 @@ 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"` // 任务名称
|
||||
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")
|
||||
|
|
|
|||
Loading…
Reference in New Issue