diff --git a/llama_index/chat_engine/types.py b/llama_index/chat_engine/types.py index 52848e161190d4c2ffcf1d2f1c2d0aa188aed0c0..0d4b3fd39d0cae1d0552b73901936c68c6190970 100644 --- a/llama_index/chat_engine/types.py +++ b/llama_index/chat_engine/types.py @@ -1,6 +1,7 @@ import asyncio import logging import queue +import time from abc import ABC, abstractmethod from dataclasses import dataclass, field from enum import Enum @@ -148,6 +149,7 @@ class StreamingAgentChatResponse: self._is_function = is_function(chat.message) self.aput_in_queue(chat.delta) final_text += chat.delta or "" + self._new_item_event.set() if self._is_function is False: self._is_function_false_event.set() if self._is_function is not None: # if loop has gone through iteration @@ -172,7 +174,7 @@ class StreamingAgentChatResponse: yield delta except queue.Empty: # Queue is empty, but we're not done yet - continue + time.sleep(0.01) self.response = self._unformatted_response.strip() async def async_response_gen(self) -> AsyncGenerator[str, None]: