结构修改
This commit is contained in:
parent
0ce09611de
commit
b81c9ef137
|
@ -223,13 +223,31 @@ func (r *AiRouterService) handleMatch(c *websocket.Conn, matchJson *entitys.Matc
|
|||
switch pointTask.Type {
|
||||
case constant.TaskTypeApi:
|
||||
res, err = r.handleApiTask(c, matchJson, pointTask)
|
||||
case constant.TaskTypeFunc:
|
||||
ctx := context.TODO()
|
||||
res, err = r.handleTask(ctx, matchJson, pointTask)
|
||||
default:
|
||||
return r.handleOtherTask(c, matchJson)
|
||||
}
|
||||
|
||||
fmt.Println(res)
|
||||
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) {
|
||||
|
||||
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 {
|
||||
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)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = mapstructure.Decode(configData.Do, &request)
|
||||
err = mapstructure.Decode(configData.Request, &request)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -13,4 +13,5 @@ type TaskType int32
|
|||
const (
|
||||
TaskTypeApi = 1
|
||||
TaskTypeKnowle = 2
|
||||
TaskTypeFunc = 3
|
||||
)
|
||||
|
|
|
@ -69,9 +69,14 @@ type Tool interface {
|
|||
Execute(ctx context.Context, args json.RawMessage) (interface{}, error)
|
||||
}
|
||||
|
||||
type ConfigData struct {
|
||||
type ConfigDataHttp struct {
|
||||
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 消息
|
||||
|
|
Loading…
Reference in New Issue