Skip to content

Instantly share code, notes, and snippets.

@jcxia43
Last active February 4, 2024 15:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcxia43/6140df1b15950c50668a7117f5579188 to your computer and use it in GitHub Desktop.
Save jcxia43/6140df1b15950c50668a7117f5579188 to your computer and use it in GitHub Desktop.
Add the OpenAI function call schema validation to monaco-editor
// OpenAI function call guide: https://platform.openai.com/docs/guides/gpt/function-calling
// JSON Schema reference: https://json-schema.org/understanding-json-schema/
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
schemas: [
{
uri: "http://myserver/foo-schema.json",
fileMatch: ["*"],
schema: {
$schema: "http://json-schema.org/draft/2020-12/schema",
definitions: {
objectWithProperties: {
type: "object",
properties: {
type: {
type: "string",
enum: [
"array",
"boolean",
"integer",
"null",
"number",
"object",
"string",
],
},
name: {
type: "string",
},
description: {
type: "string",
},
parameters: {
type: "object",
required: ["type", "required", "properties"],
properties: {
type: {
type: "string",
enum: ["object"],
},
required: {
type: "array",
items: {
type: "string",
},
},
properties: {
$ref: "#/definitions/propertiesObject",
},
},
additionalProperties: false,
},
enum: {
type: "array",
items: {
type: "string",
},
},
items: {
oneOf: [
{
$ref: "#/definitions/objectWithProperties",
},
{
type: "string",
},
],
},
required: {
type: "array",
items: {
type: "string",
},
},
properties: {
$ref: "#/definitions/propertiesObject",
},
$ref: {
type: "string",
},
},
additionalProperties: false,
},
propertiesObject: {
type: "object",
patternProperties: {
".*": {
$ref: "#/definitions/objectWithProperties",
},
},
additionalProperties: false,
},
},
type: "object",
required: ["name", "description", "parameters"],
properties: {
name: {
type: "string",
},
description: {
type: "string",
},
parameters: {
type: "object",
required: ["type", "required", "properties"],
properties: {
type: {
type: "string",
enum: ["object"],
},
required: {
type: "array",
items: {
type: "string",
},
},
properties: {
$ref: "#/definitions/propertiesObject",
},
},
additionalProperties: false,
},
},
additionalProperties: false,
},
},
],
})
@jeremyfiel
Copy link

"$schema": "https://json-schema.org/draft/2020-12/schema"
"$defs": {}

The $schema property is incorrectly defined as http prefix and definitions was deprecated in favor of $defs in JSON Schema 2020-12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment