- Javascript (zod) and Python (pydantic) LLM apis use their data class libraries to describe structured outputs for LLMs. example
dart_mappable has full awareness of the field structure during runtime which is required for this example
- there is a protocol for structured output (it's
json_schema) (see details)
Details
curl https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-2024-08-06",
"messages": [
{
"role": "system",
"content": "You are a helpful math tutor. Guide the user through the solution step by step."
},
{
"role": "user",
"content": "how can I solve 8x + 7 = -23"
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "math_response",
"schema": {
"type": "object",
"properties": {
"steps": {
"type": "array",
"items": {
"type": "object",
"properties": {
"explanation": { "type": "string" },
"output": { "type": "string" }
},
"required": ["explanation", "output"],
"additionalProperties": false
}
},
"final_answer": { "type": "string" }
},
"required": ["steps", "final_answer"],
"additionalProperties": false
},
"strict": true
}
}
}'
TODO
Why we should care
this would make dart the third language to have data classes that drive LLM responses as a first class feature
dart_mappablehas full awareness of the field structure during runtime which is required for this examplejson_schema) (see details)Details
TODO
Why we should care
this would make dart the third language to have data classes that drive LLM responses as a first class feature