Skip to content

Commit

Permalink
test: record tests for google
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelrince committed Oct 28, 2024
1 parent 8ba9005 commit 594d4fb
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 84 deletions.
80 changes: 50 additions & 30 deletions tests/cassettes/test_google/test_google_chat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,60 @@ interactions:
User-Agent:
- python-requests/2.32.3
x-goog-api-client:
- genai-py/0.7.2 gl-python/3.11.8 grpc/1.64.1 gax/2.19.1
- genai-py/0.7.2 gl-python/3.9.18 grpc/1.67.0 gax/2.21.0
x-goog-request-params:
- model=models/gemini-1.5-flash
method: POST
uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?%24alt=json%3Benum-encoding%3Dint
response:
body:
string: !!binary |
H4sIAAAAAAAC/61Wy67URhDd36/ozIaNMwJFUUKyiAgiUhbZABKKcln02GW7mXaX1d0eXwddiX/I
Kr/Hl3Cq2p6ZezfJAiTA0496nDp1qj/eGLOrbWhcYzOl3U/mL6wY81H/lT0OmULGxraExdHGfDlb
/ny8+saRTHdyaffK22hNbxtj/WyXZA5EwVjTRLIDxQqfnYvezC73+O4Jpk07eW+4NTMCo+inlA2+
ynZz3m1tyDZlV1tvUuboKO3NG67M3MNF6sm0POFaxlcDG4th35iDrY8j/po81UeCUURlXIDpaLoI
NwPjQvz86d9kbIb1yjhERD4b746wRHAZlr15C7OerBxGoMnMHEOlzlKOdkymjXahptLQZfkQbUL+
cOtxk1m8q0nYF4AUmaNLCeuHxWQ3yFYi3+7Nr1M2iQfKvQudsQfGb1wDirNG7oIgOfcujRTlyBh5
cIkEJ9ucUMEp0v423Ia3vc0muK7PlSnF0VJkOZlmlEJu1+w5Jo38yuaJXS0Y/x40nwEJY7lSqGue
fBOeIMreIiXZb4nUWBaPCsAGfU8oxCUd2K+d9XvzcoqOk0OlumBnzTRLesWFXAU0SFvJQgAqZNxL
5vOnfyR7MDiaA+fsSdFAf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XxA3AvVbBlJKjZX+ZZeP3ML9qBYqzbnOGEkAX/Ia9hdvefu
z9/vq8srMLIneeIN3JDfjt9vB3atCy71rwE6Bxx7dt4AQHSHlafnlWRbystrK+r18F15/arEOzVT
x3HBiefV9QYeOwerVJG9Z+et++o/Df34tQz98LUMPXv6/yytX+9vtl9amx0Y2dEflC0e9Pb8bBcz
w5jf4tEZXoq6XTC8ev4/2P7+uzWQXWb086O95zfi9P7mCzS0vSBBDAAA
string: "{\n \"candidates\": [\n {\n \"content\": {\n \"parts\":
[\n {\n \"text\": \"The old, dusty attic smelled of mothballs
and forgotten dreams. Lily, a freckled ten-year-old with a thirst for adventure,
rummaged through a chest filled with her grandmother's belongings. Beneath
layers of lace and faded photographs, she found it: a leather backpack, worn
and patched, with a tarnished silver buckle.\\n\\nAs Lily lifted the backpack,
a whisper of magic swirled around her. The air grew thick with the scent of
pine and a faint, sweet perfume. It was then she noticed the silver buckle
had become warm, pulsing with a faint light. When she touched it, the backpack
suddenly unzipped, revealing a shimmering, emerald green portal.\\n\\nHesitantly,
Lily peered through. The portal shimmered, revealing a world unlike any she
had ever seen: a vibrant rainforest, teeming with exotic creatures and towering
trees that reached for the sun. Curiosity gnawed at her. This had to be the
magic backpack her grandmother had always spoken of.\\n\\nIgnoring the butterflies
in her stomach, Lily stepped through the portal. The air felt warm and humid,
filled with the scent of exotic flowers. Around her, birds with iridescent
feathers sang melodies unknown to her world. Lily's heart thumped with exhilaration.
She was a explorer, a discoverer, a traveler in a land untouched by the ordinary.\\n\\nShe
spent the next few days exploring the magical rainforest. She met talking
monkeys who taught her to swing through the canopy, fireflies that lit up
the night with their bioluminescent glow, and butterflies whose wings shimmered
with rainbows. Each day brought new wonders and adventures.\\n\\nOne day,
while exploring a hidden grotto, Lily stumbled upon a small, wounded creature.
It had emerald green scales, a long, slender tail, and enormous eyes that
mirrored her own fear. Lily knew instantly she had to help. She carefully
carried the creature back to her backpack, which now had a new, unseen compartment
for its safekeeping.\\n\\nAs Lily stepped back through the portal, she noticed
the creature had healed. Its scales shone brighter, and its eyes held a spark
of gratitude. From then on, the creature, which she named Emerald, became
her constant companion.\\n\\nBack in her attic, Lily kept her adventures a
secret. She cherished the moments she spent in the magical rainforest, knowing
that a world of wonder and possibility existed beyond the ordinary. She learned
to appreciate the beauty of her own world, seeing it through new eyes, eyes
that had witnessed magic and understood its power.\\n\\nLily's life was never
the same. She carried with her the memory of the magic backpack, a reminder
that the impossible was always just a whisper away, a reminder that adventure,
wonder, and friendship could be found in the most unexpected places. And when
she needed a break from the ordinary, all she had to do was look at the worn,
patched backpack and remember the magic it held. \\n\"\n }\n ],\n
\ \"role\": \"model\"\n },\n \"finishReason\": 1,\n \"index\":
0,\n \"safetyRatings\": [\n {\n \"category\": 9,\n \"probability\":
1\n },\n {\n \"category\": 8,\n \"probability\":
1\n },\n {\n \"category\": 7,\n \"probability\":
1\n },\n {\n \"category\": 10,\n \"probability\":
1\n }\n ]\n }\n ],\n \"usageMetadata\": {\n \"promptTokenCount\":
9,\n \"candidatesTokenCount\": 594,\n \"totalTokenCount\": 603\n },\n
\ \"modelVersion\": \"gemini-1.5-flash-001\"\n}\n"
headers:
Alt-Svc:
- h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Expand All @@ -61,11 +81,11 @@ interactions:
Content-Type:
- application/json; charset=UTF-8
Date:
- Wed, 17 Jul 2024 11:45:56 GMT
- Mon, 28 Oct 2024 15:41:36 GMT
Server:
- scaffolding on HTTPServer2
Server-Timing:
- gfet4t7; dur=5138
- gfet4t7; dur=3407
Transfer-Encoding:
- chunked
Vary:
Expand Down
102 changes: 52 additions & 50 deletions tests/cassettes/test_google/test_google_stream_chat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,62 @@ interactions:
User-Agent:
- python-requests/2.32.3
x-goog-api-client:
- genai-py/0.7.2 gl-python/3.11.8 grpc/1.64.1 gax/2.19.1
- genai-py/0.7.2 gl-python/3.9.18 grpc/1.67.0 gax/2.21.0
x-goog-request-params:
- model=models/gemini-1.5-flash
method: POST
uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent?%24alt=json%3Benum-encoding%3Dint
response:
body:
string: !!binary |
H4sIAAAAAAAC/1SQvQ7CMAyE9zxF5JkBRliZWVC3isFqDI1o46pxpUpV3p2kJf3JEFn3Xc52yklp
DRU6Yw0KebjpMipaT/OdGDshJxFkKYod9rJ5lzPt6mgRGtMjKGqCHQlr/TpteT03lMwtG2qyPWQD
vK2zvn4SenbRdlmBdYbGqJxVzp5TYfD4oQcJxqVwHR26nttOCv6Su/MwL3VdsnZfcMD/ViAs2BxJ
6hlUUD8AAAD//9Lh5aJ5ICrk56QoJCUmZxcAsUJ5YrFCSmlxSaUC0EqF8vyiPB2FktLk7NQUhcTy
xEqFzDyFkoxUsHqF/DQwO7GkJDNZhw4RARcpTkxLLakMSizJzEtH9SWyH4GhVpKanl9UiYgKWOgU
5SclJmXmZJaA5AzhUrU6BA2yoJZB5tQyyNCAOJOgrFiaJWdznOnZyAyangEAAAD//6JLek7LL0rP
LwGaoZCYm5lSXKKQnJ9UnppUDE7RufklGbqpiSDZpJzEvOzUkmI9hZDUPN3K1MQiXWBWGE3HIzwd
GxvjTMcmRtB0DAAAAP//7JS7EcJADERbUQEaIj4VEFCGDWJ8g866kXQMdI8sk5KSQAG7ye57X/nx
kbkQAj0ai8ZDUrarm5UGrgjmvY4cau5NZii+gZNbShs4Pj6Rps9Nrg4umXfp5wkThSEis2tZNgB7
1lEYgcstjB4d9yDEWrmQBju49PzJ+HEy9ruPZBy2bzJeAAAA///s1j0OgCAMhuGrcADjqo7ewwX/
gEjEtBDj7f0qzo4uugIpy/skfUUGRxcHi+5D3kZmwkTELzWbNI1FtqPYp5tNr41C0qTEBNuQPMIu
rqt9csZGxYk2coze/AEFOCq7tVtb8JFH2ssKNIY9/zhA4CImOWpHP42v02jqh2W+um2cAAAA///s
l0EOwjAMBL/iB6BKSJSP8ILQuLSiiSXHlejvWZuKG1cuc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4EMA8lk5VeCypB80FhdMXxIHDHynQ/U
AXUmdIoWNHBdBCyjknUgE1ap4NH3ROgiIfDgADg764yOSo/4zGtmgnsYy8wUNowFAAAA//+iS+YF
VrmgRFMEySmQHjJ4wAeYtOHd45IMcH0IaelmgFI6UHtRIlwe3I5FauKiZbg8YBWYmQcb/wWpgo0P
Q/MytEYF5klwYwCiBDTgVVycCez/lqeC8zmsyQCdVQKNZjmCmu35OgrI42fYO+mggMrMK4WMeiHG
x6Am6YBG41ITU2BZH7y2Auz+ctD4dRk4fIB9+PJU0JqpmLzRHDzCc7C5gRHOHGxuaAjNwQAAAAD/
/4oFAAAA//8DAKFCZN3PMQAA
string: "[{\n \"candidates\": [\n {\n \"content\": {\n \"parts\":
[\n {\n \"text\": \"Elara,\"\n }\n ],\n
\ \"role\": \"model\"\n },\n \"index\": 0,\n \"safetyRatings\":
[\n {\n \"category\": 9,\n \"probability\": 1\n },\n
\ {\n \"category\": 8,\n \"probability\": 1\n },\n
\ {\n \"category\": 7,\n \"probability\": 1\n },\n
\ {\n \"category\": 10,\n \"probability\": 1\n }\n
\ ]\n }\n ],\n \"usageMetadata\": {\n \"promptTokenCount\": 9,\n
\ \"candidatesTokenCount\": 3,\n \"totalTokenCount\": 12\n },\n \"modelVersion\":
\"gemini-1.5-flash-001\"\n}\n,\r\n{\n \"candidates\": [\n {\n \"content\":
{\n \"parts\": [\n {\n \"text\": \" a girl with
hair the color of spun gold and eyes like sparkling emeralds,\"\n }\n
\ ],\n \"role\": \"model\"\n },\n \"index\": 0,\n \"safetyRatings\":
[\n {\n \"category\": 9,\n \"probability\": 1\n },\n
\ {\n \"category\": 8,\n \"probability\": 1\n },\n
\ {\n \"category\": 7,\n \"probability\": 1\n },\n
\ {\n \"category\": 10,\n \"probability\": 1\n }\n
\ ]\n }\n ],\n \"usageMetadata\": {\n \"promptTokenCount\": 9,\n
\ \"candidatesTokenCount\": 19,\n \"totalTokenCount\": 28\n },\n \"modelVersion\":
\"gemini-1.5-flash-001\"\n}\n,\r\n{\n \"candidates\": [\n {\n \"content\":
{\n \"parts\": [\n {\n \"text\": \" had always
yearned for adventure. She devoured tales of daring explorers and fantastical
creatures,\"\n }\n ],\n \"role\": \"model\"\n },\n
\ \"index\": 0,\n \"safetyRatings\": [\n {\n \"category\":
9,\n \"probability\": 2\n },\n {\n \"category\":
8,\n \"probability\": 1\n },\n {\n \"category\":
7,\n \"probability\": 1\n },\n {\n \"category\":
10,\n \"probability\": 1\n }\n ]\n }\n ],\n \"usageMetadata\":
{\n \"promptTokenCount\": 9,\n \"candidatesTokenCount\": 37,\n \"totalTokenCount\":
46\n },\n \"modelVersion\": \"gemini-1.5-flash-001\"\n}\n,\r\n{\n \"candidates\":
[\n {\n \"content\": {\n \"parts\": [\n {\n \"text\":
\" her heart longing for something more than the quiet life of her village.
Her grandmother, a wizened woman with a mischievous twinkle in her eye, sensed
her\"\n }\n ],\n \"role\": \"model\"\n },\n \"index\":
0,\n \"safetyRatings\": [\n {\n \"category\": 9,\n \"probability\":
2\n },\n {\n \"category\": 8,\n \"probability\":
1\n },\n {\n \"category\": 7,\n \"probability\":
1\n },\n {\n \"category\": 10,\n \"probability\":
1\n }\n ]\n }\n ],\n \"usageMetadata\": {\n \"promptTokenCount\":
9,\n \"candidatesTokenCount\": 69,\n \"totalTokenCount\": 78\n },\n
\ \"modelVersion\": \"gemini-1.5-flash-001\"\n}\n,\r\n{\n \"candidates\":
[\n {\n \"finishReason\": 3,\n \"index\": 0,\n \"safetyRatings\":
[\n {\n \"category\": 9,\n \"probability\": 3\n },\n
\ {\n \"category\": 8,\n \"probability\": 1\n },\n
\ {\n \"category\": 7,\n \"probability\": 1\n },\n
\ {\n \"category\": 10,\n \"probability\": 1\n }\n
\ ]\n }\n ],\n \"usageMetadata\": {\n \"promptTokenCount\": 9,\n
\ \"candidatesTokenCount\": 69,\n \"totalTokenCount\": 78\n },\n \"modelVersion\":
\"gemini-1.5-flash-001\"\n}\n]"
headers:
Alt-Svc:
- h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Expand All @@ -81,11 +83,11 @@ interactions:
Content-Type:
- application/json; charset=UTF-8
Date:
- Wed, 17 Jul 2024 11:45:57 GMT
- Mon, 28 Oct 2024 15:41:37 GMT
Server:
- scaffolding on HTTPServer2
Server-Timing:
- gfet4t7; dur=958
- gfet4t7; dur=1447
Transfer-Encoding:
- chunked
Vary:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@pytest.mark.vcr
def test_google_chat(tracer_init):
genai.configure(transport='rest')
genai.configure(transport="rest")
model = genai.GenerativeModel("gemini-1.5-flash")
response = model.generate_content("Write a story about a magic backpack.")
assert len(response.text) > 0
Expand All @@ -16,7 +16,7 @@ def test_google_chat(tracer_init):
@pytest.mark.vcr
@pytest.mark.asyncio
async def test_google_async_chat(tracer_init):
genai.configure(transport='rest')
genai.configure(transport="rest")
model = genai.GenerativeModel("gemini-1.5-flash")
response = await model.generate_content_async("Write a story about a magic backpack.")
assert len(response.text) > 0
Expand All @@ -25,7 +25,7 @@ async def test_google_async_chat(tracer_init):

@pytest.mark.vcr
def test_google_stream_chat(tracer_init):
genai.configure(transport='rest')
genai.configure(transport="rest")
model = genai.GenerativeModel("gemini-1.5-flash")
stream = model.generate_content(
"Write a story about a magic backpack.",
Expand All @@ -40,7 +40,7 @@ def test_google_stream_chat(tracer_init):
@pytest.mark.vcr
@pytest.mark.asyncio
async def test_google_async_stream_chat(tracer_init):
genai.configure(transport='rest')
genai.configure(transport="rest")
model = genai.GenerativeModel("gemini-1.5-flash")
stream = await model.generate_content_async(
"Write a story about a magic backpack.",
Expand Down

0 comments on commit 594d4fb

Please sign in to comment.