|
11 | 11 |
|
12 | 12 | namespace Symfony\AI\AiBundle;
|
13 | 13 |
|
| 14 | +use Google\Auth\ApplicationDefaultCredentials; |
14 | 15 | use Symfony\AI\Agent\Agent;
|
15 | 16 | use Symfony\AI\Agent\AgentInterface;
|
16 | 17 | use Symfony\AI\Agent\InputProcessor\SystemPromptInputProcessor;
|
|
27 | 28 | use Symfony\AI\AiBundle\Security\Attribute\IsGrantedTool;
|
28 | 29 | use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory as AnthropicPlatformFactory;
|
29 | 30 | use Symfony\AI\Platform\Bridge\Azure\OpenAi\PlatformFactory as AzureOpenAiPlatformFactory;
|
| 31 | +use Symfony\AI\Platform\Bridge\Cerebras\PlatformFactory as CerebrasPlatformFactory; |
30 | 32 | use Symfony\AI\Platform\Bridge\Gemini\PlatformFactory as GeminiPlatformFactory;
|
31 | 33 | use Symfony\AI\Platform\Bridge\LmStudio\PlatformFactory as LmStudioPlatformFactory;
|
32 | 34 | use Symfony\AI\Platform\Bridge\Mistral\PlatformFactory as MistralPlatformFactory;
|
33 | 35 | use Symfony\AI\Platform\Bridge\Ollama\PlatformFactory as OllamaPlatformFactory;
|
34 | 36 | use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory as OpenAiPlatformFactory;
|
35 | 37 | use Symfony\AI\Platform\Bridge\OpenRouter\PlatformFactory as OpenRouterPlatformFactory;
|
36 |
| -use Symfony\AI\Platform\Bridge\Cerebras\PlatformFactory as CerebrasPlatformFactory; |
| 38 | +use Symfony\AI\Platform\Bridge\VertexAi\PlatformFactory as VertexAiPlatformFactory; |
| 39 | +use Symfony\AI\Platform\Exception\RuntimeException; |
37 | 40 | use Symfony\AI\Platform\Model;
|
38 | 41 | use Symfony\AI\Platform\ModelClientInterface;
|
39 | 42 | use Symfony\AI\Platform\Platform;
|
|
62 | 65 | use Symfony\Component\DependencyInjection\Definition;
|
63 | 66 | use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
64 | 67 | use Symfony\Component\DependencyInjection\Reference;
|
| 68 | +use Symfony\Component\HttpClient\EventSourceHttpClient; |
65 | 69 | use Symfony\Component\HttpClient\HttpClient;
|
66 | 70 | use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
|
67 | 71 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
@@ -226,6 +230,37 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
|
226 | 230 | return;
|
227 | 231 | }
|
228 | 232 |
|
| 233 | + if ('vertexai' === $type && isset($platform['location'], $platform['project_id'])) { |
| 234 | + if (!class_exists(ApplicationDefaultCredentials::class)) { |
| 235 | + throw new RuntimeException('For using the Vertex AI platform, google/auth package is required. Try running "composer require google/auth".'); |
| 236 | + } |
| 237 | + |
| 238 | + $credentials = ApplicationDefaultCredentials::getCredentials([ |
| 239 | + 'https://www.googleapis.com/auth/cloud-platform', |
| 240 | + ]); |
| 241 | + |
| 242 | + $httpClient = new EventSourceHttpClient(HttpClient::create([ |
| 243 | + 'auth_bearer' => $credentials?->fetchAuthToken()['access_token'] ?? null, |
| 244 | + ])); |
| 245 | + |
| 246 | + $platformId = 'ai.platform.vertexai'; |
| 247 | + $definition = (new Definition(Platform::class)) |
| 248 | + ->setFactory([VertexAiPlatformFactory::class, 'create']) |
| 249 | + ->setLazy(true) |
| 250 | + ->addTag('proxy', ['interface' => PlatformInterface::class]) |
| 251 | + ->setArguments([ |
| 252 | + $platform['location'], |
| 253 | + $platform['project_id'], |
| 254 | + $httpClient, |
| 255 | + new Reference('ai.platform.contract.vertexai', ContainerInterface::NULL_ON_INVALID_REFERENCE), |
| 256 | + ]) |
| 257 | + ->addTag('ai.platform'); |
| 258 | + |
| 259 | + $container->setDefinition($platformId, $definition); |
| 260 | + |
| 261 | + return; |
| 262 | + } |
| 263 | + |
229 | 264 | if ('openai' === $type) {
|
230 | 265 | $platformId = 'ai.platform.openai';
|
231 | 266 | $definition = (new Definition(Platform::class))
|
|
0 commit comments