结构修改

This commit is contained in:
renzhiyuan 2025-09-22 11:03:40 +08:00
parent 0ce09611de
commit b81c9ef137
3 changed files with 29 additions and 5 deletions

View File

@ -223,13 +223,31 @@ func (r *AiRouterService) handleMatch(c *websocket.Conn, matchJson *entitys.Matc
switch pointTask.Type { switch pointTask.Type {
case constant.TaskTypeApi: case constant.TaskTypeApi:
res, err = r.handleApiTask(c, matchJson, pointTask) res, err = r.handleApiTask(c, matchJson, pointTask)
case constant.TaskTypeFunc:
ctx := context.TODO()
res, err = r.handleTask(ctx, matchJson, pointTask)
default: default:
return r.handleOtherTask(c, matchJson) return r.handleOtherTask(c, matchJson)
} }
fmt.Println(res)
return return
} }
func (r *AiRouterService) handleTask(c context.Context, matchJson *entitys.Match, task *model.AiTask) (res []byte, err error) {
var configData entitys.ConfigDataTool
err = json.Unmarshal([]byte(task.Config), &configData)
if err != nil {
return
}
resInterface, err := r.toolManager.ExecuteTool(c, configData.Tool, []byte(matchJson.Parameters))
if err != nil {
return nil, err
}
return json.Marshal(resInterface)
}
func (r *AiRouterService) handleOtherTask(c *websocket.Conn, matchJson *entitys.Match) (err error) { func (r *AiRouterService) handleOtherTask(c *websocket.Conn, matchJson *entitys.Match) (err error) {
c.WriteMessage(1, []byte(matchJson.Reasoning)) c.WriteMessage(1, []byte(matchJson.Reasoning))
@ -251,12 +269,12 @@ func (r *AiRouterService) handleApiTask(c *websocket.Conn, matchJson *entitys.Ma
for k, v := range requestParam { for k, v := range requestParam {
task.Config = strings.ReplaceAll(task.Config, "${"+k+"}", fmt.Sprintf("%v", v)) task.Config = strings.ReplaceAll(task.Config, "${"+k+"}", fmt.Sprintf("%v", v))
} }
var configData entitys.ConfigData var configData entitys.ConfigDataHttp
err = json.Unmarshal([]byte(task.Config), &configData) err = json.Unmarshal([]byte(task.Config), &configData)
if err != nil { if err != nil {
return return
} }
err = mapstructure.Decode(configData.Do, &request) err = mapstructure.Decode(configData.Request, &request)
if err != nil { if err != nil {
return return
} }

View File

@ -13,4 +13,5 @@ type TaskType int32
const ( const (
TaskTypeApi = 1 TaskTypeApi = 1
TaskTypeKnowle = 2 TaskTypeKnowle = 2
TaskTypeFunc = 3
) )

View File

@ -69,9 +69,14 @@ type Tool interface {
Execute(ctx context.Context, args json.RawMessage) (interface{}, error) Execute(ctx context.Context, args json.RawMessage) (interface{}, error)
} }
type ConfigData struct { type ConfigDataHttp struct {
Param map[string]interface{} `json:"param"` Param map[string]interface{} `json:"param"`
Do map[string]interface{} `json:"do"` Request map[string]interface{} `json:"request"`
}
type ConfigDataTool struct {
Param map[string]interface{} `json:"param"`
Tool string `json:"tool"`
} }
// Message 消息 // Message 消息