结构修改
This commit is contained in:
parent
3910c6e9f8
commit
7a1662943e
|
@ -198,7 +198,8 @@ func (r *AiRouterBiz) RouteWithSocket(c *websocket.Conn, req *entitys.ChatSockRe
|
||||||
log.Info(resMsg)
|
log.Info(resMsg)
|
||||||
return errors.SysErr("数据结构错误:%v", err.Error())
|
return errors.SysErr("数据结构错误:%v", err.Error())
|
||||||
}
|
}
|
||||||
|
matchJson.History = pkg.JsonByteIgonErr(history)
|
||||||
|
matchJson.UserInput = req.Text
|
||||||
if err := r.handleMatch(ctx, c, ch, &matchJson, task, sysInfo); err != nil {
|
if err := r.handleMatch(ctx, c, ch, &matchJson, task, sysInfo); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -268,13 +269,13 @@ func (r *AiRouterBiz) handleMatch(ctx context.Context, c *websocket.Conn, ch cha
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AiRouterBiz) handleTask(channel chan entitys.Response, c *websocket.Conn, matchJson *entitys.Match, task *model.AiTask) (err error) {
|
func (r *AiRouterBiz) handleTask(channel chan entitys.Response, c *websocket.Conn, matchJson *entitys.Match, task *model.AiTask) (err error) {
|
||||||
|
|
||||||
var configData entitys.ConfigDataTool
|
var configData entitys.ConfigDataTool
|
||||||
err = json.Unmarshal([]byte(task.Config), &configData)
|
err = json.Unmarshal([]byte(task.Config), &configData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = r.toolManager.ExecuteTool(channel, c, configData.Tool, []byte(matchJson.Parameters))
|
|
||||||
|
err = r.toolManager.ExecuteTool(channel, c, configData.Tool, []byte(matchJson.Parameters), matchJson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -358,7 +359,7 @@ func (r *AiRouterBiz) handleKnowle(channel chan entitys.Response, c *websocket.C
|
||||||
}
|
}
|
||||||
|
|
||||||
// 执行工具
|
// 执行工具
|
||||||
err = r.toolManager.ExecuteTool(channel, c, configData.Tool, b)
|
err = r.toolManager.ExecuteTool(channel, c, configData.Tool, b, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ type Tool interface {
|
||||||
Name() string
|
Name() string
|
||||||
Description() string
|
Description() string
|
||||||
Definition() ToolDefinition
|
Definition() ToolDefinition
|
||||||
Execute(channel chan Response, c *websocket.Conn, args json.RawMessage) error
|
Execute(channel chan Response, c *websocket.Conn, args json.RawMessage, matchJson *Match) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigDataHttp struct {
|
type ConfigDataHttp struct {
|
||||||
|
@ -116,6 +116,8 @@ type Match struct {
|
||||||
IsMatch bool `json:"is_match"`
|
IsMatch bool `json:"is_match"`
|
||||||
Parameters string `json:"parameters"`
|
Parameters string `json:"parameters"`
|
||||||
Reasoning string `json:"reasoning"`
|
Reasoning string `json:"reasoning"`
|
||||||
|
History []byte `json:"history"`
|
||||||
|
UserInput string `json:"user_input"`
|
||||||
}
|
}
|
||||||
type ChatHis struct {
|
type ChatHis struct {
|
||||||
SessionId string `json:"session_id"`
|
SessionId string `json:"session_id"`
|
||||||
|
|
|
@ -6,8 +6,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func JsonStringIgonErr(data interface{}) string {
|
func JsonStringIgonErr(data interface{}) string {
|
||||||
|
return string(JsonByteIgonErr(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
func JsonByteIgonErr(data interface{}) []byte {
|
||||||
dataByte, _ := json.Marshal(data)
|
dataByte, _ := json.Marshal(data)
|
||||||
return string(dataByte)
|
return dataByte
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsChannelClosed 检查给定的 channel 是否已经关闭
|
// IsChannelClosed 检查给定的 channel 是否已经关闭
|
||||||
|
|
|
@ -60,7 +60,7 @@ func (k *KnowledgeBaseTool) Definition() entitys.ToolDefinition {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute 执行知识库查询
|
// Execute 执行知识库查询
|
||||||
func (k *KnowledgeBaseTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage) error {
|
func (k *KnowledgeBaseTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage, matchJson *entitys.Match) error {
|
||||||
|
|
||||||
var params KnowledgeBaseRequest
|
var params KnowledgeBaseRequest
|
||||||
if err := json.Unmarshal(args, ¶ms); err != nil {
|
if err := json.Unmarshal(args, ¶ms); err != nil {
|
||||||
|
|
|
@ -100,13 +100,13 @@ func (m *Manager) GetToolDefinitions(caller constants.Caller) []entitys.ToolDefi
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecuteTool 执行工具
|
// ExecuteTool 执行工具
|
||||||
func (m *Manager) ExecuteTool(channel chan entitys.Response, c *websocket.Conn, name string, args json.RawMessage) error {
|
func (m *Manager) ExecuteTool(channel chan entitys.Response, c *websocket.Conn, name string, args json.RawMessage, matchJson *entitys.Match) error {
|
||||||
tool, exists := m.GetTool(name)
|
tool, exists := m.GetTool(name)
|
||||||
if !exists {
|
if !exists {
|
||||||
return fmt.Errorf("tool not found: %s", name)
|
return fmt.Errorf("tool not found: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tool.Execute(channel, c, args)
|
return tool.Execute(channel, c, args, matchJson)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecuteToolCalls 执行多个工具调用
|
// ExecuteToolCalls 执行多个工具调用
|
||||||
|
|
|
@ -81,7 +81,7 @@ type ZltxOrderDetailData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute 执行直连天下订单详情查询
|
// Execute 执行直连天下订单详情查询
|
||||||
func (w *ZltxOrderDetailTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage) error {
|
func (w *ZltxOrderDetailTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage, matchJson *entitys.Match) error {
|
||||||
var req ZltxOrderDetailRequest
|
var req ZltxOrderDetailRequest
|
||||||
if err := json.Unmarshal(args, &req); err != nil {
|
if err := json.Unmarshal(args, &req); err != nil {
|
||||||
return fmt.Errorf("invalid zltxOrderDetail request: %w", err)
|
return fmt.Errorf("invalid zltxOrderDetail request: %w", err)
|
||||||
|
@ -92,11 +92,11 @@ func (w *ZltxOrderDetailTool) Execute(channel chan entitys.Response, c *websocke
|
||||||
}
|
}
|
||||||
|
|
||||||
// 这里可以集成真实的直连天下订单详情API
|
// 这里可以集成真实的直连天下订单详情API
|
||||||
return w.getZltxOrderDetail(channel, c, req.OrderNumber)
|
return w.getZltxOrderDetail(channel, c, req.OrderNumber, matchJson)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getMockZltxOrderDetail 获取模拟直连天下订单详情数据
|
// getMockZltxOrderDetail 获取模拟直连天下订单详情数据
|
||||||
func (w *ZltxOrderDetailTool) getZltxOrderDetail(ch chan entitys.Response, c *websocket.Conn, number string) (err error) {
|
func (w *ZltxOrderDetailTool) getZltxOrderDetail(ch chan entitys.Response, c *websocket.Conn, number string, matchJson *entitys.Match) (err error) {
|
||||||
//查询订单详情
|
//查询订单详情
|
||||||
var auth string
|
var auth string
|
||||||
if c != nil {
|
if c != nil {
|
||||||
|
@ -169,9 +169,17 @@ func (w *ZltxOrderDetailTool) getZltxOrderDetail(ch chan entitys.Response, c *we
|
||||||
Role: "system",
|
Role: "system",
|
||||||
Content: "你是一个订单日志助手。用户可能会提供订单日志,你需要分析订单日志,提取出订单失败的原因。",
|
Content: "你是一个订单日志助手。用户可能会提供订单日志,你需要分析订单日志,提取出订单失败的原因。",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Role: "assistant",
|
||||||
|
Content: fmt.Sprintf("聊天记录:%s", string(matchJson.History)),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Role: "assistant",
|
||||||
|
Content: fmt.Sprintf("需要分析的订单日志:%s", string(dataJson)),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Role: "user",
|
Role: "user",
|
||||||
Content: fmt.Sprintf("订单日志:%s", string(dataJson)),
|
Content: matchJson.UserInput,
|
||||||
},
|
},
|
||||||
}, w.Name())
|
}, w.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -67,7 +67,7 @@ type ZltxOrderDirectLogData struct {
|
||||||
Data map[string]interface{} `json:"data"`
|
Data map[string]interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ZltxOrderLogTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage) error {
|
func (t *ZltxOrderLogTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage, matchJson *entitys.Match) error {
|
||||||
var req ZltxOrderLogRequest
|
var req ZltxOrderLogRequest
|
||||||
if err := json.Unmarshal(args, &req); err != nil {
|
if err := json.Unmarshal(args, &req); err != nil {
|
||||||
return fmt.Errorf("invalid zltxOrderLog request: %w", err)
|
return fmt.Errorf("invalid zltxOrderLog request: %w", err)
|
||||||
|
|
|
@ -53,7 +53,7 @@ type ZltxProductRequest struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z ZltxProductTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage) error {
|
func (z ZltxProductTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage, matchJson *entitys.Match) error {
|
||||||
var req ZltxProductRequest
|
var req ZltxProductRequest
|
||||||
if err := json.Unmarshal(args, &req); err != nil {
|
if err := json.Unmarshal(args, &req); err != nil {
|
||||||
return fmt.Errorf("invalid zltxProduct request: %w", err)
|
return fmt.Errorf("invalid zltxProduct request: %w", err)
|
||||||
|
|
|
@ -46,7 +46,7 @@ type ZltxOrderStatisticsRequest struct {
|
||||||
Number string `json:"number"`
|
Number string `json:"number"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z ZltxOrderStatisticsTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage) error {
|
func (z ZltxOrderStatisticsTool) Execute(channel chan entitys.Response, c *websocket.Conn, args json.RawMessage, matchJson *entitys.Match) error {
|
||||||
var req ZltxOrderStatisticsRequest
|
var req ZltxOrderStatisticsRequest
|
||||||
if err := json.Unmarshal(args, &req); err != nil {
|
if err := json.Unmarshal(args, &req); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue