Skip to content

Commit 9b0d38f

Browse files
valtzuchr-hertel
authored andcommitted
fix: Gemini multiple tools (#380)
Resolves #379
1 parent 7a0fb4f commit 9b0d38f

File tree

3 files changed

+26
-40
lines changed

3 files changed

+26
-40
lines changed

src/platform/src/Bridge/Google/Contract/ToolNormalizer.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,17 @@ protected function supportsModel(Model $model): bool
3838
* @param Tool $data
3939
*
4040
* @return array{
41-
* functionDeclarations: array{
42-
* name: string,
43-
* description: string,
44-
* parameters: JsonSchema|array{type: 'object'}
45-
* }[]
41+
* name: string,
42+
* description: string,
43+
* parameters: JsonSchema|array{type: 'object'}
4644
* }
4745
*/
4846
public function normalize(mixed $data, ?string $format = null, array $context = []): array
4947
{
5048
return [
51-
'functionDeclarations' => [
52-
[
53-
'description' => $data->description,
54-
'name' => $data->name,
55-
'parameters' => $data->parameters ? $this->removeAdditionalProperties($data->parameters) : null,
56-
],
57-
],
49+
'description' => $data->description,
50+
'name' => $data->name,
51+
'parameters' => $data->parameters ? $this->removeAdditionalProperties($data->parameters) : null,
5852
];
5953
}
6054

src/platform/src/Bridge/Google/ModelHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function request(Model $model, array|string $payload, array $options = []
7373
unset($generationConfig['generationConfig']['server_tools']);
7474

7575
if (isset($options['tools'])) {
76-
$generationConfig['tools'] = $options['tools'];
76+
$generationConfig['tools'][] = ['functionDeclarations' => $options['tools']];
7777
unset($options['tools']);
7878
}
7979

src/platform/tests/Bridge/Google/Contract/ToolNormalizerTest.php

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,25 @@ public static function normalizeDataProvider(): iterable
9999
],
100100
),
101101
[
102-
'functionDeclarations' => [
103-
[
104-
'description' => 'A tool with required parameters',
105-
'name' => 'tool_required_params',
106-
'parameters' => [
102+
'description' => 'A tool with required parameters',
103+
'name' => 'tool_required_params',
104+
'parameters' => [
105+
'type' => 'object',
106+
'properties' => [
107+
'text' => [
108+
'type' => 'string',
109+
'description' => 'Text parameter',
110+
],
111+
'number' => [
112+
'type' => 'integer',
113+
'description' => 'Number parameter',
114+
],
115+
'nestedObject' => [
107116
'type' => 'object',
108-
'properties' => [
109-
'text' => [
110-
'type' => 'string',
111-
'description' => 'Text parameter',
112-
],
113-
'number' => [
114-
'type' => 'integer',
115-
'description' => 'Number parameter',
116-
],
117-
'nestedObject' => [
118-
'type' => 'object',
119-
'description' => 'bar',
120-
],
121-
],
122-
'required' => ['text', 'number'],
117+
'description' => 'bar',
123118
],
124119
],
120+
'required' => ['text', 'number'],
125121
],
126122
],
127123
];
@@ -134,13 +130,9 @@ public static function normalizeDataProvider(): iterable
134130
null,
135131
),
136132
[
137-
'functionDeclarations' => [
138-
[
139-
'description' => 'A tool without parameters',
140-
'name' => 'tool_no_params',
141-
'parameters' => null,
142-
],
143-
],
133+
'description' => 'A tool without parameters',
134+
'name' => 'tool_no_params',
135+
'parameters' => null,
144136
],
145137
];
146138
}

0 commit comments

Comments
 (0)