Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sleep to fix lag in chat stream #10339

Merged
merged 3 commits into from
Feb 9, 2024
Merged
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
4 changes: 3 additions & 1 deletion llama_index/chat_engine/types.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -141,6 +142,7 @@ async def awrite_response_to_history(
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
Expand All @@ -165,7 +167,7 @@ def response_gen(self) -> Generator[str, None, None]:
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]:
Expand Down
Loading