Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions litellm/llms/vertex_ai/vertex_ai_non_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TextStreamer:

def __init__(self, text):
self.text = text.split() # let's assume words as a streaming unit
self._len = len(self.text)
self.index = 0

def __iter__(self):
Expand All @@ -50,9 +51,11 @@ def __aiter__(self):
return self

async def __anext__(self):
if self.index < len(self.text):
result = self.text[self.index]
self.index += 1
idx = self.index
if idx < self._len:
# Avoid attribute lookups in hot path.
result = self.text[idx]
self.index = idx + 1
return result
else:
raise StopAsyncIteration # once we run out of data to stream, we raise this error
Expand Down