Skip to content

Commit bf7b9ab

Browse files
committed
[AiBundle] Fix VertexAI services
1 parent f9be079 commit bf7b9ab

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/ai-bundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"symfony/string": "^6.4 || ^7.0"
2626
},
2727
"require-dev": {
28+
"google/auth": "^1.47",
2829
"phpstan/phpstan": "^2.1",
2930
"phpunit/phpunit": "^11.5",
3031
"symfony/expression-language": "^6.4 || ^7.0",

src/ai-bundle/src/AiBundle.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\AI\AiBundle;
1313

1414
use Google\Auth\ApplicationDefaultCredentials;
15+
use Google\Auth\FetchAuthTokenInterface;
1516
use Symfony\AI\Agent\Agent;
1617
use Symfony\AI\Agent\AgentInterface;
1718
use Symfony\AI\Agent\Attribute\AsInputProcessor;
@@ -73,7 +74,6 @@
7374
use Symfony\Component\DependencyInjection\Definition;
7475
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
7576
use Symfony\Component\DependencyInjection\Reference;
76-
use Symfony\Component\HttpClient\EventSourceHttpClient;
7777
use Symfony\Component\HttpClient\HttpClient;
7878
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
7979
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
@@ -279,13 +279,21 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
279279
throw new RuntimeException('For using the Vertex AI platform, google/auth package is required. Try running "composer require google/auth".');
280280
}
281281

282-
$credentials = ApplicationDefaultCredentials::getCredentials([
283-
'https://www.googleapis.com/auth/cloud-platform',
284-
]);
282+
$credentials = (new Definition(FetchAuthTokenInterface::class))
283+
->setFactory([ApplicationDefaultCredentials::class, 'getCredentials'])
284+
->setArguments([
285+
'https://www.googleapis.com/auth/cloud-platform',
286+
])
287+
;
285288

286-
$httpClient = new EventSourceHttpClient(HttpClient::create([
287-
'auth_bearer' => $credentials?->fetchAuthToken()['access_token'] ?? null,
288-
]));
289+
$credentialsObject = new Definition(\ArrayObject::class, [(new Definition('array'))->setFactory([$credentials, 'fetchAuthToken'])]);
290+
291+
$httpClient = (new Definition(HttpClientInterface::class))
292+
->setFactory([HttpClient::class, 'create'])
293+
->setArgument(0, [
294+
'auth_bearer' => (new Definition('string', ['access_token']))->setFactory([$credentialsObject, 'offsetGet']),
295+
])
296+
;
289297

290298
$platformId = 'ai.platform.vertexai';
291299
$definition = (new Definition(Platform::class))

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ private function getFullConfig(): array
369369
'voyage' => [
370370
'api_key' => 'voyage_key_full',
371371
],
372+
'vertexai' => [
373+
'location' => 'global',
374+
'project_id' => '123',
375+
],
372376
],
373377
'agent' => [
374378
'my_chat_agent' => [

0 commit comments

Comments
 (0)