Skip to content

Commit 3b936f2

Browse files
committed
feature #876 [Platform] Unify options key for structured output to response_format (chr-hertel)
This PR was merged into the main branch. Discussion ---------- [Platform] Unify options key for structured output to `response_format` | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | | License | MIT it is now possible to just use the option `response_format` for everything instead of differentiating between `output_structure` for classes and `response_format` for concrete array structures. Commits ------- 0f13dd3 Unify options key for structured output to `response_format`
2 parents 4523036 + 0f13dd3 commit 3b936f2

File tree

18 files changed

+56
-43
lines changed

18 files changed

+56
-43
lines changed

docs/components/platform.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,14 @@ To achieve this, the ``Symfony\AI\Platform\StructuredOutput\PlatformSubscriber``
310310
Message::forSystem('You are a helpful math tutor. Guide the user through the solution step by step.'),
311311
Message::ofUser('how can I solve 8x + 7 = -23'),
312312
);
313-
$result = $platform->invoke('mistral-small-latest', $messages, ['output_structure' => MathReasoning::class]);
313+
$result = $platform->invoke('mistral-small-latest', $messages, ['response_format' => MathReasoning::class]);
314314

315315
dump($result->asObject()); // returns an instance of `MathReasoning` class
316316

317317
Array Structures as Output
318318
~~~~~~~~~~~~~~~~~~~~~~~~~~
319319

320-
Also PHP array structures as response_format are supported, which also requires the event subscriber mentioned above. On
320+
Also PHP array structures as `response_format` are supported, which also requires the event subscriber mentioned above. On
321321
top this example uses the feature through the agent to leverage tool calling::
322322

323323
use Symfony\AI\Platform\Message\Message;

examples/gemini/structured-output-math.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
Message::ofUser('how can I solve 8x + 7 = -23'),
2828
);
2929

30-
$result = $platform->invoke('gemini-2.5-flash', $messages, ['output_structure' => MathReasoning::class]);
30+
$result = $platform->invoke('gemini-2.5-flash', $messages, ['response_format' => MathReasoning::class]);
3131

3232
dump($result->asObject());

examples/mistral/structured-output-math.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
Message::forSystem('You are a helpful math tutor. Guide the user through the solution step by step.'),
2727
Message::ofUser('how can I solve 8x + 7 = -23'),
2828
);
29-
$result = $platform->invoke('mistral-small-latest', $messages, ['output_structure' => MathReasoning::class]);
29+
$result = $platform->invoke('mistral-small-latest', $messages, ['response_format' => MathReasoning::class]);
3030

3131
dump($result->asObject());

examples/ollama/structured-output-math.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
Message::forSystem('You are a helpful math tutor. Guide the user through the solution step by step.'),
2727
Message::ofUser('how can I solve 8x + 7 = -23'),
2828
);
29-
$result = $platform->invoke(env('OLLAMA_LLM'), $messages, ['output_structure' => MathReasoning::class]);
29+
$result = $platform->invoke(env('OLLAMA_LLM'), $messages, ['response_format' => MathReasoning::class]);
3030

3131
dump($result->asObject());

examples/openai/structured-output-list-of-polymorphic-items.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
Message::forSystem('You are a persona data collector! Return all the data you can gather from the user input.'),
2727
Message::ofUser('Hi! My name is John Doe, I am 30 years old and I live in Paris.'),
2828
);
29-
$result = $platform->invoke('gpt-4o-mini', $messages, ['output_structure' => ListOfPolymorphicTypesDto::class]);
29+
$result = $platform->invoke('gpt-4o-mini', $messages, ['response_format' => ListOfPolymorphicTypesDto::class]);
3030

3131
dump($result->asObject());

examples/openai/structured-output-math.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
Message::ofUser('how can I solve 8x + 7 = -23'),
2828
);
2929

30-
$result = $platform->invoke('gpt-4o-mini', $messages, ['output_structure' => MathReasoning::class]);
30+
$result = $platform->invoke('gpt-4o-mini', $messages, ['response_format' => MathReasoning::class]);
3131

3232
dump($result->asObject());

examples/openai/structured-output-union-types.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
PROMPT),
3030
Message::ofUser('What is the current time?'),
3131
);
32-
$result = $platform->invoke('gpt-4o-mini', $messages, ['output_structure' => UnionTypeDto::class]);
32+
$result = $platform->invoke('gpt-4o-mini', $messages, ['response_format' => UnionTypeDto::class]);
3333

3434
dump($result->asObject());

examples/scaleway/structured-output-math.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
Message::forSystem('You are a helpful math tutor. Guide the user through the solution step by step.'),
2828
Message::ofUser('how can I solve 8x + 7 = -23'),
2929
);
30-
$result = $platform->invoke('gpt-oss-120b', $messages, ['output_structure' => MathReasoning::class]);
30+
$result = $platform->invoke('gpt-oss-120b', $messages, ['response_format' => MathReasoning::class]);
3131

3232
dump($result->asObject());

examples/vertexai/structured-output-math.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
Message::ofUser('how can I solve 8x + 7 = -23'),
2828
);
2929

30-
$result = $platform->invoke('gemini-2.5-flash-lite', $messages, ['output_structure' => MathReasoning::class]);
30+
$result = $platform->invoke('gemini-2.5-flash-lite', $messages, ['response_format' => MathReasoning::class]);
3131

3232
dump($result->asObject());

src/agent/src/MultiAgent/MultiAgent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function call(MessageBag $messages, array $options = []): ResultInterface
8181
$agentSelectionPrompt = $this->buildAgentSelectionPrompt($userText);
8282

8383
$decision = $this->orchestrator->call(new MessageBag(Message::ofUser($agentSelectionPrompt)), array_merge($options, [
84-
'output_structure' => Decision::class,
84+
'response_format' => Decision::class,
8585
]))->getContent();
8686

8787
if (!$decision instanceof Decision) {

0 commit comments

Comments
 (0)