Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit a24724c

Browse files
authored
fix: Gemini multiple tools (#380)
Resolves #379
1 parent 71714f5 commit a24724c

File tree

3 files changed

+26
-40
lines changed

3 files changed

+26
-40
lines changed

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,17 @@ protected function supportsModel(Model $model): bool
2929
* @param Tool $data
3030
*
3131
* @return array{
32-
* functionDeclarations: array{
33-
* name: string,
34-
* description: string,
35-
* parameters: JsonSchema|array{type: 'object'}
36-
* }[]
32+
* name: string,
33+
* description: string,
34+
* parameters: JsonSchema|array{type: 'object'}
3735
* }
3836
*/
3937
public function normalize(mixed $data, ?string $format = null, array $context = []): array
4038
{
4139
return [
42-
'functionDeclarations' => [
43-
[
44-
'description' => $data->description,
45-
'name' => $data->name,
46-
'parameters' => $data->parameters ? $this->removeAdditionalProperties($data->parameters) : null,
47-
],
48-
],
40+
'description' => $data->description,
41+
'name' => $data->name,
42+
'parameters' => $data->parameters ? $this->removeAdditionalProperties($data->parameters) : null,
4943
];
5044
}
5145

src/Platform/Bridge/Google/ModelHandler.php

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

6868
if (isset($options['tools'])) {
69-
$generationConfig['tools'] = $options['tools'];
69+
$generationConfig['tools'][] = ['functionDeclarations' => $options['tools']];
7070
unset($options['tools']);
7171
}
7272

tests/Platform/Bridge/Google/Contract/ToolNormalizerTest.php

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,25 @@ public static function normalizeDataProvider(): iterable
9292
],
9393
),
9494
[
95-
'functionDeclarations' => [
96-
[
97-
'description' => 'A tool with required parameters',
98-
'name' => 'tool_required_params',
99-
'parameters' => [
95+
'description' => 'A tool with required parameters',
96+
'name' => 'tool_required_params',
97+
'parameters' => [
98+
'type' => 'object',
99+
'properties' => [
100+
'text' => [
101+
'type' => 'string',
102+
'description' => 'Text parameter',
103+
],
104+
'number' => [
105+
'type' => 'integer',
106+
'description' => 'Number parameter',
107+
],
108+
'nestedObject' => [
100109
'type' => 'object',
101-
'properties' => [
102-
'text' => [
103-
'type' => 'string',
104-
'description' => 'Text parameter',
105-
],
106-
'number' => [
107-
'type' => 'integer',
108-
'description' => 'Number parameter',
109-
],
110-
'nestedObject' => [
111-
'type' => 'object',
112-
'description' => 'bar',
113-
],
114-
],
115-
'required' => ['text', 'number'],
110+
'description' => 'bar',
116111
],
117112
],
113+
'required' => ['text', 'number'],
118114
],
119115
],
120116
];
@@ -127,13 +123,9 @@ public static function normalizeDataProvider(): iterable
127123
null,
128124
),
129125
[
130-
'functionDeclarations' => [
131-
[
132-
'description' => 'A tool without parameters',
133-
'name' => 'tool_no_params',
134-
'parameters' => null,
135-
],
136-
],
126+
'description' => 'A tool without parameters',
127+
'name' => 'tool_no_params',
128+
'parameters' => null,
137129
],
138130
];
139131
}

0 commit comments

Comments
 (0)