feat: 1.增加直连天下售后任务配置 2. 增加工具 3.增加输入输出mock
This commit is contained in:
parent
8cb59f656b
commit
8b4e696c77
|
|
@ -55,6 +55,11 @@ tools:
|
|||
enabled: true
|
||||
api_key: "dingsbbntrkeiyazcfdg"
|
||||
api_secret: "ObqxwyR20r9rVNhju0sCPQyQA98_FZSc32W4vgxnGFH_b02HZr1BPCJsOAF816nu"
|
||||
zltxOrderAfterSale:
|
||||
enabled: true
|
||||
base_url: "https://revcl.1688sup.com/api/admin/direct/ai/%s"
|
||||
add_url: "https://revcl.1688sup.com/api/admin/direct/log/%s/%s"
|
||||
|
||||
|
||||
default_prompt:
|
||||
img_recognize:
|
||||
|
|
|
|||
|
|
@ -89,6 +89,8 @@ type ToolsConfig struct {
|
|||
//通过账号获取订单统计信息
|
||||
ZltxOrderStatistics ToolConfig `mapstructure:"zltxOrderStatistics"`
|
||||
DingTalkBot ToolConfig `mapstructure:"dingTalkBot"`
|
||||
//直连天下订单售后工具
|
||||
ZltxOrderAfterSale ToolConfig `mapstructure:"zltxOrderAfterSale"`
|
||||
}
|
||||
|
||||
// ToolConfig 单个工具配置
|
||||
|
|
|
|||
|
|
@ -70,10 +70,16 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager {
|
|||
m.tools[knowledgeTool.Name()] = knowledgeTool
|
||||
}
|
||||
|
||||
if config.Tools.Knowledge.Enabled {
|
||||
knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge)
|
||||
m.tools[knowledgeTool.Name()] = knowledgeTool
|
||||
// 注册直连天下订单售后工具
|
||||
if config.Tools.ZltxOrderAfterSale.Enabled {
|
||||
zltxOrderAfterSaleTool := NewZltxOrderAfterSaleTool(config.Tools.ZltxOrderAfterSale)
|
||||
m.tools[zltxOrderAfterSaleTool.Name()] = zltxOrderAfterSaleTool
|
||||
}
|
||||
|
||||
// if config.Tools.Knowledge.Enabled {
|
||||
// knowledgeTool := NewKnowledgeBaseTool(config.Tools.Knowledge)
|
||||
// m.tools[knowledgeTool.Name()] = knowledgeTool
|
||||
// }
|
||||
// 普通对话
|
||||
chat := NewNormalChatTool(m.llm, config)
|
||||
m.tools[chat.Name()] = chat
|
||||
|
|
|
|||
|
|
@ -0,0 +1,131 @@
|
|||
package tools
|
||||
|
||||
import (
|
||||
"ai_scheduler/internal/config"
|
||||
"ai_scheduler/internal/entitys"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"gitea.cdlsxd.cn/self-tools/l_request"
|
||||
)
|
||||
|
||||
type ZltxOrderAfterSaleTool struct {
|
||||
config config.ToolConfig
|
||||
}
|
||||
|
||||
func (z ZltxOrderAfterSaleTool) Name() string {
|
||||
return "zltxOrderAfterSale"
|
||||
}
|
||||
|
||||
func (z ZltxOrderAfterSaleTool) Description() string {
|
||||
return "查询直连天下订单售后信息"
|
||||
}
|
||||
|
||||
func (z ZltxOrderAfterSaleTool) Definition() entitys.ToolDefinition {
|
||||
return entitys.ToolDefinition{
|
||||
Type: "function",
|
||||
Function: entitys.FunctionDef{
|
||||
Name: z.Name(),
|
||||
Description: z.Description(),
|
||||
Parameters: map[string]interface{}{
|
||||
"type": "object",
|
||||
"properties": map[string]interface{}{
|
||||
"number": map[string]interface{}{
|
||||
"type": "string",
|
||||
"description": "账号或分销商号",
|
||||
},
|
||||
},
|
||||
"required": []string{"number"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type ZltxOrderAfterSaleRequest struct {
|
||||
Number string `json:"number"`
|
||||
}
|
||||
|
||||
func (z ZltxOrderAfterSaleTool) Execute(ctx context.Context, requireData *entitys.RequireData) error {
|
||||
var req ZltxOrderAfterSaleRequest
|
||||
if err := json.Unmarshal([]byte(requireData.Match.Parameters), &req); err != nil {
|
||||
return err
|
||||
}
|
||||
if req.Number == "" {
|
||||
return fmt.Errorf("number is required")
|
||||
}
|
||||
return z.getZltxOrderAfterSale(req.Number, requireData)
|
||||
}
|
||||
|
||||
type ZltxOrderAfterSaleResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data struct {
|
||||
List []*ZltxOrderAfterSaleData `json:"list"`
|
||||
} `json:"data"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
type ZltxOrderAfterSaleData struct {
|
||||
// 处理方式 价款/扣款
|
||||
HandleMethod string `json:"handle_method"`
|
||||
// 售后金额
|
||||
AfterSaleAmount float64 `json:"after_sale_amount"`
|
||||
// 售后原因
|
||||
AfterSaleReason string `json:"after_sale_reason"`
|
||||
// 原单信息
|
||||
OriginalOrderInfo *OrderInfo
|
||||
}
|
||||
|
||||
type OrderInfo struct {
|
||||
SerialNumber string `json:"serial_number"` // 订单流水号
|
||||
SupplierName string `json:"supplier_name"` // 供应商名称
|
||||
SigningBody string `json:"signing_body"` // 签约主体
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
UpstreamPrice float64 `json:"upstream_price"` // 上游价格
|
||||
RechargeAccount string `json:"recharge_account"` // 充值账号
|
||||
RechargeStatus string `json:"recharge_status"` // 充值状态
|
||||
}
|
||||
|
||||
func (z ZltxOrderAfterSaleTool) getZltxOrderAfterSale(number string, requireData *entitys.RequireData) error {
|
||||
//查询订单详情
|
||||
|
||||
url := fmt.Sprintf("%s%s", z.config.BaseURL, number)
|
||||
req := l_request.Request{
|
||||
Url: url,
|
||||
Headers: map[string]string{
|
||||
"Authorization": fmt.Sprintf("Bearer %s", requireData.Auth),
|
||||
},
|
||||
Method: "GET",
|
||||
}
|
||||
res, err := req.Send()
|
||||
var resData ZltxOrderAfterSaleResponse
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := json.Unmarshal(res.Content, &resData); err != nil {
|
||||
return err
|
||||
}
|
||||
if resData.Code != 200 {
|
||||
return fmt.Errorf("为获取到数据,请检查权限: %s", string(res.Content))
|
||||
}
|
||||
//按照日期排序
|
||||
sort.Slice(resData.Data.RecentThreeDays, func(i, j int) bool {
|
||||
return resData.Data.RecentThreeDays[i].Date < resData.Data.RecentThreeDays[j].Date
|
||||
})
|
||||
sort.Slice(resData.Data.RecentOneMonth, func(i, j int) bool {
|
||||
return resData.Data.RecentOneMonth[i].Date < resData.Data.RecentOneMonth[j].Date
|
||||
})
|
||||
jsonByte, err := json.Marshal(resData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
entitys.ResJson(requireData.Ch, z.Name(), string(jsonByte))
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewZltxOrderAfterSaleTool(config config.ToolConfig) *ZltxOrderAfterSaleTool {
|
||||
return &ZltxOrderAfterSaleTool{
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue