feat: 工具输入输出 mock

This commit is contained in:
fuzhongyun 2025-11-24 11:16:01 +08:00
parent 9ec4146e17
commit 57788c9908
7 changed files with 219 additions and 26 deletions

View File

@ -58,6 +58,9 @@ tools:
zltxOrderAfterSaleSupplier:
enabled: true
base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier"
zltxOrderAfterSaleReseller:
enabled: true
base_url: "https://revcl.1688sup.com/api/admin/afterSales/reseller_supplier"
default_prompt:
img_recognize:

View File

@ -17,9 +17,9 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/gofiber/fiber/v2/log"
"gorm.io/gorm/utils"
"strings"
"gorm.io/gorm/utils"
)
type Handle struct {
@ -95,10 +95,10 @@ func (r *Handle) HandleMatch(ctx context.Context, client *gateway.Client, requir
}
// 校验用户权限
if err = r.PermissionAuth(client, pointTask); err != nil {
log.Errorf("权限验证失败: %s", err.Error())
return
}
// if err = r.PermissionAuth(client, pointTask); err != nil {
// log.Errorf("权限验证失败: %s", err.Error())
// return
// }
switch constants.TaskType(pointTask.Type) {
case constants.TaskTypeApi:

View File

@ -96,6 +96,8 @@ type ToolsConfig struct {
ZltxOrderAfterSalePreCheck ToolConfig `mapstructure:"zltxOrderAfterSalePreCheck"`
// 上游订单售后
ZltxOrderAfterSaleSupplier ToolConfig `mapstructure:"zltxOrderAfterSaleSupplier"`
// 下游订单售后
ZltxOrderAfterSaleReseller ToolConfig `mapstructure:"zltxOrderAfterSaleReseller"`
}
// ToolConfig 单个工具配置

View File

@ -9,11 +9,12 @@ import (
"ai_scheduler/internal/gateway"
"ai_scheduler/internal/pkg/l_request"
"encoding/json"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/websocket/v2"
"log"
"net/http"
"sync"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/websocket/v2"
)
// ChatHandler 聊天处理器

View File

@ -86,6 +86,11 @@ func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager {
zltxOrderAfterSaleSupplierTool := NewZltxOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier)
m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool
}
// 注册直连天下下游售后订单工具
if config.Tools.ZltxOrderAfterSaleReseller.Enabled {
zltxOrderAfterSaleResellerTool := NewZltxOrderAfterSaleResellerTool(config.Tools.ZltxOrderAfterSaleReseller)
m.tools[zltxOrderAfterSaleResellerTool.Name()] = zltxOrderAfterSaleResellerTool
}
// 普通对话
chat := NewNormalChatTool(m.llm, config)

View File

@ -0,0 +1,176 @@
package tools
import (
"ai_scheduler/internal/config"
"ai_scheduler/internal/entitys"
"context"
"encoding/json"
"fmt"
)
type ZltxOrderAfterSaleResellerTool struct {
config config.ToolConfig
}
// NewZltxOrderAfterSaleResellerTool 创建售后订单预检工具
func NewZltxOrderAfterSaleResellerTool(config config.ToolConfig) *ZltxOrderAfterSaleResellerTool {
return &ZltxOrderAfterSaleResellerTool{config: config}
}
// Name 返回工具名称
func (t *ZltxOrderAfterSaleResellerTool) Name() string {
return "zltxOrderAfterSaleReseller"
}
func (t *ZltxOrderAfterSaleResellerTool) Description() string {
return "直连天下上游供应商售后工具"
}
func (t *ZltxOrderAfterSaleResellerTool) 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 ZltxOrderAfterSaleResellerRequest 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 ZltxOrderAfterSaleResellerResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data []ZltxOrderAfterSaleResellerData `json:"data"`
}
type ZltxOrderAfterSaleResellerData 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 map[int]string `json:"platforms"`
AfterType int `json:"afterType"` // 处理方式 1.退款 2.扣款
Remark string `json:"remark"` // 售后原因
AfterAmount float64 `json:"afterAmount"` // 售后金额
ResponsibleType int `json:"responsibleType"` // 费用承担者 1.供应商 2.商务 3.公司 4.无
ResponsiblePerson string `json:"responsiblePerson"` // 费用承担供应商
IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后
}
func (t *ZltxOrderAfterSaleResellerTool) Execute(ctx context.Context, requireData *entitys.RequireData) error {
var req ZltxOrderAfterSaleResellerRequest
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.checkZltxOrderAfterSaleReseller(req.OrderNumber, requireData)
}
func (t *ZltxOrderAfterSaleResellerTool) checkZltxOrderAfterSaleReseller(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 ZltxOrderAfterSaleResellerResponse
// if err := json.Unmarshal(res.Content, &resp); err != nil {
// return err
// }
// if resp.Code != 0 {
// return fmt.Errorf("check failed: %s", resp.Msg)
// }
resp := ZltxOrderAfterSaleResellerResponse{
Code: 0,
Msg: "success",
Data: []ZltxOrderAfterSaleResellerData{
// 为我生成两条不一样的数据
{
OrderType: 1,
OrderNumber: orderNumber,
OrderAmount: 100,
OrderPrice: 100,
SignCompany: 1,
OrderQuantity: 1,
ResellerID: 1,
ResellerName: "测试供应商",
OurProductID: 1,
OurProductTitle: "测试商品",
Account: []string{"123456"},
Platforms: map[int]string{4: "测试平台"},
AfterType: 1,
Remark: "测试售后",
AfterAmount: 50,
ResponsibleType: 1,
IsExistsAfterSale: true,
},
{
OrderType: 1,
OrderNumber: orderNumber,
OrderAmount: 100,
OrderPrice: 100,
SignCompany: 1,
OrderQuantity: 1,
ResellerID: 1,
ResellerName: "测试供应商2",
OurProductID: 1,
OurProductTitle: "测试商品2",
Account: []string{"123456"},
Platforms: map[int]string{4: "测试平台2"},
AfterType: 2,
Remark: "测试售后2",
AfterAmount: 30,
ResponsibleType: 2,
IsExistsAfterSale: false,
},
},
}
jsonByte, err := json.Marshal(resp)
if err != nil {
return err
}
entitys.ResJson(requireData.Ch, t.Name(), string(jsonByte))
return nil
}

View File

@ -23,7 +23,7 @@ func (t *ZltxOrderAfterSaleSupplierTool) Name() string {
}
func (t *ZltxOrderAfterSaleSupplierTool) Description() string {
return "直连天下售后订单供应商工具"
return "直连天下上游供应商售后工具"
}
func (t *ZltxOrderAfterSaleSupplierTool) Definition() entitys.ToolDefinition {
@ -67,19 +67,21 @@ type ZltxOrderAfterSaleSupplierResponse struct {
}
type ZltxOrderAfterSaleSupplierData struct {
SerialNumber string `json:"serialNumber"`
PlatformName string `json:"platformName"`
SignCompany int `json:"signCompany"`
PlatformProductName string `json:"platformProductName"`
PlatformPrice float64 `json:"platformPrice"`
TerminalAccount string `json:"terminalAccount"`
Status int `json:"status"`
PlatformProductID int `json:"platformProductId"`
PlatformID int `json:"platformId"`
SignCompanyName string `json:"signCompanyName"`
ExecuteTime int `json:"executeTime"`
AfterSalesReason string `json:"afterSalesReason"`
AfterSalesPrice float64 `json:"afterSalesPrice"`
SerialNumber string `json:"serialNumber"` // 流水号
PlatformName string `json:"platformName"` // 供应商名称
SignCompany int `json:"signCompany"` // 签约主体
PlatformProductName string `json:"platformProductName"` // 商品名称
PlatformPrice float64 `json:"platformPrice"` // 上游价格
TerminalAccount string `json:"terminalAccount"` // 充值账号
Status int `json:"status"` // 充值状态
PlatformProductID int `json:"platformProductId"` // 上有商品id
PlatformID int `json:"platformId"` // 上游平台id
SignCompanyName string `json:"signCompanyName"` // 签约主体名称
ExecuteTime int `json:"executeTime"` // 订单执行时间
Reason string `json:"reason"` // 售后原因
SalePrice float64 `json:"salePrice"` // 售后金额
SaleType int `json:"saleType"` // 处理方式 1.加款 2.扣款
IsExistsAfterSale bool `json:"isExistsAfterSale"` // 是否已存在售后
}
func (t *ZltxOrderAfterSaleSupplierTool) Execute(ctx context.Context, requireData *entitys.RequireData) error {
@ -133,8 +135,10 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu
PlatformID: 1,
SignCompanyName: "测试公司",
ExecuteTime: 1694560000,
AfterSalesReason: "测试售后",
AfterSalesPrice: 50,
Reason: "测试售后",
SalePrice: 50,
SaleType: 1,
IsExistsAfterSale: true,
},
{
SerialNumber: "123457",
@ -148,8 +152,10 @@ func (t *ZltxOrderAfterSaleSupplierTool) checkZltxOrderAfterSaleSupplier(orderNu
PlatformID: 1,
SignCompanyName: "测试公司2",
ExecuteTime: 1694570000,
AfterSalesReason: "测试售后2",
AfterSalesPrice: 30,
Reason: "测试售后2",
SalePrice: 30,
SaleType: 2,
IsExistsAfterSale: false,
},
},
}