Skip to content

Commit 653978e

Browse files
feat(platform): Add support for Google vertex AI
- Adds ai bundle integration
1 parent cd83b3b commit 653978e

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/ai-bundle/src/AiBundle.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\AI\AiBundle;
1313

14+
use Google\Auth\ApplicationDefaultCredentials;
1415
use Symfony\AI\Agent\Agent;
1516
use Symfony\AI\Agent\AgentInterface;
1617
use Symfony\AI\Agent\InputProcessor\SystemPromptInputProcessor;
@@ -27,13 +28,15 @@
2728
use Symfony\AI\AiBundle\Security\Attribute\IsGrantedTool;
2829
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory as AnthropicPlatformFactory;
2930
use Symfony\AI\Platform\Bridge\Azure\OpenAi\PlatformFactory as AzureOpenAiPlatformFactory;
31+
use Symfony\AI\Platform\Bridge\Cerebras\PlatformFactory as CerebrasPlatformFactory;
3032
use Symfony\AI\Platform\Bridge\Gemini\PlatformFactory as GeminiPlatformFactory;
3133
use Symfony\AI\Platform\Bridge\LmStudio\PlatformFactory as LmStudioPlatformFactory;
3234
use Symfony\AI\Platform\Bridge\Mistral\PlatformFactory as MistralPlatformFactory;
3335
use Symfony\AI\Platform\Bridge\Ollama\PlatformFactory as OllamaPlatformFactory;
3436
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory as OpenAiPlatformFactory;
3537
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;
3740
use Symfony\AI\Platform\Model;
3841
use Symfony\AI\Platform\ModelClientInterface;
3942
use Symfony\AI\Platform\Platform;
@@ -62,6 +65,7 @@
6265
use Symfony\Component\DependencyInjection\Definition;
6366
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
6467
use Symfony\Component\DependencyInjection\Reference;
68+
use Symfony\Component\HttpClient\EventSourceHttpClient;
6569
use Symfony\Component\HttpClient\HttpClient;
6670
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
6771
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
@@ -226,6 +230,37 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
226230
return;
227231
}
228232

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+
229264
if ('openai' === $type) {
230265
$platformId = 'ai.platform.openai';
231266
$definition = (new Definition(Platform::class))

0 commit comments

Comments
 (0)