Skip to content

Commit a1787d7

Browse files
authored
Update Google GLA file docs + example code
- Added example code for file uploads and inline usage with Gemini GLA. - Clarified Google GLA file upload option
1 parent 24e47bf commit a1787d7

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

docs/input.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ The situation is different for certain models:
110110

111111
- [`AnthropicModel`][pydantic_ai.models.anthropic.AnthropicModel]: if you provide a PDF document via `DocumentUrl`, the URL is sent directly in the API request, so no download happens on the user side.
112112

113+
- [`GoogleModel`][pydantic_ai.models.google.GoogleModel] on GLA:
114+
- YouTube video URLs are sent directly in the request to the model.
115+
- Files uploaded to the [Files API](https://ai.google.dev/gemini-api/docs/files) (by prefix matching on `https://generativelanguage.googleapis.com/v1beta/files`)
116+
113117
- [`GoogleModel`][pydantic_ai.models.google.GoogleModel] on Vertex AI: any URL provided using `ImageUrl`, `AudioUrl`, `VideoUrl`, or `DocumentUrl` is sent as-is in the API request and no data is downloaded beforehand.
114118

115119
See the [Gemini API docs for Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#filedata) to learn more about supported URLs, formats and limitations:
@@ -120,4 +124,28 @@ The situation is different for certain models:
120124

121125
However, because of crawling restrictions, it may happen that Gemini can't access certain URLs. In that case, you can instruct Pydantic AI to download the file content and send that instead of the URL by setting the boolean flag `force_download` to `True`. This attribute is available on all objects that inherit from [`FileUrl`][pydantic_ai.messages.FileUrl].
122126

123-
- [`GoogleModel`][pydantic_ai.models.google.GoogleModel] on GLA: YouTube video URLs are sent directly in the request to the model.
127+
## Example code for Gemini GLA
128+
129+
Upload a file via Files API:
130+
131+
```py {title="file_upload.py" test="skip" lint="skip"}
132+
from google import genai
133+
from pydantic_ai.messages import BinaryContent, DocumentUrl
134+
from io import BytesIO
135+
136+
client = genai.Client(api_key=API_KEY)
137+
uploaded_file = client.files.upload(file=BytesIO(file_bytes), config={"mime_type": mimetype})
138+
user_prompt = ["Show me the money!", DocumentUrl(url=uploaded_file.uri, media_type=mimetype)]
139+
await agent.run(user_prompt)
140+
```
141+
142+
Inline a file as a text part:
143+
144+
```py {title="file_inline.py" test="skip" lint="skip"}
145+
from google import genai
146+
from pydantic_ai.messages import BinaryContent, DocumentUrl
147+
148+
client = genai.Client(api_key=API_KEY)
149+
user_prompt = ["This seemed important at 3am", BinaryContent(data=file_bytes, media_type=mimetype)]
150+
await agent.run(user_prompt)
151+
```

0 commit comments

Comments
 (0)