<?php
require 'examples/boot.php';
require_once 'examples/_support/eventlog_readback.php';
use Cognesy\Instructor\StructuredOutput;
use Cognesy\Instructor\StructuredOutputRuntime;
use Cognesy\Logging\EventLog;
use Cognesy\Polyglot\Inference\LLMProvider;
final class IncidentSummary
{
public string $severity;
public string $summary;
}
$logPath = ExampleEventLog::path('examples-a03-structured-output-eventlog');
EventLog::enable($logPath);
try {
$runtime = StructuredOutputRuntime::fromProvider(LLMProvider::using('openai'));
$incident = (new StructuredOutput($runtime))
->with(
messages: 'Customer report: checkout returns HTTP 500 after payment. Mark severity and summarize it in one sentence.',
responseModel: IncidentSummary::class,
)
->get();
$entries = ExampleEventLog::read($logPath);
} finally {
EventLog::disable();
}
echo "=== StructuredOutput Result ===\n";
echo "Severity: {$incident->severity}\n";
echo "Summary: {$incident->summary}\n";
echo "\n=== EventLog Entries ===\n";
echo "Log file: {$logPath}\n";
echo 'Entries captured: ' . count($entries) . "\n\n";
ExampleEventLog::print($entries, 8);
assert($incident->severity !== '');
assert($incident->summary !== '');
assert($entries !== []);
?>