Skip to content

Commit

Permalink
aiter, anext not exist error (#127)
Browse files Browse the repository at this point in the history
* aiter, anext not exist error

* Un-skip test, format with black.

* Fix aiter & anext implementations.

---------

Co-authored-by: Mark Daoust <markdaoust@google.com>
  • Loading branch information
Andy963 and MarkDaoust committed Dec 19, 2023
1 parent 106daab commit 8f05227
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 14 additions & 0 deletions google/generativeai/types/generation_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@
"GenerateContentResponse",
]

if sys.version_info < (3, 10):

def aiter(obj):
return obj.__aiter__()

async def anext(obj, default=None):
try:
return await obj.__anext__()
except StopAsyncIteration:
if default is not None:
return default
else:
raise


class BlockedPromptException(Exception):
pass
Expand Down
4 changes: 0 additions & 4 deletions tests/test_generative_models_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ async def test_basic(self):

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

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

0 comments on commit 8f05227

Please sign in to comment.