|
12 | 12 | namespace Symfony\AI\AiBundle; |
13 | 13 |
|
14 | 14 | use Google\Auth\ApplicationDefaultCredentials; |
| 15 | +use Google\Auth\FetchAuthTokenInterface; |
15 | 16 | use Symfony\AI\Agent\Agent; |
16 | 17 | use Symfony\AI\Agent\AgentInterface; |
17 | 18 | use Symfony\AI\Agent\Attribute\AsInputProcessor; |
|
75 | 76 | use Symfony\Component\DependencyInjection\Definition; |
76 | 77 | use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; |
77 | 78 | use Symfony\Component\DependencyInjection\Reference; |
78 | | -use Symfony\Component\HttpClient\EventSourceHttpClient; |
79 | 79 | use Symfony\Component\HttpClient\HttpClient; |
80 | 80 | use Symfony\Component\HttpKernel\Bundle\AbstractBundle; |
81 | 81 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
@@ -281,13 +281,21 @@ private function processPlatformConfig(string $type, array $platform, ContainerB |
281 | 281 | throw new RuntimeException('For using the Vertex AI platform, google/auth package is required. Try running "composer require google/auth".'); |
282 | 282 | } |
283 | 283 |
|
284 | | - $credentials = ApplicationDefaultCredentials::getCredentials([ |
285 | | - 'https://www.googleapis.com/auth/cloud-platform', |
286 | | - ]); |
| 284 | + $credentials = (new Definition(FetchAuthTokenInterface::class)) |
| 285 | + ->setFactory([ApplicationDefaultCredentials::class, 'getCredentials']) |
| 286 | + ->setArguments([ |
| 287 | + 'https://www.googleapis.com/auth/cloud-platform', |
| 288 | + ]) |
| 289 | + ; |
287 | 290 |
|
288 | | - $httpClient = new EventSourceHttpClient(HttpClient::create([ |
289 | | - 'auth_bearer' => $credentials?->fetchAuthToken()['access_token'] ?? null, |
290 | | - ])); |
| 291 | + $credentialsObject = new Definition(\ArrayObject::class, [(new Definition('array'))->setFactory([$credentials, 'fetchAuthToken'])]); |
| 292 | + |
| 293 | + $httpClient = (new Definition(HttpClientInterface::class)) |
| 294 | + ->setFactory([HttpClient::class, 'create']) |
| 295 | + ->setArgument(0, [ |
| 296 | + 'auth_bearer' => (new Definition('string', ['access_token']))->setFactory([$credentialsObject, 'offsetGet']), |
| 297 | + ]) |
| 298 | + ; |
291 | 299 |
|
292 | 300 | $platformId = 'ai.platform.vertexai'; |
293 | 301 | $definition = (new Definition(Platform::class)) |
|
0 commit comments