feat: Support Structured Outputs (#813)
* feat: Support Structured Outputs * feat: Support Structured Outputs * update imports * add integration test * update JSON schema comments
This commit is contained in:
13
chat.go
13
chat.go
@@ -5,6 +5,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
)
|
||||
|
||||
// Chat message role defined by the OpenAI API.
|
||||
@@ -175,11 +177,20 @@ type ChatCompletionResponseFormatType string
|
||||
|
||||
const (
|
||||
ChatCompletionResponseFormatTypeJSONObject ChatCompletionResponseFormatType = "json_object"
|
||||
ChatCompletionResponseFormatTypeJSONSchema ChatCompletionResponseFormatType = "json_schema"
|
||||
ChatCompletionResponseFormatTypeText ChatCompletionResponseFormatType = "text"
|
||||
)
|
||||
|
||||
type ChatCompletionResponseFormat struct {
|
||||
Type ChatCompletionResponseFormatType `json:"type,omitempty"`
|
||||
Type ChatCompletionResponseFormatType `json:"type,omitempty"`
|
||||
JSONSchema ChatCompletionResponseFormatJSONSchema `json:"json_schema,omitempty"`
|
||||
}
|
||||
|
||||
type ChatCompletionResponseFormatJSONSchema struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Schema jsonschema.Definition `json:"schema"`
|
||||
Strict bool `json:"strict"`
|
||||
}
|
||||
|
||||
// ChatCompletionRequest represents a request structure for chat completion API.
|
||||
|
||||
Reference in New Issue
Block a user