Compare commits

..

2 Commits

Author SHA1 Message Date
renzhiyuan 7a1662943e 结构修改 2025-09-29 16:01:10 +08:00
renzhiyuan 3910c6e9f8 结构修改 2025-09-29 15:15:34 +08:00
10 changed files with 32 additions and 17 deletions

View File

@ -12,7 +12,7 @@ ollama:
sys: sys:
session_len: 3 session_len: 6
channel_pool_len: 100 channel_pool_len: 100
channel_pool_size: 32 channel_pool_size: 32
llm_pool_len: 5 llm_pool_len: 5

View File

@ -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
} }

View File

@ -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"`

View File

@ -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 是否已经关闭

View File

@ -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, &params); err != nil { if err := json.Unmarshal(args, &params); err != nil {

View File

@ -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 执行多个工具调用

View File

@ -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 {

View File

@ -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)

View File

@ -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)

View File

@ -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