diff --git a/chat.go b/chat.go index 1a8ed46..04a4a12 100644 --- a/chat.go +++ b/chat.go @@ -13,6 +13,7 @@ import ( "time" "github.com/conneroisu/groq-go/pkg/builders" + "github.com/conneroisu/groq-go/pkg/schema" "github.com/conneroisu/groq-go/pkg/tools" ) @@ -102,7 +103,7 @@ type ( Description string `json:"description,omitempty"` // description of the chat completion response format json schema. // Schema is the schema of the chat completion response format json schema. - Schema Schema `json:"schema"` + Schema schema.Schema `json:"schema"` // Strict determines whether to enforce the schema upon the generated // content. Strict bool `json:"strict"` @@ -380,8 +381,10 @@ func (c *Client) CreateChatCompletionJSON( request ChatCompletionRequest, output any, ) (err error) { - r := &reflector{} - schema := r.ReflectFromType(reflect.TypeOf(output)) + schema, err := schema.ReflectSchema(reflect.TypeOf(output)) + if err != nil { + return err + } request.ResponseFormat = &ChatCompletionResponseFormat{} request.ResponseFormat.JSONSchema = &ChatCompletionResponseFormatJSONSchema{ Name: schema.Title, diff --git a/schema.go b/pkg/schema/schema.go similarity index 99% rename from schema.go rename to pkg/schema/schema.go index 4e97dcc..57890ff 100644 --- a/schema.go +++ b/pkg/schema/schema.go @@ -1,4 +1,4 @@ -package groq +package schema import ( "bytes" diff --git a/schema_test.go b/pkg/schema/schema_test.go similarity index 99% rename from schema_test.go rename to pkg/schema/schema_test.go index 8e07fec..2a4c9bc 100644 --- a/schema_test.go +++ b/pkg/schema/schema_test.go @@ -1,4 +1,4 @@ -package groq +package schema import ( "encoding/json" @@ -471,8 +471,16 @@ func TestSchemaGeneration(t *testing.T) { reflector *reflector fixture string }{ - {&TestUser{}, &reflector{}, "testdata/test_user.json"}, - {&UserWithAnchor{}, &reflector{}, "testdata/user_with_anchor.json"}, + { + &TestUser{}, + &reflector{}, + "testdata/test_user.json", + }, + { + &UserWithAnchor{}, + &reflector{}, + "testdata/user_with_anchor.json", + }, { &TestUser{}, &reflector{AssignAnchor: true},