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 },
});
// Example response: "{ "name": "Gladiator", "director": "Ridley Scott", "release_year": 2000 }"
const structuredResponse = JSON.parse(response.content[0].text);