Skip to content

Commit 3b7c18e

Browse files
stefannaeDouweM
andauthored
Add custom Vertex AI Model Garden example (#2868)
Co-authored-by: Douwe Maan <[email protected]>
1 parent 5287abf commit 3b7c18e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/models/google.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,36 @@ agent = Agent(model)
108108
...
109109
```
110110

111+
#### Customizing Model
112+
113+
You can access models from the [Model Garden](https://cloud.google.com/model-garden?hl=en) that support the generateContent API and are available under your GCP project, including but not limited to Gemini, using one of the following `model_name` patterns:
114+
115+
- `{model_id}` for Gemini models
116+
- `{publisher}/{model_id}`
117+
- `publishers/{publisher}/models/{model_id}`
118+
- `projects/{project}/locations/{location}/publishers/{publisher}/models/{model_id}`
119+
120+
```python {test="skip"}
121+
from google.oauth2 import service_account
122+
123+
from pydantic_ai import Agent
124+
from pydantic_ai.models.google import GoogleModel
125+
from pydantic_ai.providers.google import GoogleProvider
126+
127+
credentials = service_account.Credentials.from_service_account_file(
128+
'path/to/service-account.json',
129+
scopes=['https://www.googleapis.com/auth/cloud-platform'],
130+
)
131+
provider = GoogleProvider(
132+
credentials=credentials,
133+
project='your-gcp-project-id',
134+
location='us-central1', # the region where the model is available
135+
)
136+
model = GoogleModel('meta/llama-3.3-70b-instruct-maas', provider=provider)
137+
agent = Agent(model)
138+
...
139+
```
140+
111141
## Provider Argument
112142

113143
You can supply a custom `GoogleProvider` instance using the `provider` argument to configure advanced client options, such as setting a custom `base_url`.

0 commit comments

Comments
 (0)