Skip to content

Commit 8f05227

Browse files
Andy963MarkDaoust
andauthored
aiter, anext not exist error (#127)
* aiter, anext not exist error * Un-skip test, format with black. * Fix aiter & anext implementations. --------- Co-authored-by: Mark Daoust <[email protected]>
1 parent 106daab commit 8f05227

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

google/generativeai/types/generation_types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@
2727
"GenerateContentResponse",
2828
]
2929

30+
if sys.version_info < (3, 10):
31+
32+
def aiter(obj):
33+
return obj.__aiter__()
34+
35+
async def anext(obj, default=None):
36+
try:
37+
return await obj.__anext__()
38+
except StopAsyncIteration:
39+
if default is not None:
40+
return default
41+
else:
42+
raise
43+
3044

3145
class BlockedPromptException(Exception):
3246
pass

tests/test_generative_models_async.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ async def test_basic(self):
8383

8484
self.assertEqual(response.text, "world!")
8585

86-
@unittest.skipIf(
87-
sys.version_info.major == 3 and sys.version_info.minor < 10,
88-
"streaming async requires python 3.10+",
89-
)
9086
async def test_streaming(self):
9187
# Generate text from text prompt
9288
model = generative_models.GenerativeModel(model_name="gemini-m")

0 commit comments

Comments
 (0)