<?php
use Cognesy\Polyglot\Inference\Inference;
use Cognesy\Polyglot\Inference\Enums\OutputMode;
$inference = new Inference();
// Include expected format in the prompt
$prompt = <<<EOT
List three programming languages with their key features.
Respond with a JSON object following this structure:
{
"languages": [
{
"name": "Language name",
"paradigm": "Programming paradigm",
"year_created": year as number,
"key_features": ["feature1", "feature2", "feature3"]
},
]
}
EOT;
$response = $inference->with(
messages: $prompt,
mode: OutputMode::MdJson
)->toJson();
// Process as normal JSON
// @doctest id="6768"