fix:修复报错
This commit is contained in:
parent
567874848b
commit
d7b39f4d60
|
|
@ -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)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import (
|
|||
// 判断文件大小
|
||||
// 判断文件类型
|
||||
// 判断文件是否合法
|
||||
func HandleRecognizeFile(file *entitys.RecognizeFile) {
|
||||
func HandleRecognizeFile(files *entitys.RecognizeFile) {
|
||||
//Todo 仲云
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue