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:
14
function.go
14
function.go
@@ -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)
|
||||
|
Reference in New Issue
Block a user