fix: Update Assistant API to handle arguments and improve error logging

- Modify APIPayload structure to include Args field for passing arguments.
- Enhance error handling in Call method by adding logging for method not found scenarios.
- Adjust Call method to handle cases with and without arguments, ensuring flexibility in API usage.
This commit is contained in:
Max 2025-04-03 14:36:39 +08:00
parent af002aa396
commit 46b0947dfd
2 changed files with 9 additions and 4 deletions

View file

@ -306,10 +306,15 @@ func (ast *Assistant) Call(c *gin.Context, payload APIPayload) (interface{}, err
// Check if the method exists
if !scriptCtx.Global().Has(method) {
color.Red("Assistant Call: %s Method %s not found", ast.ID, method)
return nil, fmt.Errorf(HookErrorMethodNotFound)
}
return scriptCtx.CallWith(ctx, method, payload.Payload)
if payload.Args == nil || len(payload.Args) == 0 {
return scriptCtx.CallWith(ctx, method)
}
return scriptCtx.CallWith(ctx, method, payload.Args...)
}
// handleChatStream manages the streaming chat interaction with the AI

View file

@ -32,9 +32,9 @@ type API interface {
// APIPayload the API payload
type APIPayload struct {
Sid string `json:"sid"`
Name string `json:"name"`
Payload map[string]interface{} `json:"payload"`
Sid string `json:"sid"`
Name string `json:"name"`
Args []interface{} `json:"args,omitempty"`
}
// ResHookInit the response of the init hook