Documentation
¶
Overview ¶
Package schema holds what is done to a JSON schema before a model is sent it, the one place of the tools host for it: the repair of values no provider takes, the sanitizing of every tool's parameters that the one assembly runs, the subsets one provider takes, and the keys a sanitized schema renamed, which a call of the tool is read back through
Index ¶
- func Check(schema map[string]any) error
- func CollapseConstUnions(schema any) any
- func Definitions(tools []map[string]any) ([]map[string]any, map[string]string)
- func Fit(schema map[string]any) map[string]any
- func FitTools(tools []map[string]any) ([]map[string]any, bool)
- func Fitting(schema map[string]any) (map[string]any, bool)
- func Gemini(schema any) map[string]any
- func Inlined(parameters map[string]any) map[string]any
- func Key(key string) string
- func Misfit(schema map[string]any, value any) string
- func Plain(schema map[string]any) (map[string]any, bool)
- func Renames(properties any) map[string]string
- func Sanitize(parameters any) map[string]any
- func Slashless(schema map[string]any) (map[string]any, bool)
- func StripNullableUnions(schema any, keepNullableHint bool) any
- type Made
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Why the schema is no valid JSON schema, nil when it is one: compiled as the latest draft reads it, nothing loaded from elsewhere
func CollapseConstUnions ¶
Unions of constants of one type made an enum of them, the input left as it was: one null branch makes it nullable
func Definitions ¶
What the model is sent of the tools in the OpenAI shape, each tool's parameters as Make makes them: the list itself when every tool already was, else a copy holding each tool that was as the very map it is; and the tools whose schema could not be made valid, by name with why
func Fit ¶
JSON schema in a form every provider takes: the schema itself when it already was, else a copy, the schema given left as it was, so one shared between requests is never written to. No keyword whose value must be a list or an object holds null or a value of another kind at any depth. A required of null requires nothing, an enum of null or of nothing constrains nothing and goes, an entry of a union that is no schema goes, and a union of none goes. A schema of null where one must be is the empty schema, which takes anything, for a property, a definition, a place in a list or the items of a list, and goes elsewhere; properties of null are none. A word, number or flag of null goes. What a schema holds as data, such as a default, a const or the values of an enum, and keywords it does not know are left as they are
func FitTools ¶
Tools in the OpenAI shape with the parameters of each function in a form every provider takes, as Fit makes them, and a description of null left out: the list itself when every tool already was, else a copy holding each tool that was as the very map it is; and whether any needed it
func Gemini ¶
Schema kept to the subset Gemini's parameters field takes, its type unions as anyOf branches with their own constraints, enums of numbers and booleans as text, required naming only properties it has; read as JSON reads it back, so a list of any Go type, such as an enum of integers a tool builds, is seen as the list it is
func Inlined ¶
Full JSON schema with its $schema dropped, its local refs put in place and an object at its root, as Gemini's parametersJsonSchema and responseJsonSchema take it; kept as it is, but for $schema, when a ref can't be put in place
func Key ¶
Property key as every provider takes it: each character outside letters, digits, underscore, dot and dash made an underscore, cut to 64, param when nothing is left
func Misfit ¶
Why a value does not fit a schema, in words a person reads, such as "steps is 80, more than the most, 50"; empty when it fits. A schema that does not compile fits nothing, which Check says on its own
func Plain ¶
A copy of a schema without the keywords a grammar can't take at any depth, and whether it held any: what is sent again to a llama.cpp server that refused a schema it could not turn into a grammar, and always to xAI's Responses API; the schema given left as it was
func Renames ¶
Renames the sanitizer makes of the keys of a properties map, each key it renames by the key it is sent as: keys taken in sorted order, a key that clashes with one taken given _2, _3 and on, cut to stay within 64; the rule a call of the tool is read back through
func Sanitize ¶
Parameters of a tool as alpha's sanitizer sends them: a copy, the parameters given left as they are. Property keys every provider takes, with suffixes where two clash and required following them; a bare type name where a schema belongs made the schema of that type, and any other text the empty object; a list of types made one type, or an anyOf of one type each, null making it nullable; a property that says it is required with a flag of its own, as JSON schema's third draft did, named in its object's required; an object given its properties and a required naming only those; then at the top an object with properties and required, a union of one branch and null collapsed into that branch marked nullable, the combinators strict providers refuse there dropped, and default beside $ref dropped everywhere. What a schema holds as data, such as a const, a default, an example or the values of an enum, is left as it is
func Slashless ¶
A copy of a schema without each enum one of whose values holds a slash at any depth, which xAI's Responses API fails to compile into a grammar, and whether it held any; the schema given left as it was
func StripNullableUnions ¶
Each anyOf or oneOf of one branch and null collapsed into that branch, marked nullable when asked, the union's metadata carried over
Types ¶
type Made ¶
Parameters of a tool as the model is sent them, and why they could not be made valid, empty when they could
func Make ¶
Parameters of a tool made what the model is sent, the one pass every tool's schema goes through whoever registered the tool: fitted, unions of constants made enums, legacy definitions moved to $defs, sanitized as Sanitize does, references that can't be followed taken out, then checked with nothing fetched from outside. One that does not check is sent without its patterns and formats when that checks, else as an object of any properties, with why