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

Conversation

@valtzu
Copy link
Contributor

@valtzu valtzu commented Jun 13, 2025

Add tool support to Google Gemini.

Extracted from #320 with updates after #326

@tryvin
Copy link
Contributor

tryvin commented Jun 13, 2025

@valtzu thanks for the extraction! It's kinda hard to keep up with the updates here, as I can only contribute in my free time and I'm kinda busy lately.

Hopefully this gets merged soon

@valtzu
Copy link
Contributor Author

valtzu commented Jun 15, 2025

Added tool calls for streams too

Comment on lines 38 to 50
return [
['text' => $data->content],
array_filter(
[
'text' => $data->content,
'functionCall' => ($data->toolCalls[0] ?? null) ? [
'id' => $data->toolCalls[0]->id,
'name' => $data->toolCalls[0]->name,
'args' => $data->toolCalls[0]->arguments ?: new \ArrayObject(),
] : null,
],
static fn ($content) => null !== $content,
),
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this the same like

$normalized = [];

if (null !== $data->content) {
    $normalized['text'] = $data->content;
}

if (isset($data->toolCalls[0])) {
    $normalized['functionCall'] = [
        'id' => $data->toolCalls[0]->id,
        'name' => $data->toolCalls[0]->name,
        'args' => $data->toolCalls[0]->arguments ?: new \ArrayObject(),
    ];
}

return [$normalized];

at least that's more readable to me

could also have a separate ToolCallNormalizer but that might be overkill

Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this - looks great already.
Can you please have a look at my comment and fix phpstan?

@chr-hertel
Copy link
Member

Oh, and would be great if you could add @author tags in new src files 👍

@valtzu
Copy link
Contributor Author

valtzu commented Jun 16, 2025

Should be good now

public function normalize(mixed $data, ?string $format = null, array $context = []): array
{
$parameters = $data->parameters;
unset($parameters['additionalProperties']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why/if this is needed, but it was included in the original implementation by @tryvin

@chr-hertel
Copy link
Member

Nevermind the commit pipeline thingy ... 👍

Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @valtzu & @tryvin - looks good 👍

@chr-hertel chr-hertel merged commit dbd6ff8 into php-llm:main Jun 16, 2025
6 of 7 checks passed
chr-hertel added a commit to symfony/ai that referenced this pull request Jun 18, 2025
This PR was merged into the main branch.

Discussion
----------

feat: add Google Gemini tool support (#331)

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| Docs?         | no
| Issues        |
| License       | MIT

Cherry-Picking php-llm/llm-chain#331

> Add tool support to Google Gemini.
>
> Extracted from #320 with updates after #326

Commits
-------

2206f1e feat: add Google Gemini tool support (#331)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants