Chat_bot / streaming.py
Tammy's picture
Streaming capabilities
e829d04 verified
raw
history blame contribute delete
350 Bytes
from langchain_core.callbacks.base import BaseCallbackHandler
class StreamHandler(BaseCallbackHandler):
def __init__(self, container, initial_text=""):
self.container = container
self.text = initial_text
def on_llm_new_token(self, token: str, **kwargs):
self.text += token
self.container.markdown(self.text)