From a47758213cccdc8517826081977279093546019e Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 5 Jan 2026 10:51:54 +0800 Subject: [PATCH 01/14] =?UTF-8?q?feat=EF=BC=9A1.=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=AD=98=E5=82=A8=E4=BB=BB=E5=8A=A1=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=202.=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=A2=9E=E5=8A=A0=E4=BB=BB=E5=8A=A1=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/do/ctx.go | 18 +++++++++++++++--- internal/data/model/ai_chat_his.gen.go | 5 +++-- internal/entitys/chat_history.go | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/biz/do/ctx.go b/internal/biz/do/ctx.go index 48813b1..28e4454 100644 --- a/internal/biz/do/ctx.go +++ b/internal/biz/do/ctx.go @@ -253,7 +253,11 @@ func (d *Do) startMessageHandler( requireData *entitys.RequireData, ) <-chan struct{} { done := make(chan struct{}) - var chat []string + type chatType struct { + Ans string `json:"ans"` + TaskIndex string `json:"task_index"` + } + var chat []chatType go func() { defer func() { @@ -263,10 +267,15 @@ func (d *Do) startMessageHandler( hisLog = &entitys.ChatHisLog{} ) if len(chat) > 0 { + var ans strings.Builder + for _, v := range chat { + ans.WriteString(v.Ans) + } AiRes := &model.AiChatHi{ SessionID: requireData.Session, Ques: requireData.Req.Text, - Ans: strings.Join(chat, ""), + Ans: ans.String(), // 合并所有回答 + TaskIndex: chat[len(chat)-1].TaskIndex, // 取最后一个任务索引 Files: requireData.Req.Img, TaskID: requireData.Task.TaskID, } @@ -287,7 +296,10 @@ func (d *Do) startMessageHandler( return } if v.Type == entitys.ResponseText || v.Type == entitys.ResponseStream || v.Type == entitys.ResponseJson { - chat = append(chat, v.Content) + chat = append(chat, chatType{ + Ans: v.Content, + TaskIndex: v.Index, + }) } } }() diff --git a/internal/data/model/ai_chat_his.gen.go b/internal/data/model/ai_chat_his.gen.go index 595b4c4..d429eba 100644 --- a/internal/data/model/ai_chat_his.gen.go +++ b/internal/data/model/ai_chat_his.gen.go @@ -20,8 +20,9 @@ type AiChatHi struct { 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;not null" json:"task_id"` // 任务ID - Content string `gorm:"column:content" json:"content"` // 前端回传数据 + 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"` // 前端回传数据 } // TableName AiChatHi's table name diff --git a/internal/entitys/chat_history.go b/internal/entitys/chat_history.go index b50148e..b47638d 100644 --- a/internal/entitys/chat_history.go +++ b/internal/entitys/chat_history.go @@ -36,6 +36,7 @@ type ChatHisQueryResponse struct { 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"` // 任务索引 } func (c *ChatHisQueryResponse) FromModel(chat model.AiChatHi, task model.AiTask) { From 72ed9b3717b0e127e177ee84e49b6339e5b7d43a Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 5 Jan 2026 10:53:44 +0800 Subject: [PATCH 02/14] =?UTF-8?q?fix:=20=E6=B5=8B=E8=AF=95=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E7=A6=81=E7=94=A8=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=92=8C=E9=92=89=E9=92=89=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server/main.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index baca30d..9b09f74 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -2,7 +2,6 @@ package main import ( "ai_scheduler/internal/config" - "context" "flag" "fmt" @@ -11,9 +10,9 @@ import ( func main() { configPath := flag.String("config", "./config/config_test.yaml", "Path to configuration file") - onBot := flag.String("bot", "", "bot start") + // onBot := flag.String("bot", "", "bot start") flag.Parse() - ctx := context.Background() + // ctx := context.Background() bc, err := config.LoadConfig(*configPath) if err != nil { log.Fatalf("加载配置失败: %v", err) @@ -27,8 +26,8 @@ func main() { cleanup() }() //钉钉机器人 - app.DingBotServer.Run(ctx, *onBot) + // app.DingBotServer.Run(ctx, *onBot) //定时任务 - app.Cron.Run(ctx) + // app.Cron.Run(ctx) log.Fatal(app.HttpServer.Listen(fmt.Sprintf(":%d", bc.Server.Port))) } From 900cb0c1c729cd1113fc6a4d5053040dac75cc15 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 5 Jan 2026 10:59:49 +0800 Subject: [PATCH 03/14] =?UTF-8?q?fix=EF=BC=9A=20=E8=BF=98=E5=8E=9F=20bot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server/main.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 9b09f74..cf2585c 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -2,6 +2,7 @@ package main import ( "ai_scheduler/internal/config" + "context" "flag" "fmt" @@ -10,9 +11,9 @@ import ( func main() { configPath := flag.String("config", "./config/config_test.yaml", "Path to configuration file") - // onBot := flag.String("bot", "", "bot start") + onBot := flag.String("bot", "", "bot start") flag.Parse() - // ctx := context.Background() + ctx := context.Background() bc, err := config.LoadConfig(*configPath) if err != nil { log.Fatalf("加载配置失败: %v", err) @@ -26,7 +27,7 @@ func main() { cleanup() }() //钉钉机器人 - // app.DingBotServer.Run(ctx, *onBot) + app.DingBotServer.Run(ctx, *onBot) //定时任务 // app.Cron.Run(ctx) log.Fatal(app.HttpServer.Listen(fmt.Sprintf(":%d", bc.Server.Port))) From bb9650aa3ac3b205f8d7e1b03a350ec46d45789f Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 5 Jan 2026 11:06:18 +0800 Subject: [PATCH 04/14] =?UTF-8?q?fix:=20=E8=BF=BD=E5=8A=A0taskIndex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/entitys/chat_history.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/entitys/chat_history.go b/internal/entitys/chat_history.go index b47638d..7c04ddb 100644 --- a/internal/entitys/chat_history.go +++ b/internal/entitys/chat_history.go @@ -49,6 +49,7 @@ func (c *ChatHisQueryResponse) FromModel(chat model.AiChatHi, task model.AiTask) c.CreateAt = chat.CreateAt.Format("2006-01-02 15:04:05") c.TaskID = chat.TaskID c.TaskName = task.Name + c.TaskIndex = task.Index c.Contents = make([]string, 0) // 解析Content From 2187057b7bcce22eab713616e1ebe3f68281a13c Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 5 Jan 2026 11:07:14 +0800 Subject: [PATCH 05/14] =?UTF-8?q?fix:=20=E8=BF=BD=E5=8A=A0taskIndex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/entitys/chat_history.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/entitys/chat_history.go b/internal/entitys/chat_history.go index 7c04ddb..7b7a975 100644 --- a/internal/entitys/chat_history.go +++ b/internal/entitys/chat_history.go @@ -49,7 +49,7 @@ func (c *ChatHisQueryResponse) FromModel(chat model.AiChatHi, task model.AiTask) c.CreateAt = chat.CreateAt.Format("2006-01-02 15:04:05") c.TaskID = chat.TaskID c.TaskName = task.Name - c.TaskIndex = task.Index + c.TaskIndex = chat.TaskIndex c.Contents = make([]string, 0) // 解析Content From 618909ea18b824596c29de4e600f6a8e46eda49d Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 5 Jan 2026 11:23:22 +0800 Subject: [PATCH 06/14] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0ans=5Ftype?= =?UTF-8?q?=E7=94=A8=E6=9D=A5=E8=A7=A3=E6=9E=90=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/do/ctx.go | 16 +++++++++++++--- internal/data/model/ai_chat_his.gen.go | 1 + internal/entitys/chat_history.go | 6 ++++-- 3 files changed, 18 insertions(+), 5 deletions(-) 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") From 4221c3a012f2cfb884528d0d45bef3846c0efbbd Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Mon, 5 Jan 2026 14:22:24 +0800 Subject: [PATCH 07/14] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E6=95=88=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/entitys/chat_history.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/entitys/chat_history.go b/internal/entitys/chat_history.go index a95854c..092be7d 100644 --- a/internal/entitys/chat_history.go +++ b/internal/entitys/chat_history.go @@ -26,7 +26,7 @@ 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"` From 3a7925fb5521c23e8ea75885bca0f7d213f9a3dc Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 7 Jan 2026 10:05:23 +0800 Subject: [PATCH 08/14] =?UTF-8?q?fix=EF=BC=9A=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E5=8E=86=E5=8F=B2=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/do/ctx.go | 29 +++++--------------------- internal/data/model/ai_chat_his.gen.go | 6 ++---- internal/entitys/chat_history.go | 4 ---- 3 files changed, 7 insertions(+), 32 deletions(-) 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 From 4452fb156850d0d48fd381a66442ec44a3ae9505 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 7 Jan 2026 10:31:20 +0800 Subject: [PATCH 09/14] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B5=81?= =?UTF-8?q?=E5=BC=8F=E5=AF=B9=E8=AF=9D=E6=97=A5=E5=BF=97=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/do/ctx.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/internal/biz/do/ctx.go b/internal/biz/do/ctx.go index 62b259f..6058b38 100644 --- a/internal/biz/do/ctx.go +++ b/internal/biz/do/ctx.go @@ -284,14 +284,42 @@ func (d *Do) startMessageHandler( }() + streamText := "" + streamIndex := "" for v := range requireData.Ch { // 自动检测通道关闭 if err := sendWithTimeout(client, v, 10*time.Second); err != nil { log.Errorf("Send error: %v", err) return } - if v.Type == entitys.ResponseText || v.Type == entitys.ResponseStream || v.Type == entitys.ResponseJson { + // 文本+卡片 + if v.Type == entitys.ResponseText || v.Type == entitys.ResponseJson { chat = append(chat, v) } + // 流式-追加 + if v.Type == entitys.ResponseStream { + streamText += v.Content + streamIndex = v.Index + } + // 流式-阶段结束|对话结束 + if streamText != "" && v.Type != entitys.ResponseStream { + chat = append(chat, entitys.Response{ + Content: streamText, + Type: entitys.ResponseText, + Index: streamIndex, + }) + streamText = "" + streamIndex = "" + } + } + // 流式结束 + if streamText != "" { + chat = append(chat, entitys.Response{ + Content: streamText, + Type: entitys.ResponseText, + Index: streamIndex, + }) + streamText = "" + streamIndex = "" } }() From 7bbe7093da97f51cdde19a5abd580c290a815cd1 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 7 Jan 2026 14:32:36 +0800 Subject: [PATCH 10/14] =?UTF-8?q?fix:=201.=E5=87=8F=E5=B0=91=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87=E8=BD=AE=E6=95=B0=202.=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E5=8A=A9=E6=89=8B=E5=9B=9E=E5=A4=8D=E9=99=8D?= =?UTF-8?q?=E5=99=AA=203.=E8=A7=92=E8=89=B2=E5=8C=B9=E9=85=8D=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.yaml | 2 +- config/config_env.yaml | 2 +- config/config_test.yaml | 2 +- internal/biz/router.go | 22 ++++++++++++++++++++-- internal/pkg/utils_ollama/client.go | 1 + 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 2e6903f..85769d0 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -31,7 +31,7 @@ lsxd: sys: - session_len: 6 + session_len: 3 channel_pool_len: 100 channel_pool_size: 32 llm_pool_len: 5 diff --git a/config/config_env.yaml b/config/config_env.yaml index b571f51..0e002e0 100644 --- a/config/config_env.yaml +++ b/config/config_env.yaml @@ -32,7 +32,7 @@ lsxd: sys: - session_len: 6 + session_len: 3 channel_pool_len: 100 channel_pool_size: 32 llm_pool_len: 5 diff --git a/config/config_test.yaml b/config/config_test.yaml index 7355304..2e9e778 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -32,7 +32,7 @@ lsxd: check_token_url: "https://api.user.1688sup.com/v1/user/welcome" sys: - session_len: 6 + session_len: 3 channel_pool_len: 100 channel_pool_size: 32 llm_pool_len: 5 diff --git a/internal/biz/router.go b/internal/biz/router.go index 7d045f8..2d827dc 100644 --- a/internal/biz/router.go +++ b/internal/biz/router.go @@ -174,14 +174,15 @@ func (r *AiRouterBiz) buildChatHistory(requireData *entitys.RequireData) entitys // 用户消息 messages = append(messages, entitys.HisMessage{ Role: constants.RoleUser, // 用户角色 - Content: h.Ans, // 用户输入内容 + Content: h.Ques, // 用户输入内容 Timestamp: h.CreateAt.Format(time.DateTime), }) // 助手消息 + ansStr := r.ansNoiseReduction(h.Ans) // 助手回复降噪 messages = append(messages, entitys.HisMessage{ Role: constants.RoleAssistant, // 助手角色 - Content: h.Ques, // 助手回复内容 + Content: ansStr, // 助手回复内容 Timestamp: h.CreateAt.Format(time.DateTime), }) } @@ -196,3 +197,20 @@ func (r *AiRouterBiz) buildChatHistory(requireData *entitys.RequireData) entitys }, } } + +// ansNoiseReduction 助手回复降噪 +func (r *AiRouterBiz) ansNoiseReduction(ansJson string) string { + // 使用anw统一类型解析 + ansStruct := make([]*entitys.Response, 0) + err := json.Unmarshal([]byte(ansJson), &ansStruct) + if err != nil { + log.Errorf("解析助手回复失败: %s", err.Error()) + return ansJson + } + var ansStr string + for _, item := range ansStruct { + ansStr += item.Content + } + + return ansStr +} diff --git a/internal/pkg/utils_ollama/client.go b/internal/pkg/utils_ollama/client.go index fa88afa..febd8cd 100644 --- a/internal/pkg/utils_ollama/client.go +++ b/internal/pkg/utils_ollama/client.go @@ -53,6 +53,7 @@ func (c *Client) ToolSelect(ctx context.Context, messages []api.Message, tools [ res = resp return nil }) + if err != nil { return } From cc0a05eb9759e2940774338e307140657a825f32 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 7 Jan 2026 14:35:01 +0800 Subject: [PATCH 11/14] =?UTF-8?q?fix=EF=BC=9Ago=20mod=20tidy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 12 +++++++----- go.sum | 4 ---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 374a7f3..095f736 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/alibabacloud-go/dingtalk v1.6.96 github.com/alibabacloud-go/tea v1.2.2 github.com/alibabacloud-go/tea-utils/v2 v2.0.6 + github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible github.com/cloudwego/eino v0.7.7 github.com/cloudwego/eino-ext/components/model/ollama v0.1.6 github.com/cloudwego/eino-ext/components/model/openai v0.1.5 @@ -25,10 +26,12 @@ require ( github.com/gofiber/websocket/v2 v2.2.1 github.com/google/uuid v1.6.0 github.com/google/wire v0.7.0 - github.com/json-iterator/go v1.1.12 github.com/ollama/ollama v0.12.7 github.com/redis/go-redis/v9 v9.16.0 + github.com/robfig/cron/v3 v3.0.1 + github.com/shopspring/decimal v1.4.0 github.com/spf13/viper v1.17.0 + github.com/stretchr/testify v1.11.1 github.com/tmc/langchaingo v0.1.13 github.com/xuri/excelize/v2 v2.10.0 golang.org/x/sync v0.17.0 @@ -39,14 +42,12 @@ require ( ) require ( - dario.cat/mergo v1.0.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.5 // indirect github.com/alibabacloud-go/debug v1.0.1 // indirect github.com/alibabacloud-go/gateway-dingtalk v1.0.2 // indirect github.com/alibabacloud-go/openapi-util v0.1.1 // indirect github.com/alibabacloud-go/tea-xml v1.1.3 // indirect - github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible // indirect github.com/aliyun/credentials-go v1.4.6 // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect @@ -58,6 +59,7 @@ require ( github.com/clbanning/mxj/v2 v2.5.5 // indirect github.com/cloudwego/base64x v0.1.6 // indirect github.com/cloudwego/eino-ext/libs/acl/openai v0.1.2 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dlclark/regexp2 v1.11.4 // indirect github.com/dustin/go-humanize v1.0.1 // indirect @@ -73,6 +75,7 @@ require ( github.com/hashicorp/hcl v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect + github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.17.9 // indirect github.com/klauspost/cpuid/v2 v2.2.9 // indirect github.com/leodido/go-urn v1.4.0 // indirect @@ -89,14 +92,13 @@ require ( github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pkoukk/tiktoken-go v0.1.6 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/richardlehane/mscfb v1.0.4 // indirect github.com/richardlehane/msoleps v1.0.4 // indirect github.com/rivo/uniseg v0.2.0 // indirect - github.com/robfig/cron/v3 v3.0.1 // indirect github.com/sagikazarmark/locafero v0.3.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect - github.com/shopspring/decimal v1.4.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/slongfield/pyfmt v0.0.0-20220222012616-ea85ff4c361f // indirect github.com/sourcegraph/conc v0.3.0 // indirect diff --git a/go.sum b/go.sum index f101537..7d1f8b1 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= -dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= @@ -195,8 +193,6 @@ github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclK github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-kratos/kratos/v2 v2.9.1 h1:EGif6/S/aK/RCR5clIbyhioTNyoSrii3FC118jG40Z0= -github.com/go-kratos/kratos/v2 v2.9.1/go.mod h1:a1MQLjMhIh7R0kcJS9SzJYR43BRI7EPzzN0J1Ksu2bA= github.com/go-kratos/kratos/v2 v2.9.2 h1:px8GJQBeLpquDKQWQ9zohEWiLA8n4D/pv7aH3asvUvo= github.com/go-kratos/kratos/v2 v2.9.2/go.mod h1:Jc7jaeYd4RAPjetun2C+oFAOO7HNMHTT/Z4LxpuEDJM= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= From 5046e31b63a8779deb9c7510148465f2b3c6cea9 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 7 Jan 2026 15:18:39 +0800 Subject: [PATCH 12/14] =?UTF-8?q?fix:=201.=E8=BF=98=E5=8E=9F6=E6=AC=A1?= =?UTF-8?q?=E8=BE=93=E5=85=A5=202.=E7=A7=BB=E9=99=A4=E5=8A=A9=E6=89=8B?= =?UTF-8?q?=E6=B6=88=E6=81=AF=EF=BC=88=E7=BA=AF=E5=99=AA=E9=9F=B3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.yaml | 2 +- config/config_env.yaml | 2 +- config/config_test.yaml | 2 +- internal/biz/do/prompt.go | 6 +++--- internal/biz/router.go | 42 +++++++++++++++++++-------------------- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 5e45ce9..33fa025 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -31,7 +31,7 @@ lsxd: sys: - session_len: 3 + session_len: 6 channel_pool_len: 100 channel_pool_size: 32 llm_pool_len: 5 diff --git a/config/config_env.yaml b/config/config_env.yaml index 0e002e0..b571f51 100644 --- a/config/config_env.yaml +++ b/config/config_env.yaml @@ -32,7 +32,7 @@ lsxd: sys: - session_len: 3 + session_len: 6 channel_pool_len: 100 channel_pool_size: 32 llm_pool_len: 5 diff --git a/config/config_test.yaml b/config/config_test.yaml index 873eb42..ec63488 100644 --- a/config/config_test.yaml +++ b/config/config_test.yaml @@ -32,7 +32,7 @@ lsxd: check_token_url: "https://api.user.1688sup.com/v1/user/welcome" sys: - session_len: 3 + session_len: 6 channel_pool_len: 100 channel_pool_size: 32 llm_pool_len: 5 diff --git a/internal/biz/do/prompt.go b/internal/biz/do/prompt.go index a27d698..b94d235 100644 --- a/internal/biz/do/prompt.go +++ b/internal/biz/do/prompt.go @@ -36,9 +36,9 @@ func (f *WithSys) CreatePrompt(ctx context.Context, rec *entitys.Recognize) (mes mes = append(prompt, api.Message{ Role: "system", // 系统角色 Content: rec.SystemPrompt, // 系统提示内容 - }, api.Message{ - Role: "assistant", // 助手角色 - Content: "### 聊天记录:" + pkg.JsonStringIgonErr(rec.ChatHis), // 助手回复内容 + // }, api.Message{ // 助手回复无需 + // Role: "assistant", // 助手角色 + // Content: "### 聊天记录:" + pkg.JsonStringIgonErr(rec.ChatHis), // 助手回复内容 }, api.Message{ Role: "user", // 用户角色 Content: content.String(), // 用户输入内容 diff --git a/internal/biz/router.go b/internal/biz/router.go index 2d827dc..3069ab0 100644 --- a/internal/biz/router.go +++ b/internal/biz/router.go @@ -178,13 +178,13 @@ func (r *AiRouterBiz) buildChatHistory(requireData *entitys.RequireData) entitys Timestamp: h.CreateAt.Format(time.DateTime), }) - // 助手消息 - ansStr := r.ansNoiseReduction(h.Ans) // 助手回复降噪 - messages = append(messages, entitys.HisMessage{ - Role: constants.RoleAssistant, // 助手角色 - Content: ansStr, // 助手回复内容 - Timestamp: h.CreateAt.Format(time.DateTime), - }) + // 助手消息 - 助手回复噪音太大且无需,pass + // ansStr := r.ansNoiseReduction(h.Ans) // 助手回复降噪 + // messages = append(messages, entitys.HisMessage{ + // Role: constants.RoleAssistant, // 助手角色 + // Content: ansStr, // 助手回复内容 + // Timestamp: h.CreateAt.Format(time.DateTime), + // }) } // 构建聊天历史上下文 @@ -199,18 +199,18 @@ func (r *AiRouterBiz) buildChatHistory(requireData *entitys.RequireData) entitys } // ansNoiseReduction 助手回复降噪 -func (r *AiRouterBiz) ansNoiseReduction(ansJson string) string { - // 使用anw统一类型解析 - ansStruct := make([]*entitys.Response, 0) - err := json.Unmarshal([]byte(ansJson), &ansStruct) - if err != nil { - log.Errorf("解析助手回复失败: %s", err.Error()) - return ansJson - } - var ansStr string - for _, item := range ansStruct { - ansStr += item.Content - } +// func (r *AiRouterBiz) ansNoiseReduction(ansJson string) string { +// // 使用anw统一类型解析 +// ansStruct := make([]*entitys.Response, 0) +// err := json.Unmarshal([]byte(ansJson), &ansStruct) +// if err != nil { +// log.Errorf("解析助手回复失败: %s", err.Error()) +// return ansJson +// } +// var ansStr string +// for _, item := range ansStruct { +// ansStr += item.Content +// } - return ansStr -} +// return ansStr +// } From f94738f7e7d7ecbd95d51045ab24085ce3171dcd Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 7 Jan 2026 16:49:10 +0800 Subject: [PATCH 13/14] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/do/prompt.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/biz/do/prompt.go b/internal/biz/do/prompt.go index b94d235..3993af1 100644 --- a/internal/biz/do/prompt.go +++ b/internal/biz/do/prompt.go @@ -39,6 +39,9 @@ func (f *WithSys) CreatePrompt(ctx context.Context, rec *entitys.Recognize) (mes // }, api.Message{ // 助手回复无需 // Role: "assistant", // 助手角色 // Content: "### 聊天记录:" + pkg.JsonStringIgonErr(rec.ChatHis), // 助手回复内容 + }, api.Message{ + Role: "user", // 用户角色 + Content: "历史聊天记录:" + pkg.JsonStringIgonErr(rec.ChatHis), // 用户输入内容 }, api.Message{ Role: "user", // 用户角色 Content: content.String(), // 用户输入内容 @@ -63,10 +66,10 @@ func (f *WithSys) getUserContent(ctx context.Context, rec *entitys.Recognize) (c content.WriteString(rec.UserContent.Tag) } - if len(rec.ChatHis.Messages) > 0 { - content.WriteString("### 引用历史聊天记录:\n") - content.WriteString(pkg.JsonStringIgonErr(rec.ChatHis)) - } + // if len(rec.ChatHis.Messages) > 0 { + // content.WriteString("### 引用历史聊天记录:\n") + // content.WriteString(pkg.JsonStringIgonErr(rec.ChatHis)) + // } if hasFile { content.WriteString("\n") From eb398a4b4d16fdfe68ed6a61b854d8d43e2999e3 Mon Sep 17 00:00:00 2001 From: fuzhongyun <15339891972@163.com> Date: Wed, 7 Jan 2026 16:50:53 +0800 Subject: [PATCH 14/14] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/do/prompt.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/biz/do/prompt.go b/internal/biz/do/prompt.go index 3993af1..3e4e965 100644 --- a/internal/biz/do/prompt.go +++ b/internal/biz/do/prompt.go @@ -40,8 +40,8 @@ func (f *WithSys) CreatePrompt(ctx context.Context, rec *entitys.Recognize) (mes // Role: "assistant", // 助手角色 // Content: "### 聊天记录:" + pkg.JsonStringIgonErr(rec.ChatHis), // 助手回复内容 }, api.Message{ - Role: "user", // 用户角色 - Content: "历史聊天记录:" + pkg.JsonStringIgonErr(rec.ChatHis), // 用户输入内容 + Role: "assistant", // 助手角色 + Content: "用户历史输入:" + pkg.JsonStringIgonErr(rec.ChatHis), // 用户历史输入 }, api.Message{ Role: "user", // 用户角色 Content: content.String(), // 用户输入内容