File tree Expand file tree Collapse file tree 2 files changed +97
-0
lines changed
Expand file tree Collapse file tree 2 files changed +97
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 3636 ThinkingPartDelta ,
3737 ToolCallPart ,
3838 ToolReturnPart ,
39+ UploadedFile ,
3940 UserPromptPart ,
4041 VideoUrl ,
4142)
5758 MediaModality ,
5859 ModalityTokenCount ,
5960 Outcome ,
61+ File ,
6062 )
6163
6264 from pydantic_ai .models .google import GoogleModel , GoogleModelSettings , _metadata_as_usage # type: ignore
@@ -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+ )
You can’t perform that action at this time.
0 commit comments