You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Structured outputs use JSON schemas to enforce output structure. JSON schemas describe the shape of the JSON object including expected values, types, and which ones are required. ThoseJSON objects are encoded as a string within the response of the model.
32
+
33
+
### Example
34
+
35
+
To exemplify the scenario, let's try to parse the attributes of a GitHub Issue from its description.
'<!--\r\nIF SUFFICIENT INFORMATION IS NOT PROVIDED VIA THE FOLLOWING TEMPLATE THE ISSUE MIGHT BE CLOSED WITHOUT FURTHER CONSIDERATION OR INVESTIGATION\r\n-->\r\n> Please provide us with the following information:\r\n> ---------------------------------------------------------------\r\n\r\n### This issue is for a: (mark with an `x`)\r\n```\r\n- [x] bug report -> please search issues before submitting\r\n- [ ] feature request\r\n- [ ] documentation issue or request\r\n- [ ] regression (a behavior that used to work and stopped in a new release)\r\n```\r\n\r\n### Minimal steps to reproduce\r\n> Deploy the app with auth and acl´s turned on, configure the acls file, run all the scripts needed.\r\n\r\n### Any log messages given by the failure\r\n> None\r\n\r\n### Expected/desired behavior\r\n> groups field to be filled the the groups id\'s that have permissions to "view the file"\r\n\r\n### OS and Version?\r\n> win 10\r\n### azd version?\r\n> azd version 1.11.0\r\n\r\n### Versions\r\n>\r\n\r\n### Mention any other details that might be useful\r\n\r\nAfter configuring the json with the perms all the scripts (`adlsgen2setup.py` and `prepdocs.ps1`) everything goes well but the groups metadata tag never gets to have any groups.\r\n\r\n\r\n\r\n\r\n> ---------------------------------------------------------------\r\n> Thanks! We\'ll be in touch soon.\r\n'
59
+
```
60
+
61
+
### Define the schema
62
+
63
+
The following JSON schema defines the schema of a GitHub issue:
"title": "Metadata tags issue on access control lists - ADLSgen2 setup",
162
+
"description": "Our project seems to have an issue with the metadata tag for groups when deploying the application with access control lists and necessary settings.",
163
+
"type": "Bug",
164
+
"operating_system": "Windows 10"
165
+
}
166
+
```
167
+
168
+
## Structured outputs in images
169
+
170
+
You can use structured outputs with multi-modal models to extract information from data like images.
171
+
172
+
Let's consider the following chart:
173
+
174
+
:::image type="content" source="../../media/use-structured-outputs/example_graph_treecover.png" alt-text="An example image showing a chart with the annual loss in thousand square kilometers of global tree cover across different climate zones." lightbox="../../media/use-structured-outputs/example_graph_treecover.png":::
175
+
176
+
We can define a generic schema that can be used to encode the information contained in the chart and then use it for further analysis.
177
+
178
+
__graph_schema.json__
179
+
180
+
```json
181
+
{
182
+
"$defs": {
183
+
"DataPoint": {
184
+
"properties": {
185
+
"x": {
186
+
"title": "X",
187
+
"type": "number"
188
+
},
189
+
"y": {
190
+
"title": "Y",
191
+
"type": "number"
192
+
},
193
+
"serie": {
194
+
"title": "Serie",
195
+
"type": "string"
196
+
}
197
+
},
198
+
"required": [
199
+
"x",
200
+
"y",
201
+
"serie"
202
+
],
203
+
"title": "DataPoint",
204
+
"type": "object"
205
+
}
206
+
},
207
+
"title": "Graph",
208
+
"type": "object",
209
+
"properties": {
210
+
"title": {
211
+
"title": "Title",
212
+
"type": "string"
213
+
},
214
+
"description": {
215
+
"title": "Description",
216
+
"type": "string"
217
+
},
218
+
"x_axis": {
219
+
"title": "X Axis",
220
+
"type": "string"
221
+
},
222
+
"y_axis": {
223
+
"title": "Y Axis",
224
+
"type": "string"
225
+
},
226
+
"legend": {
227
+
"items": {
228
+
"type": "string"
229
+
},
230
+
"title": "Legend",
231
+
"type": "array"
232
+
},
233
+
"data": {
234
+
"items": {
235
+
"$ref": "#/$defs/DataPoint"
236
+
},
237
+
"title": "Data",
238
+
"type": "array"
239
+
}
240
+
},
241
+
"required": [
242
+
"title",
243
+
"description",
244
+
"x_axis",
245
+
"y_axis",
246
+
"legend",
247
+
"data"
248
+
],
249
+
"additionalProperties": false
250
+
}
251
+
```
252
+
253
+
Let's load this schema:
254
+
255
+
```javascript
256
+
const fs = require('fs');
257
+
258
+
const data = fs.readFileSync('./graph_schema.json', 'utf-8');
259
+
const graphSchema = JSON.parse(data);```
260
+
```
261
+
262
+
We can load the image as follows to pass it to the model:
263
+
264
+
```javascript
265
+
/**
266
+
* Get the data URL of an image file.
267
+
* @param {string} imageFile - The path to the image file.
268
+
* @param {string} imageFormatType - The format of the image file. For example: "jpeg", "png".
269
+
* @returns {string} The data URL of the image.
270
+
*/
271
+
function getImageDataUrl(imageFile, imageFormatType) {
"description": "Annual loss in thousand square kilometers of global tree cover across different climate zones.",
338
+
"x_axis": "Year",
339
+
"y_axis": "Thousand square kilometers",
340
+
"legend": [
341
+
"Boreal",
342
+
"Temperate",
343
+
"Subtropical",
344
+
"Tropical"
345
+
],
346
+
"data": [
347
+
{
348
+
"x": 2001,
349
+
"y": -35,
350
+
"serie": "Boreal"
351
+
},
352
+
{
353
+
"x": 2001,
354
+
"y": -10,
355
+
"serie": "Temperate"
356
+
},
357
+
{
358
+
"x": 2001,
359
+
"y": -55,
360
+
...
361
+
"serie": "Tropical"
362
+
}
363
+
]
364
+
}
365
+
```
366
+
367
+
To see how much information the model was able to capture, we can try to plot the data:
368
+
369
+
:::image type="content" source="../../media/use-structured-outputs/graph_treecover_plot.png" alt-text="The resulting plot of the data contained in the structured output generated by the model." lightbox="../../media/use-structured-outputs/graph_treecover_plot.png":::
370
+
371
+
While the information isn't perfect, we can see the model was able to capture a good amount of information from the original chart.
0 commit comments