|
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;
|
|
73 | 74 | use Symfony\Component\DependencyInjection\Definition;
|
74 | 75 | use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
75 | 76 | use Symfony\Component\DependencyInjection\Reference;
|
76 |
| -use Symfony\Component\HttpClient\EventSourceHttpClient; |
77 | 77 | use Symfony\Component\HttpClient\HttpClient;
|
78 | 78 | use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
|
79 | 79 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
@@ -279,13 +279,21 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
|
279 | 279 | throw new RuntimeException('For using the Vertex AI platform, google/auth package is required. Try running "composer require google/auth".');
|
280 | 280 | }
|
281 | 281 |
|
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 | + ; |
285 | 288 |
|
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 | + ; |
289 | 297 |
|
290 | 298 | $platformId = 'ai.platform.vertexai';
|
291 | 299 | $definition = (new Definition(Platform::class))
|
|
0 commit comments