结构修改
This commit is contained in:
parent
1412554661
commit
3f37427181
|
@ -26,3 +26,9 @@ redis:
|
|||
db:
|
||||
driver: mysql
|
||||
source: root:SD###sdf323r343@tcp(121.199.38.107:3306)/sys_ai?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai
|
||||
|
||||
tools:
|
||||
zltxOrderDetail:
|
||||
enabled: true
|
||||
base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/direct/ai/"
|
||||
api_key: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1c2VyQ2VudGVyIiwiZXhwIjoxNzU2MTgyNTM1LCJuYmYiOjE3NTYxODA3MzUsImp0aSI6IjEiLCJQaG9uZSI6IjE4MDAwMDAwMDAwIiwiVXNlck5hbWUiOiJsc3hkIiwiUmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJBY2NvdW50VHlwZSI6MSwiR3JvdXBDb2RlcyI6IlZDTF9DQVNISUVSLFZDTF9PUEVSQVRFLFZDTF9BRE1JTixWQ0xfQUFBLFZDTF9WQ0xfT1BFUkFULFZDTF9JTlZPSUNFLENSTV9BRE1JTixMSUFOTElBTl9BRE1JTixNQVJLRVRNQUcyX0FETUlOLFBIT05FQklMTF9BRE1JTixRSUFOWkhVX1NVUFBFUl9BRE0sTUFSS0VUSU5HU0FBU19TVVBFUkFETUlOLENBUkRfQ09ERSxDQVJEX1BST0NVUkVNRU5ULE1BUktFVElOR1NZU1RFTV9TVVBFUixTVEFUSVNUSUNBTFNZU1RFTV9BRE1JTixaTFRYX0FETUlOLFpMVFhfT1BFUkFURSIsIkRpbmdVc2VySWQiOiIxNjIwMjYxMjMwMjg5MzM4MzQifQ.N1xv1PYbcO8_jR5adaczc16YzGsr4z101gwEZdulkRaREBJNYTOnFrvRxTFx3RJTooXsqTqroE1MR84v_1WPX6BS6kKonA-kC1Jgot6yrt5rFWhGNGb2Cpr9rKIFCCQYmiGd3AUgDazEeaQ0_sodv3E-EXg9VfE1SX8nMcck9Yjnc8NCy7RTWaBIaSeOdZcEl-JfCD0S6GSx3oErp_hk-U9FKGwf60wAuDGTY1R0BP4BYpcEqS-C2LSnsSGyURi54Cuk5xH8r1WuF0Dm5bwAj5d7Hvs77-N_sUF-C5ONqyZJRAEhYLgcmN9RX_WQZfizdQJxizlTczdpzYfy-v-1eQ"
|
||||
|
|
|
@ -10,6 +10,9 @@ import (
|
|||
"ai_scheduler/utils"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
|
@ -29,12 +32,16 @@ type configData struct {
|
|||
|
||||
func Test_Order(t *testing.T) {
|
||||
routerBiz := in()
|
||||
err := routerBiz.handleTask(nil, &entitys.Match{Index: "order_diagnosis"}, &model.AiTask{Config: `{"tool": "zltxOrderDetail", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`})
|
||||
err := routerBiz.handleTask(nil, &entitys.Match{Index: "order_diagnosis", Parameters: `{"order_number":"12312312312"}`}, &model.AiTask{Config: `{"tool": "zltxOrderDetail", "param": {"type": "object", "optional": [], "required": ["order_number"], "properties": {"order_number": {"type": "string", "description": "订单编号/流水号"}}}}`})
|
||||
t.Log(err)
|
||||
}
|
||||
|
||||
func in() *AiRouterBiz {
|
||||
configPath := flag.String("config", "./config/config.yaml", "Path to configuration file")
|
||||
modDir, err := getModuleDir()
|
||||
if err != nil {
|
||||
panic("1")
|
||||
}
|
||||
configPath := flag.String("config", fmt.Sprintf("%s/config/config.yaml", modDir), "Path to configuration file")
|
||||
flag.Parse()
|
||||
configConfig, err := config.LoadConfig(*configPath)
|
||||
if err != nil {
|
||||
|
@ -52,3 +59,26 @@ func in() *AiRouterBiz {
|
|||
|
||||
return routerBiz
|
||||
}
|
||||
|
||||
func getModuleDir() (string, error) {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for {
|
||||
modPath := filepath.Join(dir, "go.mod")
|
||||
if _, err := os.Stat(modPath); err == nil {
|
||||
return dir, nil // 找到 go.mod
|
||||
}
|
||||
|
||||
// 向上查找父目录
|
||||
parent := filepath.Dir(dir)
|
||||
if parent == dir {
|
||||
break // 到达根目录,未找到
|
||||
}
|
||||
dir = parent
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("go.mod not found in current directory or parents")
|
||||
}
|
||||
|
|
|
@ -73,10 +73,9 @@ type ToolsConfig struct {
|
|||
|
||||
// ToolConfig 单个工具配置
|
||||
type ToolConfig struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
APIKey string `mapstructure:"api_key"`
|
||||
BizSystem string `mapstructure:"biz_system"`
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
APIKey string `mapstructure:"api_key"`
|
||||
}
|
||||
|
||||
// LoggingConfig 日志配置
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/gofiber/websocket/v2"
|
||||
)
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ func (w *ZltxOrderDetailTool) Definition() entitys.ToolDefinition {
|
|||
|
||||
// ZltxOrderDetailRequest 直连天下订单详情请求参数
|
||||
type ZltxOrderDetailRequest struct {
|
||||
Number string `json:"number"`
|
||||
OrderNumber string `json:"order_number"`
|
||||
}
|
||||
|
||||
// ZltxOrderDetailResponse 直连天下订单详情响应
|
||||
|
@ -77,21 +77,28 @@ func (w *ZltxOrderDetailTool) Execute(c *websocket.Conn, args json.RawMessage) e
|
|||
return fmt.Errorf("invalid zltxOrderDetail request: %w", err)
|
||||
}
|
||||
|
||||
if req.Number == "" {
|
||||
if req.OrderNumber == "" {
|
||||
return fmt.Errorf("number is required")
|
||||
}
|
||||
|
||||
// 这里可以集成真实的直连天下订单详情API
|
||||
return w.getZltxOrderDetail(c, req.Number)
|
||||
return w.getZltxOrderDetail(c, req.OrderNumber)
|
||||
}
|
||||
|
||||
// getMockZltxOrderDetail 获取模拟直连天下订单详情数据
|
||||
func (w *ZltxOrderDetailTool) getZltxOrderDetail(c *websocket.Conn, number string) (err error) {
|
||||
//查询订单详情
|
||||
var auth string
|
||||
if c != nil {
|
||||
auth = c.Headers("X-Authorization", "")
|
||||
}
|
||||
if len(auth) == 0 {
|
||||
auth = w.config.APIKey
|
||||
}
|
||||
req := l_request.Request{
|
||||
Url: fmt.Sprintf("%s/admin/direct/ai/%s", w.config.BaseURL, number),
|
||||
Url: fmt.Sprintf("%s%s", w.config.BaseURL, number),
|
||||
Headers: map[string]string{
|
||||
"Authorization": fmt.Sprintf("Bearer %s", w.config.APIKey),
|
||||
"Authorization": fmt.Sprintf("Bearer %s", auth),
|
||||
},
|
||||
Method: "GET",
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue