Skip to content
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
1 change: 1 addition & 0 deletions src/ai-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"symfony/string": "^6.4 || ^7.0"
},
"require-dev": {
"google/auth": "^1.47",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^11.5",
"symfony/expression-language": "^6.4 || ^7.0",
Expand Down
22 changes: 15 additions & 7 deletions src/ai-bundle/src/AiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\AI\AiBundle;

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

$credentials = ApplicationDefaultCredentials::getCredentials([
'https://www.googleapis.com/auth/cloud-platform',
]);
$credentials = (new Definition(FetchAuthTokenInterface::class))
->setFactory([ApplicationDefaultCredentials::class, 'getCredentials'])
->setArguments([
'https://www.googleapis.com/auth/cloud-platform',
])
;

$httpClient = new EventSourceHttpClient(HttpClient::create([
'auth_bearer' => $credentials?->fetchAuthToken()['access_token'] ?? null,
]));
$credentialsObject = new Definition(\ArrayObject::class, [(new Definition('array'))->setFactory([$credentials, 'fetchAuthToken'])]);

$httpClient = (new Definition(HttpClientInterface::class))
->setFactory([HttpClient::class, 'create'])
->setArgument(0, [
'auth_bearer' => (new Definition('string', ['access_token']))->setFactory([$credentialsObject, 'offsetGet']),
])
;

$platformId = 'ai.platform.vertexai';
$definition = (new Definition(Platform::class))
Expand Down
4 changes: 4 additions & 0 deletions src/ai-bundle/tests/DependencyInjection/AiBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ private function getFullConfig(): array
'voyage' => [
'api_key' => 'voyage_key_full',
],
'vertexai' => [
'location' => 'global',
'project_id' => '123',
],
],
'agent' => [
'my_chat_agent' => [
Expand Down