Hey there!
I’m trying to get my schema to accept two different objects within my response.
This is example JSON I’d like to get:
{
"tasks": [
{
"title": "Lolipop",
"type": "candy"
},
{
"title": "Apples",
"type": "fruit",
"taste": "sweet",
"cal": 1000
},
{
"title": "Cucumber",
"type": "vegetable",
"taste": "regular",
"cal": 200
}
]
}
And here is my current scheme:
let jsonSchema: [String: Any] = [
"type": "json_schema",
"json_schema": [
"name": "groceries_schema", // Name of the schema
"schema": [
"type": "object",
"properties": [
"tasks": [
"type": "array",
"items": [
"type": "object",
"properties": [
"title": ["type": "string"],
"type": [
"type": "string",
"enum": ["vegetable", "fruit", "candy"] // Define enum values for type
],
"taste": [
"type": ["string", "null"] // Allow date to be null if not provided
],
"cal": [
"type": ["string", "null"] // Allow time to be null if not provided
]
],
"required": ["title", "type", "cal", "taste"], // Include all properties in required
"additionalProperties": false
]
]
],
"required": ["tasks"], // Require the "tasks" array
"additionalProperties": false
],
"strict": true // Enable strict mode
]
]
This makes the chat response with “cal”: null and “taste”: null, I’m trying to get results without those values if the chat doesn’t have information on those.
I’d love some help here, thank you!