Skip to content

Commit aeccff2

Browse files
committed
feature #50 feat: Google structured output (valtzu)
This PR was merged into the main branch. Discussion ---------- feat: Google structured output | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | Issues | | License | MIT Cherry picking php-llm/llm-chain#354 Commits ------- 0a0e632 feat: Google structured output (#354)
2 parents 7ad2aea + ac47652 commit aeccff2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Bridge/Google/Gemini.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function __construct(string $name = self::GEMINI_2_PRO, array $options =
3636
Capability::INPUT_AUDIO,
3737
Capability::INPUT_PDF,
3838
Capability::OUTPUT_STREAMING,
39+
Capability::OUTPUT_STRUCTURED,
3940
Capability::TOOL_CALLING,
4041
];
4142

src/Bridge/Google/ModelHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public function request(Model $model, array|string $payload, array $options = []
6161
$options['stream'] ?? false ? 'streamGenerateContent' : 'generateContent',
6262
);
6363

64+
if (isset($options['response_format']['json_schema']['schema'])) {
65+
$options['responseMimeType'] = 'application/json';
66+
$options['responseJsonSchema'] = $options['response_format']['json_schema']['schema'];
67+
unset($options['response_format']);
68+
}
69+
6470
$generationConfig = ['generationConfig' => $options];
6571
unset($generationConfig['generationConfig']['stream']);
6672
unset($generationConfig['generationConfig']['tools']);

0 commit comments

Comments
 (0)