Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move schema generation to it's own package inside pkg #83

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading