Skip to content

Commit

Permalink
chore: Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith committed Dec 16, 2024
1 parent d01fcae commit 82e16a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 2 additions & 0 deletions sdk-go/inferable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func TestGetSchema(t *testing.T) {
"TestFunc": {
"name": "TestFunc",
"input": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"a": {"type": "integer"},
Expand All @@ -210,6 +211,7 @@ func TestGetSchema(t *testing.T) {
"TestFunc2": {
"name": "TestFunc2",
"input": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"c": {
Expand Down
3 changes: 0 additions & 3 deletions sdk-go/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,9 @@ func TestInferableFunctions(t *testing.T) {
t.Fatalf("Error registering reverse function: %v", err)
}

jsonDef, err := inferableInstance.toJSONDefinition()
if err != nil {
t.Fatalf("Error generating JSON definition: %v", err)
}
t.Logf("JSON Definition:\n%s\n", string(jsonDef))

t.Run("Echo Function", func(t *testing.T) {
testInput := EchoInput{Input: "Hello, Inferable!"}
result, err := inferableInstance.callFunc("string_operations", "echo", testInput)
Expand Down
24 changes: 12 additions & 12 deletions sdk-go/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ func (s *service) RegisterFunc(fn Function) (*FunctionReference, error) {
}
argType := fnType.In(0)

// Set the argument type to the referenced type
if argType.Kind() == reflect.Ptr {
argType = argType.Elem()
}

if argType.Kind() != reflect.Struct {
return nil, fmt.Errorf("function '%s' first argument must be a struct or a pointer to a struct", fn.Name)
}

// Get the schema for the input struct
reflector := jsonschema.Reflector{DoNotReference: true}
schema := reflector.Reflect(reflect.New(argType).Interface())
// Set the argument type to the referenced type
if argType.Kind() == reflect.Ptr {
argType = argType.Elem()
}

if argType.Kind() != reflect.Struct {
return nil, fmt.Errorf("function '%s' first argument must be a struct or a pointer to a struct", fn.Name)
}

// Get the schema for the input struct
reflector := jsonschema.Reflector{DoNotReference: true, Anonymous: true}
schema := reflector.Reflect(reflect.New(argType).Interface())

if schema == nil {
return nil, fmt.Errorf("failed to get schema for function '%s'", fn.Name)
Expand Down

0 comments on commit 82e16a5

Please sign in to comment.