Skip to content

Google Gemini tool support #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2025
Merged

Google Gemini tool support #331

merged 1 commit into from
Jun 16, 2025

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants