Last active
July 18, 2024 17:54
-
-
Save jcxia43/6140df1b15950c50668a7117f5579188 to your computer and use it in GitHub Desktop.
Add the OpenAI function call schema validation to monaco-editor
This file contains hidden or 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
| // 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, | |
| }, | |
| }, | |
| ], | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
$schemaproperty is incorrectly defined ashttpprefix anddefinitionswas deprecated in favor of$defsin JSON Schema 2020-12.