From 4d009a94b9f672580aea7f1d1be6c1e08d034823 Mon Sep 17 00:00:00 2001 From: estill01 Date: Tue, 29 Aug 2023 15:44:44 -0700 Subject: [PATCH] Add async iterator to fix/enable streaming responses --- litellm/utils.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index 7633950abe3..b24606f9e08 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -1568,6 +1568,7 @@ def get_or_generate_uuid(): uuid_value = uuid_value.strip() else: raise FileNotFoundError + except FileNotFoundError: # Generate a new UUID if the file doesn't exist or is empty new_uuid = uuid.uuid4() @@ -1636,7 +1637,10 @@ class CustomStreamWrapper: def __iter__(self): return self - + + def __aiter__(self): + return self + def logging(self, text): if self.logging_obj: self.logging_obj.post_call(text) @@ -1743,6 +1747,12 @@ class CustomStreamWrapper: return {"choices": [{"delta": completion_obj}]} except: raise StopIteration + + async def __anext__(self): + try: + return next(self) + except StopIteration: + raise StopAsyncIteration ########## Reading Config File ############################