fix:修复报错
This commit is contained in:
parent
567874848b
commit
d7b39f4d60
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"ai_scheduler/internal/config"
|
"ai_scheduler/internal/config"
|
||||||
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
|
@ -10,6 +11,7 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configPath := flag.String("config", "./config/config_test.yaml", "Path to configuration file")
|
configPath := flag.String("config", "./config/config_test.yaml", "Path to configuration file")
|
||||||
|
onBot := flag.String("bot", "", "bot start")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
bc, err := config.LoadConfig(*configPath)
|
bc, err := config.LoadConfig(*configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -23,7 +25,7 @@ func main() {
|
||||||
defer func() {
|
defer func() {
|
||||||
cleanup()
|
cleanup()
|
||||||
}()
|
}()
|
||||||
//app.DingBotServer.Run(context.Background())
|
app.DingBotServer.Run(context.Background(), *onBot)
|
||||||
//app.DingBotServer.RunBots(app.DingBotServer.BotServices)
|
|
||||||
log.Fatal(app.HttpServer.Listen(fmt.Sprintf(":%d", bc.Server.Port)))
|
log.Fatal(app.HttpServer.Listen(fmt.Sprintf(":%d", bc.Server.Port)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,10 @@ fi
|
||||||
|
|
||||||
CONFIG_FILE="config/config.yaml"
|
CONFIG_FILE="config/config.yaml"
|
||||||
BRANCH="master"
|
BRANCH="master"
|
||||||
|
BOT="ALL"
|
||||||
if [ "$MODE" = "dev" ]; then
|
if [ "$MODE" = "dev" ]; then
|
||||||
CONFIG_FILE="config/config_test.yaml"
|
CONFIG_FILE="config/config_test.yaml"
|
||||||
|
BOT="zltx"
|
||||||
BRANCH="test"
|
BRANCH="test"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -33,6 +35,6 @@ docker run -itd \
|
||||||
-e "OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://host.docker.internal:11434}" \
|
-e "OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://host.docker.internal:11434}" \
|
||||||
-e "MODE=${MODE}" \
|
-e "MODE=${MODE}" \
|
||||||
-p 8090:8090 \
|
-p 8090:8090 \
|
||||||
"${CONTAINER_NAME}" ./server --config "./${CONFIG_FILE}"
|
"${CONTAINER_NAME}" ./server --config "./${CONFIG_FILE}" --bot "./${BOT}"
|
||||||
|
|
||||||
docker logs -f ${CONTAINER_NAME}
|
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) {
|
func (f *WithSys) getUserContent(ctx context.Context, rec *entitys.Recognize) (content strings.Builder, err error) {
|
||||||
var hasFile bool
|
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
|
hasFile = true
|
||||||
}
|
}
|
||||||
content.WriteString(rec.UserContent.Text)
|
content.WriteString(rec.UserContent.Text)
|
||||||
|
|
@ -65,7 +65,10 @@ func (f *WithSys) getUserContent(ctx context.Context, rec *entitys.Recognize) (c
|
||||||
if hasFile {
|
if hasFile {
|
||||||
content.WriteString("\n")
|
content.WriteString("\n")
|
||||||
content.WriteString("### 文件内容:\n")
|
content.WriteString("### 文件内容:\n")
|
||||||
handle.HandleRecognizeFile(rec.UserContent.File)
|
for _, file := range rec.UserContent.File {
|
||||||
|
handle.HandleRecognizeFile(file)
|
||||||
|
}
|
||||||
|
|
||||||
//...do something with file
|
//...do something with file
|
||||||
}
|
}
|
||||||
return
|
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) {
|
func (f *WithDingTalkBot) getUserContent(ctx context.Context, rec *entitys.Recognize) (content strings.Builder, err error) {
|
||||||
var hasFile bool
|
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
|
hasFile = true
|
||||||
}
|
}
|
||||||
content.WriteString(rec.UserContent.Text)
|
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))
|
content.WriteString(pkg.JsonStringIgonErr(rec.ChatHis))
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasFile {
|
|
||||||
content.WriteString("\n")
|
|
||||||
content.WriteString("### 文件内容:\n")
|
|
||||||
handle.HandleRecognizeFile(rec.UserContent.File)
|
|
||||||
//...do something with file
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import (
|
||||||
// 判断文件大小
|
// 判断文件大小
|
||||||
// 判断文件类型
|
// 判断文件类型
|
||||||
// 判断文件是否合法
|
// 判断文件是否合法
|
||||||
func HandleRecognizeFile(file *entitys.RecognizeFile) {
|
func HandleRecognizeFile(files *entitys.RecognizeFile) {
|
||||||
//Todo 仲云
|
//Todo 仲云
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ type RequireDataDingTalkBot struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type DingTalkBot struct {
|
type DingTalkBot struct {
|
||||||
ClientId string `mapstructure:"client_id"`
|
BotIndex string
|
||||||
ClientSecret string `mapstructure:"client_secret"`
|
ClientId string
|
||||||
|
ClientSecret string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ type DingBotServiceInterface interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type DingTalkBotServer struct {
|
type DingTalkBotServer struct {
|
||||||
Clients []*client.StreamClient
|
Clients map[string]*client.StreamClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDingTalkBotServer 批量注册钉钉客户端cli
|
// NewDingTalkBotServer 批量注册钉钉客户端cli
|
||||||
|
|
@ -27,19 +27,19 @@ type DingTalkBotServer struct {
|
||||||
func NewDingTalkBotServer(
|
func NewDingTalkBotServer(
|
||||||
services []DingBotServiceInterface,
|
services []DingBotServiceInterface,
|
||||||
) *DingTalkBotServer {
|
) *DingTalkBotServer {
|
||||||
clients := make([]*client.StreamClient, 0)
|
clients := make(map[string]*client.StreamClient)
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
serviceConfigs, index := service.GetServiceCfg()
|
serviceConfigs, err := service.GetServiceCfg()
|
||||||
for _, serviceConf := range serviceConfigs {
|
for _, serviceConf := range serviceConfigs {
|
||||||
if serviceConf.ClientId == "" || serviceConf.ClientSecret == "" {
|
if serviceConf.ClientId == "" || serviceConf.ClientSecret == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cli := DingBotServerInit(serviceConf.ClientId, serviceConf.ClientSecret, service)
|
cli := DingBotServerInit(serviceConf.ClientId, serviceConf.ClientSecret, service)
|
||||||
if cli == nil {
|
if cli == nil {
|
||||||
log.Info("%s客户端初始失败", index)
|
log.Info("%s客户端初始失败:%s", serviceConf.BotIndex, err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
clients = append(clients, cli)
|
clients[serviceConf.BotIndex] = cli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &DingTalkBotServer{
|
return &DingTalkBotServer{
|
||||||
|
|
@ -53,8 +53,13 @@ func ProvideAllDingBotServices(
|
||||||
return []DingBotServiceInterface{dingBotSvc}
|
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 {
|
for name, cli := range d.Clients {
|
||||||
|
if botIndex != "All" {
|
||||||
|
if name != botIndex {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
err := cli.Start(ctx)
|
err := cli.Start(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("%s启动失败", name)
|
log.Info("%s启动失败", name)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue