mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
remove infinit loop for streaming
This commit is contained in:
parent
9ea0c89a2d
commit
1f7c21fd1b
1 changed files with 26 additions and 26 deletions
|
@ -109,6 +109,7 @@ class ResponsesAPIStreamingIterator(BaseResponsesAPIStreamingIterator):
|
||||||
|
|
||||||
async def __anext__(self) -> ResponsesAPIStreamingResponse:
|
async def __anext__(self) -> ResponsesAPIStreamingResponse:
|
||||||
try:
|
try:
|
||||||
|
while True:
|
||||||
# Get the next chunk from the stream
|
# Get the next chunk from the stream
|
||||||
try:
|
try:
|
||||||
chunk = await self.stream_iterator.__anext__()
|
chunk = await self.stream_iterator.__anext__()
|
||||||
|
@ -122,8 +123,7 @@ class ResponsesAPIStreamingIterator(BaseResponsesAPIStreamingIterator):
|
||||||
raise StopAsyncIteration
|
raise StopAsyncIteration
|
||||||
elif result is not None:
|
elif result is not None:
|
||||||
return result
|
return result
|
||||||
else:
|
# If result is None, continue the loop to get the next chunk
|
||||||
return await self.__anext__()
|
|
||||||
|
|
||||||
except httpx.HTTPError as e:
|
except httpx.HTTPError as e:
|
||||||
# Handle HTTP errors
|
# Handle HTTP errors
|
||||||
|
@ -170,6 +170,7 @@ class SyncResponsesAPIStreamingIterator(BaseResponsesAPIStreamingIterator):
|
||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
try:
|
try:
|
||||||
|
while True:
|
||||||
# Get the next chunk from the stream
|
# Get the next chunk from the stream
|
||||||
try:
|
try:
|
||||||
chunk = next(self.stream_iterator)
|
chunk = next(self.stream_iterator)
|
||||||
|
@ -183,8 +184,7 @@ class SyncResponsesAPIStreamingIterator(BaseResponsesAPIStreamingIterator):
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
elif result is not None:
|
elif result is not None:
|
||||||
return result
|
return result
|
||||||
else:
|
# If result is None, continue the loop to get the next chunk
|
||||||
return self.__next__()
|
|
||||||
|
|
||||||
except httpx.HTTPError as e:
|
except httpx.HTTPError as e:
|
||||||
# Handle HTTP errors
|
# Handle HTTP errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue