Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/Platform/Bridge/Google/Contract/ToolNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,17 @@ protected function supportsModel(Model $model): bool
* @param Tool $data
*
* @return array{
* functionDeclarations: array{
* name: string,
* description: string,
* parameters: JsonSchema|array{type: 'object'}
* }[]
* name: string,
* description: string,
* parameters: JsonSchema|array{type: 'object'}
* }
*/
public function normalize(mixed $data, ?string $format = null, array $context = []): array
{
return [
'functionDeclarations' => [
[
'description' => $data->description,
'name' => $data->name,
'parameters' => $data->parameters ? $this->removeAdditionalProperties($data->parameters) : null,
],
],
'description' => $data->description,
'name' => $data->name,
'parameters' => $data->parameters ? $this->removeAdditionalProperties($data->parameters) : null,
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Platform/Bridge/Google/ModelHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function request(Model $model, array|string $payload, array $options = []
unset($generationConfig['generationConfig']['server_tools']);

if (isset($options['tools'])) {
$generationConfig['tools'] = $options['tools'];
$generationConfig['tools'][] = ['functionDeclarations' => $options['tools']];
unset($options['tools']);
}

Expand Down
46 changes: 19 additions & 27 deletions tests/Platform/Bridge/Google/Contract/ToolNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,25 @@ public static function normalizeDataProvider(): iterable
],
),
[
'functionDeclarations' => [
[
'description' => 'A tool with required parameters',
'name' => 'tool_required_params',
'parameters' => [
'description' => 'A tool with required parameters',
'name' => 'tool_required_params',
'parameters' => [
'type' => 'object',
'properties' => [
'text' => [
'type' => 'string',
'description' => 'Text parameter',
],
'number' => [
'type' => 'integer',
'description' => 'Number parameter',
],
'nestedObject' => [
'type' => 'object',
'properties' => [
'text' => [
'type' => 'string',
'description' => 'Text parameter',
],
'number' => [
'type' => 'integer',
'description' => 'Number parameter',
],
'nestedObject' => [
'type' => 'object',
'description' => 'bar',
],
],
'required' => ['text', 'number'],
'description' => 'bar',
],
],
'required' => ['text', 'number'],
],
],
];
Expand All @@ -127,13 +123,9 @@ public static function normalizeDataProvider(): iterable
null,
),
[
'functionDeclarations' => [
[
'description' => 'A tool without parameters',
'name' => 'tool_no_params',
'parameters' => null,
],
],
'description' => 'A tool without parameters',
'name' => 'tool_no_params',
'parameters' => null,
],
];
}
Expand Down