forked from sashabaranov/go-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move json schema to directory/package (sashabaranov#407)
* move json schema to directory/package * added jsonschema to README
- Loading branch information
Showing
4 changed files
with
119 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Package jsonschema provides very simple functionality for representing a JSON schema as a | ||
// (nested) struct. This struct can be used with the chat completion "function call" feature. | ||
// For more complicated schemas, it is recommended to use a dedicated JSON schema library | ||
// and/or pass in the schema in []byte format. | ||
package jsonschema | ||
|
||
type DataType string | ||
|
||
const ( | ||
Object DataType = "object" | ||
Number DataType = "number" | ||
Integer DataType = "integer" | ||
String DataType = "string" | ||
Array DataType = "array" | ||
Null DataType = "null" | ||
Boolean DataType = "boolean" | ||
) | ||
|
||
// Definition is a struct for describing a JSON Schema. | ||
// It is fairly limited and you may have better luck using a third-party library. | ||
type Definition struct { | ||
// Type specifies the data type of the schema. | ||
Type DataType `json:"type,omitempty"` | ||
// Description is the description of the schema. | ||
Description string `json:"description,omitempty"` | ||
// Enum is used to restrict a value to a fixed set of values. It must be an array with at least | ||
// one element, where each element is unique. You will probably only use this with strings. | ||
Enum []string `json:"enum,omitempty"` | ||
// Properties describes the properties of an object, if the schema type is Object. | ||
Properties map[string]Definition `json:"properties,omitempty"` | ||
// Required specifies which properties are required, if the schema type is Object. | ||
Required []string `json:"required,omitempty"` | ||
// Items specifies which data type an array contains, if the schema type is Array. | ||
Items *Definition `json:"items,omitempty"` | ||
} |