fix: 调整对话历史方案
This commit is contained in:
parent
0721a4e82e
commit
3a7925fb55
|
|
@ -253,12 +253,7 @@ func (d *Do) startMessageHandler(
|
||||||
requireData *entitys.RequireData,
|
requireData *entitys.RequireData,
|
||||||
) <-chan struct{} {
|
) <-chan struct{} {
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
type chatType struct {
|
var chat []entitys.Response
|
||||||
Ans string `json:"ans"`
|
|
||||||
AnsType entitys.ResponseType `json:"ans_type"`
|
|
||||||
TaskIndex string `json:"task_index"`
|
|
||||||
}
|
|
||||||
var chat []chatType
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
@ -268,23 +263,13 @@ func (d *Do) startMessageHandler(
|
||||||
hisLog = &entitys.ChatHisLog{}
|
hisLog = &entitys.ChatHisLog{}
|
||||||
)
|
)
|
||||||
if len(chat) > 0 {
|
if len(chat) > 0 {
|
||||||
// 合并所有回答
|
// 合并所有回答-转json字符串
|
||||||
var ans strings.Builder
|
ans, _ := json.Marshal(chat)
|
||||||
for _, v := range chat {
|
|
||||||
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: string(ans),
|
||||||
AnsType: string(ansType),
|
|
||||||
TaskIndex: chat[len(chat)-1].TaskIndex, // 取最后一个任务索引
|
|
||||||
Files: requireData.Req.Img,
|
Files: requireData.Req.Img,
|
||||||
TaskID: requireData.Task.TaskID,
|
TaskID: requireData.Task.TaskID,
|
||||||
}
|
}
|
||||||
|
|
@ -305,11 +290,7 @@ func (d *Do) startMessageHandler(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
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, v)
|
||||||
Ans: v.Content,
|
|
||||||
AnsType: v.Type,
|
|
||||||
TaskIndex: v.Index,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,11 @@ 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"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP" json:"updated_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
|
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"` // 前端回传数据
|
Content string `gorm:"column:content;comment:前端回传数据" json:"content"` // 前端回传数据
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,11 @@ type ChatHisQueryResponse 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 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"` // 任务名称
|
||||||
TaskIndex string `gorm:"column:task_index" json:"task_index"` // 任务索引
|
|
||||||
Contents []string `gorm:"column:contents" json:"contents"` // 前端回传数据
|
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.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")
|
||||||
c.TaskID = chat.TaskID
|
c.TaskID = chat.TaskID
|
||||||
c.TaskName = task.Name
|
c.TaskName = task.Name
|
||||||
c.TaskIndex = chat.TaskIndex
|
|
||||||
c.Contents = make([]string, 0)
|
c.Contents = make([]string, 0)
|
||||||
|
|
||||||
// 解析Content
|
// 解析Content
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue