Skip to content

Commit 2917ac8

Browse files
committed
Add test for Google UploadedFile
1 parent 490a4f3 commit 2917ac8

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
interactions:
2+
- request:
3+
headers:
4+
accept:
5+
- '*/*'
6+
accept-encoding:
7+
- gzip, deflate
8+
connection:
9+
- keep-alive
10+
content-length:
11+
- '280'
12+
content-type:
13+
- application/json
14+
host:
15+
- generativelanguage.googleapis.com
16+
method: POST
17+
parsed_body:
18+
contents:
19+
- parts:
20+
- fileData:
21+
fileUri: https://generativelanguage.googleapis.com/v1beta/files/6myu0b1v3mxl
22+
mimeType: application/pdf
23+
role: user
24+
- parts:
25+
- text: Give me a short description of this image
26+
role: user
27+
generationConfig: {}
28+
uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent
29+
response:
30+
headers:
31+
alt-svc:
32+
- h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
33+
content-length:
34+
- '881'
35+
content-type:
36+
- application/json; charset=UTF-8
37+
server-timing:
38+
- gfet4t7; dur=5652
39+
transfer-encoding:
40+
- chunked
41+
vary:
42+
- Origin
43+
- X-Origin
44+
- Referer
45+
parsed_body:
46+
candidates:
47+
- content:
48+
parts:
49+
- text: The image displays a classic smiley face. It features a bright yellow circular face with two simple black
50+
dot eyes and an upward-curved black line forming a smile. The yellow circle has a subtle darker yellow outline
51+
and is set against a plain white background.
52+
role: model
53+
finishReason: STOP
54+
index: 0
55+
modelVersion: gemini-2.5-flash
56+
responseId: T7OkaOv-JOemmtkP5IXU2QI
57+
usageMetadata:
58+
candidatesTokenCount: 51
59+
promptTokenCount: 268
60+
promptTokensDetails:
61+
- modality: TEXT
62+
tokenCount: 10
63+
- modality: DOCUMENT
64+
tokenCount: 258
65+
thoughtsTokenCount: 678
66+
totalTokenCount: 997
67+
status:
68+
code: 200
69+
message: OK
70+
version: 1

tests/models/test_google.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
ThinkingPartDelta,
3737
ToolCallPart,
3838
ToolReturnPart,
39+
UploadedFile,
3940
UserPromptPart,
4041
VideoUrl,
4142
)
@@ -49,6 +50,7 @@
4950
with try_import() as imports_successful:
5051
from google.genai.types import (
5152
CodeExecutionResult,
53+
File,
5254
GenerateContentResponse,
5355
GenerateContentResponseUsageMetadata,
5456
HarmBlockThreshold,
@@ -1706,3 +1708,28 @@ def test_map_usage():
17061708
},
17071709
)
17081710
)
1711+
1712+
1713+
async def test_uploaded_file_input(allow_model_requests: None, google_provider: GoogleProvider):
1714+
m = GoogleModel('gemini-2.5-flash', provider=google_provider)
1715+
agent = Agent(m, system_prompt='You are a helpful chatbot.')
1716+
# client = google_provider.client
1717+
# with open('tests/assets/smiley.pdf', 'rb') as f:
1718+
# google_file = client.files.upload(
1719+
# file=f,
1720+
# config={
1721+
# 'mime_type': 'application/pdf',
1722+
# },
1723+
# )
1724+
# print(google_file)
1725+
google_file = File(
1726+
name='files/6myu0b1v3mxl',
1727+
mime_type='application/pdf',
1728+
uri='https://generativelanguage.googleapis.com/v1beta/files/6myu0b1v3mxl',
1729+
)
1730+
agent = Agent(m)
1731+
1732+
result = await agent.run(['Give me a short description of this image', UploadedFile(file=google_file)])
1733+
assert result.output == snapshot(
1734+
'The image displays a classic smiley face. It features a bright yellow circular face with two simple black dot eyes and an upward-curved black line forming a smile. The yellow circle has a subtle darker yellow outline and is set against a plain white background.'
1735+
)

0 commit comments

Comments
 (0)