Change function result type from string to any
Updated the return type of functions and related code from `string` to `any` to improve flexibility and support more diverse outputs. Adjusted function implementations, signatures, and handling of results accordingly.
This commit is contained in:
@@ -87,7 +87,7 @@ var (
|
||||
ErrFunctionNotFound = errors.New("function not found")
|
||||
)
|
||||
|
||||
func (t *ToolBox) executeFunction(ctx *Context, functionName string, params string) (string, error) {
|
||||
func (t *ToolBox) executeFunction(ctx *Context, functionName string, params string) (any, error) {
|
||||
f, ok := t.names[functionName]
|
||||
|
||||
if !ok {
|
||||
@@ -97,14 +97,14 @@ func (t *ToolBox) executeFunction(ctx *Context, functionName string, params stri
|
||||
return f.Execute(ctx, params)
|
||||
}
|
||||
|
||||
func (t *ToolBox) Execute(ctx *Context, toolCall ToolCall) (string, error) {
|
||||
func (t *ToolBox) Execute(ctx *Context, toolCall ToolCall) (any, error) {
|
||||
return t.executeFunction(ctx.WithToolCall(&toolCall), toolCall.FunctionCall.Name, toolCall.FunctionCall.Arguments)
|
||||
}
|
||||
|
||||
// ExecuteCallbacks will execute all the tool calls in the given list, and call the given callbacks when a new function is created, and when a function is finished.
|
||||
// OnNewFunction is called when a new function is created
|
||||
// OnFunctionFinished is called when a function is finished
|
||||
func (t *ToolBox) ExecuteCallbacks(ctx *Context, toolCalls []ToolCall, OnNewFunction func(ctx context.Context, funcName string, parameter string) (any, error), OnFunctionFinished func(ctx context.Context, funcName string, parameter string, result string, err error, newFunctionResult any) error) ([]ToolCallResponse, error) {
|
||||
func (t *ToolBox) ExecuteCallbacks(ctx *Context, toolCalls []ToolCall, OnNewFunction func(ctx context.Context, funcName string, parameter string) (any, error), OnFunctionFinished func(ctx context.Context, funcName string, parameter string, result any, err error, newFunctionResult any) error) ([]ToolCallResponse, error) {
|
||||
var res []ToolCallResponse
|
||||
|
||||
for _, call := range toolCalls {
|
||||
|
Reference in New Issue
Block a user