feat: dev
This commit is contained in:
parent
ed6ea71bb0
commit
a8cfb118fe
|
|
@ -55,6 +55,9 @@ tools:
|
|||
enabled: true
|
||||
api_key: "dingsbbntrkeiyazcfdg"
|
||||
api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu"
|
||||
zltxOrderAfterSaleSupplier:
|
||||
enabled: true
|
||||
base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier"
|
||||
|
||||
default_prompt:
|
||||
img_recognize:
|
||||
|
|
|
|||
|
|
@ -93,6 +93,8 @@ type ToolsConfig struct {
|
|||
ZltxOrderAfterSaleDetail ToolConfig `mapstructure:"zltxOrderAfterSaleDetail"`
|
||||
//下游订单预检
|
||||
ZltxOrderAfterSalePreCheck ToolConfig `mapstructure:"zltxOrderAfterSalePreCheck"`
|
||||
// 上游订单售后
|
||||
ZltxOrderAfterSaleSupplier ToolConfig `mapstructure:"zltxOrderAfterSaleSupplier"`
|
||||
}
|
||||
|
||||
// ToolConfig 单个工具配置
|
||||
|
|
|
|||
|
|
@ -81,6 +81,12 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager {
|
|||
m.tools[zltxOrderAfterSalePreCheckTool.Name()] = zltxOrderAfterSalePreCheckTool
|
||||
}
|
||||
|
||||
// 注册直连天下上游售后订单工具
|
||||
if config.Tools.ZltxOrderAfterSaleSupplier.Enabled {
|
||||
zltxOrderAfterSaleSupplierTool := NewZltxOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier)
|
||||
m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool
|
||||
}
|
||||
|
||||
// 普通对话
|
||||
chat := NewNormalChatTool(m.llm, config)
|
||||
m.tools[chat.Name()] = chat
|
||||
|
|
|
|||
|
|
@ -0,0 +1,169 @@
|
|||
package tools
|
||||
|
||||
import (
|
||||
"ai_scheduler/internal/config"
|
||||
"ai_scheduler/internal/entitys"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ZltxOrderAfterSaleSupplierTool struct {
|
||||
config config.ToolConfig
|
||||
}
|
||||
|
||||
// NewZltxOrderAfterSaleSupplierTool 创建售后订单预检工具
|
||||
func NewZltxOrderAfterSaleSupplierTool(config config.ToolConfig) *ZltxOrderAfterSaleSupplierTool {
|
||||
return &ZltxOrderAfterSaleSupplierTool{config: config}
|
||||
}
|
||||
|
||||
// Name 返回工具名称
|
||||
func (t *ZltxOrderAfterSaleSupplierTool) Name() string {
|
||||
return "zltxOrderAfterSaleSupplier"
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleSupplierTool) Description() string {
|
||||
return "直连天下售后订单供应商工具"
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition {
|
||||
return entitys.ToolDefinition{
|
||||
Type: "function",
|
||||
Function: entitys.FunctionDef{
|
||||
Name: t.Name(),
|
||||
Description: t.Description(),
|
||||
Parameters: map[string]interface{}{
|
||||
"type": "object",
|
||||
"properties": map[string]interface{}{
|
||||
"orderType": map[string]interface{}{
|
||||
"type": "integer",
|
||||
"description": "售后订单类型",
|
||||
},
|
||||
"orderNumber": map[string]interface{}{
|
||||
"type": "string",
|
||||
"description": "售后订单号",
|
||||
},
|
||||
},
|
||||
"required": []string{"orderType", "orderNumber"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type ZltxOrderAfterSaleSupplierRequest struct {
|
||||
OrderNumber string `json:"orderNumber"` // 订单号
|
||||
SerialNumber string `json:"serialNumber"` // 流水号
|
||||
Account string `json:"account"` // 充值账号
|
||||
OrderTimeStart string `json:"orderTimeStart"` // 订单执行开始时间
|
||||
OrderTimeEnd string `json:"orderTimeEnd"` // 订单执行结束时间
|
||||
AfterSalesReason string `json:"afterSalesReason"` // 售后原因
|
||||
AfterSalesPrice string `json:"afterSalesPrice"` // 售后金额
|
||||
}
|
||||
|
||||
type ZltxOrderAfterSaleSupplierResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data []CheckResult2 `json:"data"`
|
||||
}
|
||||
|
||||
type CheckResult2 struct {
|
||||
OrderType int `json:"orderType"`
|
||||
OrderNumber string `json:"orderNumber"`
|
||||
OrderAmount float64 `json:"orderAmount"`
|
||||
OrderPrice float64 `json:"orderPrice"`
|
||||
SignCompany int `json:"signCompany"`
|
||||
OrderQuantity int `json:"orderQuantity"`
|
||||
ResellerID int `json:"resellerId"`
|
||||
ResellerName string `json:"resellerName"`
|
||||
OurProductID int `json:"ourProductId"`
|
||||
OurProductTitle string `json:"ourProductTitle"`
|
||||
Account []string `json:"account"`
|
||||
Platforms struct {
|
||||
Num4 string `json:"4"`
|
||||
} `json:"platforms"`
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error {
|
||||
var req ZltxOrderAfterSaleSupplierRequest
|
||||
if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil {
|
||||
return err
|
||||
}
|
||||
if req.OrderNumber == "" {
|
||||
return fmt.Errorf("orderType and orderNumber are required")
|
||||
}
|
||||
return t.checkZltxOrderAfterSaleSupplier(req.OrderNumber, requireData)
|
||||
}
|
||||
|
||||
func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNumber string, requireData *entitys.RequireData) error {
|
||||
// req := l_request.Request{
|
||||
// Url: t.config.BaseURL,
|
||||
// Headers: map[string]string{
|
||||
// "Authorization": fmt.Sprintf("Bearer %s", requireData.Auth),
|
||||
// },
|
||||
// Method: "POST",
|
||||
// Data: map[string]string{
|
||||
// // "orderType": fmt.Sprintf("%d", orderType),
|
||||
// "orderNumber": orderNumber,
|
||||
// },
|
||||
// }
|
||||
// res, err := req.Send()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // 解析响应
|
||||
// var resp ZltxOrderAfterSaleSupplierResponse
|
||||
// if err := json.Unmarshal(res.Content, &resp); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if resp.Code != 0 {
|
||||
// return fmt.Errorf("check failed: %s", resp.Msg)
|
||||
// }
|
||||
resp := ZltxOrderAfterSaleSupplierResponse{
|
||||
Code: 0,
|
||||
Msg: "success",
|
||||
Data: []CheckResult2{
|
||||
{
|
||||
OrderType: 1,
|
||||
OrderNumber: orderNumber,
|
||||
OrderAmount: 100,
|
||||
OrderPrice: 100,
|
||||
SignCompany: 1,
|
||||
OrderQuantity: 1,
|
||||
ResellerID: 1,
|
||||
ResellerName: "测试",
|
||||
OurProductID: 1,
|
||||
OurProductTitle: "测试",
|
||||
Account: []string{"123456"},
|
||||
Platforms: struct {
|
||||
Num4 string `json:"4"`
|
||||
}{
|
||||
Num4: "123456",
|
||||
},
|
||||
},
|
||||
{
|
||||
OrderType: 2,
|
||||
OrderNumber: orderNumber,
|
||||
OrderAmount: 100,
|
||||
OrderPrice: 100,
|
||||
SignCompany: 1,
|
||||
OrderQuantity: 1,
|
||||
ResellerID: 1,
|
||||
ResellerName: "测试",
|
||||
OurProductID: 1,
|
||||
OurProductTitle: "测试",
|
||||
Account: []string{"123456"},
|
||||
Platforms: struct {
|
||||
Num4 string `json:"4"`
|
||||
}{
|
||||
Num4: "123456",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
jsonByte, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte))
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
package tools_bot
|
||||
|
||||
import (
|
||||
"ai_scheduler/internal/entitys"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/ollama/ollama/api"
|
||||
)
|
||||
|
||||
type AfterSalesSupplierArgs struct {
|
||||
OrderNumber string `json:"orderNumber"`
|
||||
SerialNumber string `json:"serialNumber"`
|
||||
Account string `json:"account"`
|
||||
OrderTimeStart int `json:"orderTimeStart"`
|
||||
OrderTimeEnd int `json:"orderTimeEnd"`
|
||||
}
|
||||
|
||||
type AfterSalesSupplierList struct {
|
||||
AfterSalesSupplierData []*AfterSalesSupplierData `json:"afterSalesSupplierData"`
|
||||
}
|
||||
|
||||
type AfterSalesSupplierData struct {
|
||||
OrderNumber string `json:"orderNumber"`
|
||||
SerialNumber string `json:"serialNumber"`
|
||||
Account string `json:"account"`
|
||||
OrderTimeStart int `json:"orderTimeStart"`
|
||||
OrderTimeEnd int `json:"orderTimeEnd"`
|
||||
}
|
||||
|
||||
// AfterSalesSupplier 售后供应商
|
||||
func (w *BotTool) AfterSalesSupplier(ctx context.Context, requireData *entitys.RequireData) (err error) {
|
||||
// 1. 参数提取
|
||||
extractResponse, err := w.llm.Generation(ctx, &api.GenerateRequest{
|
||||
Model: w.config.Ollama.Model,
|
||||
Stream: new(bool),
|
||||
System: `
|
||||
你是一个内容提取工具,用户会提供上游供应商售后流水/订单相关问题,你需要提取用户咨询的订单/流水信息。
|
||||
- 提取的信息有 订单号、流水号、充值账号、订单时间区间
|
||||
- 仅返回json: {"orderNumber":"","serialNumber":"","account":"","orderTimeStart":unix时间戳,"orderTimeEnd":unix时间戳}
|
||||
- 不要有额外的描述、markdown等
|
||||
用户输入:%s
|
||||
`,
|
||||
Prompt: requireData.Req.Text,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
afterSalesSupplierArgs := &AfterSalesSupplierArgs{}
|
||||
_ = json.Unmarshal([]byte(extractResponse.Response), afterSalesSupplierArgs)
|
||||
|
||||
// 流水号为空
|
||||
if afterSalesSupplierArgs.SerialNumber == "" {
|
||||
// 1.1 通过充值账号查询订单号
|
||||
|
||||
// 1.2 通过订单号拉取流水号
|
||||
|
||||
}
|
||||
|
||||
// 流水号不存在
|
||||
if afterSalesSupplierArgs.SerialNumber == "" {
|
||||
return fmt.Errorf("serialNumber is required")
|
||||
}
|
||||
|
||||
// 流水号转切片
|
||||
serialNumbers := strings.Split(afterSalesSupplierArgs.SerialNumber, ",")
|
||||
_ = serialNumbers
|
||||
|
||||
// 2. 获取流水详情
|
||||
// ZltxOrderAfterSaleDetailTool
|
||||
|
||||
// 3. 组装售后订单详情
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -30,12 +30,6 @@ func (w *BotTool) Execute(ctx context.Context, toolName string, requireData *ent
|
|||
switch toolName {
|
||||
case constants.BotToolsBugOptimizationSubmit:
|
||||
err = w.BugOptimizationSubmit(ctx, requireData)
|
||||
case constants.BotToolsAfterSalesSupplier:
|
||||
err = w.AfterSalesSupplier(ctx, requireData)
|
||||
// case constants.BotToolsAfterSalesResellerSingle:
|
||||
// err = w.AfterSalesResellerSingle(ctx, requireData)
|
||||
// case constants.BotToolsAfterSalesResellerBatch:
|
||||
// err = w.AfterSalesResellerBatch(ctx, requireData)
|
||||
default:
|
||||
log.Errorf("未知的工具类型:%s", toolName)
|
||||
err = errors.ParamErr("未知的工具类型:%s", toolName)
|
||||
|
|
|
|||
Loading…
Reference in New Issue