Skip to content

Commit 6d8e535

Browse files
docs(platform): Add support for Google vertex AI
- Adds documentation for vertex ai
1 parent ea21289 commit 6d8e535

File tree

6 files changed

+126
-6
lines changed

6 files changed

+126
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Symfony AI is a set of components that integrate AI capabilities into PHP applic
1313
Symfony AI consists of several lower and higher level **components** and the respective integration **bundles**:
1414

1515
* **Components**
16-
* **[Platform](src/platform/README.md)**: A unified interface to various AI platforms like OpenAI, Anthropic, Azure, Gemini, and more.
16+
* **[Platform](src/platform/README.md)**: A unified interface to various AI platforms like OpenAI, Anthropic, Azure, Gemini, VertexAI, and more.
1717
* **[Agent](src/agent/README.md)**: Framework for building AI agents that can interact with users and perform tasks.
1818
* **[Store](src/store/README.md)**: Data storage abstraction with indexing and retrieval for AI applications.
1919
* **[MCP SDK](src/mcp-sdk/README.md)**: SDK for [Model Context Protocol](https://modelcontextprotocol.io) enabling communication between AI agents and tools.

examples/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ RUN_EXPENSIVE_EXAMPLES=false
7373
GEMINI_API_KEY=
7474

7575
# Vertex AI
76-
GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
7776
GOOGLE_CLOUD_LOCATION=global
77+
GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
7878

7979
# For using Albert API (French Sovereign AI)
8080
ALBERT_API_KEY=

src/ai-bundle/doc/index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Configuration
3434
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
3535
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
3636
37-
**Advanced Example with Anthropic, Azure, Gemini and multiple agents**
37+
**Advanced Example with Anthropic, Azure, Gemini, VertexAi and multiple agents**
3838

3939
.. code-block:: yaml
4040
@@ -52,6 +52,9 @@ Configuration
5252
api_version: '%env(AZURE_GPT_VERSION)%'
5353
gemini:
5454
api_key: '%env(GEMINI_API_KEY)%'
55+
vertexAi:
56+
location: '%env(GOOGLE_CLOUD_LOCATION)%'
57+
project_id: '%env(GOOGLE_CLOUD_PROJECT)%'
5558
ollama:
5659
host_url: '%env(OLLAMA_HOST_URL)%'
5760
agent:

src/platform/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CHANGELOG
99
* Add support for 13+ AI providers:
1010
- OpenAI (GPT-4, GPT-3.5, DALL·E, Whisper)
1111
- Anthropic (Claude models via native API and AWS Bedrock)
12-
- Google (Gemini models with server-side tools support)
12+
- Google (VertexAi and Gemini models with server-side tools support)
1313
- Azure (OpenAI and Meta Llama models)
1414
- AWS Bedrock (Anthropic Claude, Meta Llama, Amazon Nova)
1515
- Mistral AI (language models and embeddings)

src/platform/doc/index.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ usually defined by the specific models and their documentation.
7373
* `OpenAI's GPT`_ with `OpenAI`_ and `Azure`_ as Platform
7474
* `Anthropic's Claude`_ with `Anthropic`_ and `AWS Bedrock`_ as Platform
7575
* `Meta's Llama`_ with `Azure`_, `Ollama`_, `Replicate`_ and `AWS Bedrock`_ as Platform
76-
* `Gemini`_ with `Google`_ and `OpenRouter`_ as Platform
76+
* `Gemini`_ with `Google`_, `VertexAi`_ and `OpenRouter`_ as Platform
77+
* `VertexAi Gen AI`_ with `VertexAi`_ as Platform
7778
* `DeepSeek's R1`_ with `OpenRouter`_ as Platform
7879
* `Amazon's Nova`_ with `AWS Bedrock`_ as Platform
7980
* `Mistral's Mistral`_ with `Mistral`_ as Platform
8081
* `Albert API`_ models with `Albert`_ as Platform (French government's sovereign AI gateway)
8182
* **Embeddings Models**
8283
* `Gemini Text Embeddings`_ with `Google`_
84+
* `VertexAi Text Embeddings`_ with `VertexAi`_
8385
* `OpenAI's Text Embeddings`_ with `OpenAI`_ and `Azure`_ as Platform
8486
* `Voyage's Embeddings`_ with `Voyage`_ as Platform
8587
* `Mistral Embed`_ with `Mistral`_ as Platform
@@ -263,7 +265,8 @@ Server Tools
263265

264266
Some platforms provide built-in server-side tools for enhanced capabilities without custom implementations:
265267

266-
1. **[Gemini](gemini-server-tools.md)** - URL Context, Google Search, Code Execution
268+
1. **[Gemini](gemini-server-tools.rst)** - URL Context, Google Search, Code Execution
269+
2. **[VertexAi](vertexai-server-tools.rst)** - URL Context, Google Search, Code Execution
267270

268271
Parallel Platform Calls
269272
-----------------------
@@ -363,6 +366,7 @@ This allows fast and isolated testing of AI-powered features without relying on
363366
.. _`Ollama`: https://ollama.com/
364367
.. _`Replicate`: https://replicate.com/
365368
.. _`Gemini`: https://gemini.google.com/
369+
.. _`VertexAi`: https://cloud.google.com/vertex-ai/generative-ai/docs
366370
.. _`Google`: https://ai.google.dev/
367371
.. _`OpenRouter`: https://www.openrouter.ai/
368372
.. _`DeepSeek's R1`: https://www.deepseek.com/
@@ -372,6 +376,8 @@ This allows fast and isolated testing of AI-powered features without relying on
372376
.. _`Albert`: https://alliance.numerique.gouv.fr/produit/albert/
373377
.. _`Mistral`: https://www.mistral.ai/
374378
.. _`Gemini Text Embeddings`: https://ai.google.dev/gemini-api/docs/embeddings
379+
.. _`VertexAi Gen AI`: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference
380+
.. _`VertexAi Text Embeddings`: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/text-embeddings-api
375381
.. _`OpenAI's Text Embeddings`: https://platform.openai.com/docs/guides/embeddings/embedding-models
376382
.. _`Voyage's Embeddings`: https://docs.voyageai.com/docs/embeddings
377383
.. _`Voyage`: https://www.voyageai.com/
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
Vertex AI Server Tools
2+
======================
3+
4+
Server tools in Vertex AI are built-in capabilities provided by Google's Gemini models that allow the model to perform
5+
specific actions without requiring custom tool implementations.
6+
These tools run on Google's infrastructure and provide access to external data sources and execution environments.
7+
8+
Overview
9+
--------
10+
11+
Vertex AI provides several server-side tools that can be enabled when calling the model:
12+
13+
- **URL Context** - Fetches and analyzes content from URLs
14+
- **Grounding** - Lets a model output connect to verifiable sources of information.
15+
- **Code Execution** - Executes code in a sandboxed environment.
16+
17+
Available Server Tools
18+
----------------------
19+
20+
**URL Context**
21+
22+
The URL Context tool allows the model to fetch and analyze content from specified web pages. This is useful for:
23+
24+
- Analyzing current web content
25+
- Extracting structured information from pages
26+
- Providing context from external documents
27+
- https://cloud.google.com/vertex-ai/generative-ai/docs/url-context
28+
29+
::
30+
31+
$model = new VertexAi\Gemini\Model('gemini-2.5-pro');
32+
33+
$content = file_get_contents('https://www.euribor-rates.eu/en/current-euribor-rates/4/euribor-rate-12-months/');
34+
$messages = new MessageBag(
35+
Message::ofUser("Based on the following page content, what was the 12-month Euribor rate a week ago?\n\n".$content)
36+
);
37+
38+
$result = $platform->invoke($model, $messages);
39+
40+
41+
**Grounding with Google Search**
42+
The Grounding tool allows the model to connect its responses to verifiable sources of information, enhancing the reliability
43+
of its outputs. More at https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
44+
Below is an example of grounding a model's responses using Google Search, which uses publicly-available web data.
45+
46+
* Grounding with Google Search *
47+
48+
Ground a model's responses using Google Search, which uses publicly-available web data.
49+
More info can be found at https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
50+
51+
::
52+
53+
$model = new VertexAi\Gemini\Model('gemini-2.5-pro', [
54+
'tools' => [[
55+
'googleSearch' => new \stdClass()
56+
]]
57+
]);
58+
59+
$messages = new MessageBag(
60+
Message::ofUser('What are the top breakthroughs in AI in 2025 so far?')
61+
);
62+
63+
$result = $platform->invoke($model, $messages);
64+
65+
**Code Execution**
66+
67+
Executes code in a Google-managed sandbox environment and returns both the code and its output.
68+
More info can be found at https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/code-execution
69+
70+
::
71+
72+
$model = new Gemini('gemini-2.5-pro-preview-03-25', [
73+
'tools' => [[
74+
'codeExecution' => new \stdClass()
75+
]]
76+
]);
77+
78+
$messages = new MessageBag(
79+
Message::ofUser('Write Python code to calculate the 50th Fibonacci number and run it')
80+
);
81+
82+
$result = $platform->invoke($model, $messages);
83+
84+
85+
Using Multiple Server Tools
86+
---------------------------
87+
88+
You can enable multiple tools in a single request::
89+
90+
$model = new Gemini('gemini-2.5-pro-preview-03-25', [
91+
'tools' => [[
92+
'googleSearch' => new \stdClass(),
93+
'codeExecution' => new \stdClass()
94+
]]
95+
]);
96+
97+
Example
98+
-------
99+
100+
See `examples/vertexai/server-tools.php`_ for a complete working example.
101+
102+
Limitations
103+
-----------
104+
105+
- **Model support:** Not all Vertex AI Gemini model versions support all server tools — check the Vertex AI documentation for the chosen model ID.
106+
- **Permissions:** The Vertex AI service account and the models must have the required permissions or scopes to use server tools.
107+
- **Quotas:** Server tools are subject to usage limits and quotas configured in your Google Cloud project.
108+
- **Latency:** Using multiple tools or fetching from slow external sources can increase response time.
109+
- **Regional availability:** Ensure you are using a location that supports the selected model and tools.
110+
111+
.. _`examples/vertexai/server-tools.php`: https://github.com/symfony/ai/blob/main/examples/vertexai/server-tools.php

0 commit comments

Comments
 (0)