From d7b39f4d60a8db83c8d20c4fcc0371bc8effda5e Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Wed, 10 Dec 2025 14:19:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server/main.go | 6 ++++-- deploy.sh | 4 +++- internal/biz/do/prompt.go | 15 ++++++--------- internal/biz/handle/file.go | 2 +- internal/entitys/bot.go | 5 +++-- internal/server/ding_talk_bot.go | 17 +++++++++++------ 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index a6607f5..d765735 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,6 +11,7 @@ import ( func main() { configPath := flag.String("config", "./config/config_test.yaml", "Path to configuration file") + onBot := flag.String("bot", "", "bot start") flag.Parse() bc, err := config.LoadConfig(*configPath) if err != nil { @@ -23,7 +25,7 @@ func main() { defer func() { cleanup() }() - //app.DingBotServer.Run(context.Background()) - //app.DingBotServer.RunBots(app.DingBotServer.BotServices) + app.DingBotServer.Run(context.Background(), *onBot) + log.Fatal(app.HttpServer.Listen(fmt.Sprintf(":%d", bc.Server.Port))) } diff --git a/deploy.sh b/deploy.sh index f02e162..2766253 100644 --- a/deploy.sh +++ b/deploy.sh @@ -14,8 +14,10 @@ fi CONFIG_FILE="config/config.yaml" BRANCH="master" +BOT="ALL" if [ "$MODE" = "dev" ]; then CONFIG_FILE="config/config_test.yaml" + BOT="zltx" BRANCH="test" fi @@ -33,6 +35,6 @@ docker run -itd \ -e "OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://host.docker.internal:11434}" \ -e "MODE=${MODE}" \ -p 8090:8090 \ - "${CONTAINER_NAME}" ./server --config "./${CONFIG_FILE}" + "${CONTAINER_NAME}" ./server --config "./${CONFIG_FILE}" --bot "./${BOT}" docker logs -f ${CONTAINER_NAME} \ No newline at end of file diff --git a/internal/biz/do/prompt.go b/internal/biz/do/prompt.go index f25cf95..ea82f84 100644 --- a/internal/biz/do/prompt.go +++ b/internal/biz/do/prompt.go @@ -43,7 +43,7 @@ func (f *WithSys) CreatePrompt(ctx context.Context, rec *entitys.Recognize) (mes func (f *WithSys) getUserContent(ctx context.Context, rec *entitys.Recognize) (content strings.Builder, err error) { var hasFile bool - if rec.UserContent.File != nil && (len(rec.UserContent.File.FileUrl) > 0 || rec.UserContent.File.File != nil) { + if rec.UserContent.File != nil && len(rec.UserContent.File) > 0 { hasFile = true } content.WriteString(rec.UserContent.Text) @@ -65,7 +65,10 @@ func (f *WithSys) getUserContent(ctx context.Context, rec *entitys.Recognize) (c if hasFile { content.WriteString("\n") content.WriteString("### 文件内容:\n") - handle.HandleRecognizeFile(rec.UserContent.File) + for _, file := range rec.UserContent.File { + handle.HandleRecognizeFile(file) + } + //...do something with file } return @@ -100,7 +103,7 @@ func (f *WithDingTalkBot) CreatePrompt(ctx context.Context, rec *entitys.Recogni func (f *WithDingTalkBot) getUserContent(ctx context.Context, rec *entitys.Recognize) (content strings.Builder, err error) { var hasFile bool - if rec.UserContent.File != nil && (len(rec.UserContent.File.FileUrl) > 0 || rec.UserContent.File.File != nil) { + if rec.UserContent.File != nil && len(rec.UserContent.File) > 0 { hasFile = true } content.WriteString(rec.UserContent.Text) @@ -119,11 +122,5 @@ func (f *WithDingTalkBot) getUserContent(ctx context.Context, rec *entitys.Recog content.WriteString(pkg.JsonStringIgonErr(rec.ChatHis)) } - if hasFile { - content.WriteString("\n") - content.WriteString("### 文件内容:\n") - handle.HandleRecognizeFile(rec.UserContent.File) - //...do something with file - } return } diff --git a/internal/biz/handle/file.go b/internal/biz/handle/file.go index 9fd4fae..e9332aa 100644 --- a/internal/biz/handle/file.go +++ b/internal/biz/handle/file.go @@ -18,7 +18,7 @@ import ( // 判断文件大小 // 判断文件类型 // 判断文件是否合法 -func HandleRecognizeFile(file *entitys.RecognizeFile) { +func HandleRecognizeFile(files *entitys.RecognizeFile) { //Todo 仲云 return } diff --git a/internal/entitys/bot.go b/internal/entitys/bot.go index fc24764..568822c 100644 --- a/internal/entitys/bot.go +++ b/internal/entitys/bot.go @@ -24,6 +24,7 @@ type RequireDataDingTalkBot struct { } type DingTalkBot struct { - ClientId string `mapstructure:"client_id"` - ClientSecret string `mapstructure:"client_secret"` + BotIndex string + ClientId string + ClientSecret string } diff --git a/internal/server/ding_talk_bot.go b/internal/server/ding_talk_bot.go index 1d6c4a4..9a63812 100644 --- a/internal/server/ding_talk_bot.go +++ b/internal/server/ding_talk_bot.go @@ -16,7 +16,7 @@ type DingBotServiceInterface interface { } type DingTalkBotServer struct { - Clients []*client.StreamClient + Clients map[string]*client.StreamClient } // NewDingTalkBotServer 批量注册钉钉客户端cli @@ -27,19 +27,19 @@ type DingTalkBotServer struct { func NewDingTalkBotServer( services []DingBotServiceInterface, ) *DingTalkBotServer { - clients := make([]*client.StreamClient, 0) + clients := make(map[string]*client.StreamClient) for _, service := range services { - serviceConfigs, index := service.GetServiceCfg() + serviceConfigs, err := service.GetServiceCfg() for _, serviceConf := range serviceConfigs { if serviceConf.ClientId == "" || serviceConf.ClientSecret == "" { continue } cli := DingBotServerInit(serviceConf.ClientId, serviceConf.ClientSecret, service) if cli == nil { - log.Info("%s客户端初始失败", index) + log.Info("%s客户端初始失败:%s", serviceConf.BotIndex, err.Error()) continue } - clients = append(clients, cli) + clients[serviceConf.BotIndex] = cli } } return &DingTalkBotServer{ @@ -53,8 +53,13 @@ func ProvideAllDingBotServices( return []DingBotServiceInterface{dingBotSvc} } -func (d *DingTalkBotServer) Run(ctx context.Context) { +func (d *DingTalkBotServer) Run(ctx context.Context, botIndex string) { for name, cli := range d.Clients { + if botIndex != "All" { + if name != botIndex { + continue + } + } err := cli.Start(ctx) if err != nil { log.Info("%s启动失败", name)