Skip to content

Commit

Permalink
Move schema generation to it's own package inside pkg (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
conneroisu authored Oct 26, 2024
2 parents 258ed24 + df70722 commit 8e0b071
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ jobs:
run: |
go test -race -tags=integration ./...
- name: Run Unit tests
env:
GROQ_KEY: ${{ secrets.GROQ_KEY }}
TOOLHOUSE_API_KEY: ${{ secrets.TOOLHOUSE_API_KEY }}
E2B_API_KEY: ${{ secrets.E2B_API_KEY }}
UNIT: true
run: |
go test -race -covermode atomic -coverprofile=covprofile ./...
- name: Install goveralls
Expand Down
9 changes: 6 additions & 3 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion schema.go → pkg/schema/schema.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package groq
package schema

import (
"bytes"
Expand Down
14 changes: 11 additions & 3 deletions schema_test.go → pkg/schema/schema_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package groq
package schema

import (
"encoding/json"
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 8e0b071

Please sign in to comment.