Spaces:
Sleeping
Sleeping
Download streaming_response.py from Jobanpreet/LinkedInpost: direct link, hf CLI and curl.
- Browser
- Download file 356 Bytes
-
https://huggingface.co/spaces/Jobanpreet/LinkedInpost/resolve/main/streaming_response.py
- Command line
-
hf download hf://spaces/Jobanpreet/LinkedInpost/streaming_response.py
-
curl -L -o streaming_response.py https://huggingface.co/spaces/Jobanpreet/LinkedInpost/resolve/main/streaming_response.py
356 Bytes
| from langchain.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) -> None: | |
| self.text += token | |
| self.container.markdown(self.text) | |