fix: 增加ans_type用来解析回答
This commit is contained in:
parent
2187057b7b
commit
618909ea18
|
|
@ -254,8 +254,9 @@ func (d *Do) startMessageHandler(
|
||||||
) <-chan struct{} {
|
) <-chan struct{} {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
type chatType struct {
|
type chatType struct {
|
||||||
Ans string `json:"ans"`
|
Ans string `json:"ans"`
|
||||||
TaskIndex string `json:"task_index"`
|
AnsType entitys.ResponseType `json:"ans_type"`
|
||||||
|
TaskIndex string `json:"task_index"`
|
||||||
}
|
}
|
||||||
var chat []chatType
|
var chat []chatType
|
||||||
|
|
||||||
|
|
@ -267,14 +268,22 @@ func (d *Do) startMessageHandler(
|
||||||
hisLog = &entitys.ChatHisLog{}
|
hisLog = &entitys.ChatHisLog{}
|
||||||
)
|
)
|
||||||
if len(chat) > 0 {
|
if len(chat) > 0 {
|
||||||
|
// 合并所有回答
|
||||||
var ans strings.Builder
|
var ans strings.Builder
|
||||||
for _, v := range chat {
|
for _, v := range chat {
|
||||||
ans.WriteString(v.Ans)
|
ans.WriteString(v.Ans)
|
||||||
}
|
}
|
||||||
|
// 若chat长度大于1,使用文本类型
|
||||||
|
ansType := chat[0].AnsType
|
||||||
|
if len(chat) > 1 {
|
||||||
|
ansType = entitys.ResponseText
|
||||||
|
}
|
||||||
|
|
||||||
AiRes := &model.AiChatHi{
|
AiRes := &model.AiChatHi{
|
||||||
SessionID: requireData.Session,
|
SessionID: requireData.Session,
|
||||||
Ques: requireData.Req.Text,
|
Ques: requireData.Req.Text,
|
||||||
Ans: ans.String(), // 合并所有回答
|
Ans: ans.String(),
|
||||||
|
AnsType: string(ansType),
|
||||||
TaskIndex: chat[len(chat)-1].TaskIndex, // 取最后一个任务索引
|
TaskIndex: chat[len(chat)-1].TaskIndex, // 取最后一个任务索引
|
||||||
Files: requireData.Req.Img,
|
Files: requireData.Req.Img,
|
||||||
TaskID: requireData.Task.TaskID,
|
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 {
|
if v.Type == entitys.ResponseText || v.Type == entitys.ResponseStream || v.Type == entitys.ResponseJson {
|
||||||
chat = append(chat, chatType{
|
chat = append(chat, chatType{
|
||||||
Ans: v.Content,
|
Ans: v.Content,
|
||||||
|
AnsType: v.Type,
|
||||||
TaskIndex: v.Index,
|
TaskIndex: v.Index,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ type AiChatHi struct {
|
||||||
SessionID string `gorm:"column:session_id;not null" json:"session_id"`
|
SessionID string `gorm:"column:session_id;not null" json:"session_id"`
|
||||||
Ques string `gorm:"column:ques;not null" json:"ques"`
|
Ques string `gorm:"column:ques;not null" json:"ques"`
|
||||||
Ans string `gorm:"column:ans;not null" json:"ans"`
|
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"`
|
Files string `gorm:"column:files;not null" json:"files"`
|
||||||
Useful int32 `gorm:"column:useful;not null;comment:0不评价,1有用,其他为无用" json:"useful"` // 0不评价,1有用,其他为无用
|
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"`
|
CreateAt time.Time `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"`
|
||||||
|
|
|
||||||
|
|
@ -26,17 +26,18 @@ type ChatHistQuery struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChatHisQueryResponse 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"`
|
SessionID string `gorm:"column:session_id;not null" json:"session_id"`
|
||||||
Ques string `gorm:"column:ques;not null" json:"ques"`
|
Ques string `gorm:"column:ques;not null" json:"ques"`
|
||||||
Ans string `gorm:"column:ans;not null" json:"ans"`
|
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"`
|
Files string `gorm:"column:files;not null" json:"files"`
|
||||||
Useful int32 `gorm:"column:useful;not null;comment:0不评价,1有用,其他为无用" json:"useful"` // 0不评价,1有用,其他为无用
|
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"`
|
CreateAt string `gorm:"column:create_at;default:CURRENT_TIMESTAMP" json:"create_at"`
|
||||||
TaskID int32 `gorm:"column:task_id;not null" json:"task_id"` // 任务ID
|
TaskID int32 `gorm:"column:task_id;not null" json:"task_id"` // 任务ID
|
||||||
TaskName string `gorm:"column:task_name;not null" json:"task_name"` // 任务名称
|
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"` // 任务索引
|
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) {
|
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.SessionID = chat.SessionID
|
||||||
c.Ques = chat.Ques
|
c.Ques = chat.Ques
|
||||||
c.Ans = chat.Ans
|
c.Ans = chat.Ans
|
||||||
|
c.AnsType = chat.AnsType
|
||||||
c.Files = chat.Files
|
c.Files = chat.Files
|
||||||
c.Useful = chat.Useful
|
c.Useful = chat.Useful
|
||||||
c.CreateAt = chat.CreateAt.Format("2006-01-02 15:04:05")
|
c.CreateAt = chat.CreateAt.Format("2006-01-02 15:04:05")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue