Skip to content

Commit a3a005a

Browse files
committed
Add a test uploading from a file-like IO object
Change-Id: I572f02ed98b9ca45299b76e7a01695fdcf917e1e
1 parent 0cfc191 commit a3a005a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

samples/files.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ def test_files_create_pdf(self):
8383
print(response.text)
8484
# [END files_create_pdf]
8585

86+
def test_files_create_from_IO(self):
87+
# [START files_create_io]
88+
# You can pass a file-like object, instead of a path.
89+
# Useful for streaming.
90+
model = genai.GenerativeModel("gemini-1.5-flash")
91+
fpath = media / "test.pdf"
92+
with open(fpath, "rb") as f:
93+
sample_pdf = genai.upload_file(f, mime_type="application/pdf")
94+
response = model.generate_content(["Give me a summary of this pdf file.", sample_pdf])
95+
print(response.text)
96+
# [END files_create_io]
97+
8698
def test_files_list(self):
8799
# [START files_list]
88100
print("My files:")

0 commit comments

Comments
 (0)