from datagrid_ai import Datagrid
import json
datagrid = Datagrid()
example_json_schema = {
"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
}
response = datagrid.converse(
prompt="What movie won best picture at the 2001 Oscars?",
text={"format": example_json_schema}
)
# Example response: '{ "name": "Gladiator", "director": "Ridley Scott", "release_year": 2000 }'
structured_response = json.loads(response["content"][0]["text"])