import Datagrid from "datagrid-ai";
const datagrid = new Datagrid();
const movieJsonSchema = {
type: "object",
properties: {
name: {
type: "string",
description: "The name of the movie",
},
director: {
type: "string",
description: "The director of the movie",
},
release_year: {
type: "number",
description: "The year the movie was released",
},
},
required: ["name", "director", "release_year"],
additionalProperties: false,
};
const response = await datagrid.converse({
prompt: "What movie won best picture at the 2001 Oscars?",
text: { format: movieJsonSchema },
});
// Structured output is returned as a `json` content item (already parsed).
const jsonPart = response.content.find((part) => part.type === "json");
const structuredResponse = jsonPart?.json;
// => { name: "Gladiator", director: "Ridley Scott", release_year: 2000 }