ciorant commited on
Commit
9e1b307
·
verified ·
1 Parent(s): 9e9e2c1

Update src/chatbot.py

Browse files
Files changed (1) hide show
  1. src/chatbot.py +6 -3
src/chatbot.py CHANGED
@@ -19,16 +19,19 @@ from langchain.callbacks.base import BaseCallbackHandler
19
  class StreamHandler(BaseCallbackHandler):
20
  def __init__(self):
21
  self.current_text = ""
22
-
23
 
24
  def on_llm_new_token(self, token: str, **kwargs):
25
- print(token, end="", flush=True) # stream to console
26
  self.current_text += token
 
 
 
27
 
28
- def get_text(self):
29
  return self.current_text
30
 
31
 
 
32
  class BioethicsChatbot:
33
  def __init__(self, data_dir: str="data/sample_papers"):
34
  self.processor = DocumentProcessor()
 
19
  class StreamHandler(BaseCallbackHandler):
20
  def __init__(self):
21
  self.current_text = ""
22
+ self.placeholder = None # we attach this later
23
 
24
  def on_llm_new_token(self, token: str, **kwargs):
 
25
  self.current_text += token
26
+ if self.placeholder is not None:
27
+ # Show partial text with a cursor ▌
28
+ self.placeholder.markdown(self.current_text + "▌")
29
 
30
+ def get_text(self):
31
  return self.current_text
32
 
33
 
34
+
35
  class BioethicsChatbot:
36
  def __init__(self, data_dir: str="data/sample_papers"):
37
  self.processor = DocumentProcessor()