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:
2025-03-25 23:53:09 -04:00
parent 5ba42056ad
commit 82feb7d8b4
4 changed files with 18 additions and 14 deletions

View File

@@ -4,11 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"gitea.stevedudenhoeffer.com/steve/go-llm/schema"
"github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/jsonschema"
"reflect"
"time"
"github.com/sashabaranov/go-openai"
"github.com/sashabaranov/go-openai/jsonschema"
"gitea.stevedudenhoeffer.com/steve/go-llm/schema"
)
type Function struct {
@@ -31,7 +33,7 @@ type Function struct {
definition *jsonschema.Definition
}
func (f *Function) Execute(ctx *Context, input string) (string, error) {
func (f *Function) Execute(ctx *Context, input string) (any, error) {
if !f.fn.IsValid() {
return "", fmt.Errorf("function %s is not implemented", f.Name)
}
@@ -46,7 +48,7 @@ func (f *Function) Execute(ctx *Context, input string) (string, error) {
}
// now we can call the function
exec := func(ctx *Context) (string, error) {
exec := func(ctx *Context) (any, error) {
out := f.fn.Call([]reflect.Value{reflect.ValueOf(ctx), p.Elem()})
if len(out) != 2 {
@@ -54,7 +56,7 @@ func (f *Function) Execute(ctx *Context, input string) (string, error) {
}
if out[1].IsNil() {
return out[0].String(), nil
return out[0].Interface(), nil
}
return "", out[1].Interface().(error)