AduragbemiOyin commited on
Commit
c732201
1 Parent(s): 2c74bf9

Added streaming file

Browse files
Files changed (1) hide show
  1. streaming.py +11 -0
streaming.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_core.callbacks.base import BaseCallbackHandler
2
+
3
+ class StreamHandler(BaseCallbackHandler):
4
+
5
+ def __init__(self, container, initial_text=""):
6
+ self.container = container
7
+ self.text = initial_text
8
+
9
+ def on_llm_new_token(self, token: str, **kwargs):
10
+ self.text += token
11
+ self.container.markdown(self.text)