Improve handling of JSON Schema in OpenAI API Response Context (#819)

* feat: add jsonschema.Validate and jsonschema.Unmarshal

* fix Sanity check

* remove slices.Contains

* fix Sanity check

* add SchemaWrapper

* update api_integration_test.go

* update method 'reflectSchema' to support 'omitempty' in JSON tag

* add GenerateSchemaForType

* update json_test.go

* update `Warp` to `Wrap`

* fix Sanity check

* fix Sanity check

* update api_internal_test.go

* update README.md

* update README.md

* remove jsonschema.SchemaWrapper

* remove jsonschema.SchemaWrapper

* fix Sanity check

* optimize code formatting
This commit is contained in:
eiixy
2024-08-25 01:06:08 +08:00
committed by GitHub
parent 5162adbbf9
commit a3bd2569ac
7 changed files with 412 additions and 30 deletions

10
chat.go
View File

@@ -5,8 +5,6 @@ import (
"encoding/json"
"errors"
"net/http"
"github.com/sashabaranov/go-openai/jsonschema"
)
// Chat message role defined by the OpenAI API.
@@ -187,10 +185,10 @@ type ChatCompletionResponseFormat struct {
}
type ChatCompletionResponseFormatJSONSchema struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Schema jsonschema.Definition `json:"schema"`
Strict bool `json:"strict"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Schema json.Marshaler `json:"schema"`
Strict bool `json:"strict"`
}
// ChatCompletionRequest represents a request structure for chat completion API.