Spaces:
Sleeping
Sleeping
Commit
·
6287af1
1
Parent(s):
78247b5
fix
Browse files- callback_handler.py +12 -0
callback_handler.py
CHANGED
|
@@ -42,3 +42,15 @@ class StreamingStdOutCallBackHandler(BaseCallbackHandler):
|
|
| 42 |
|
| 43 |
def on_llm_end(self, response: str, **kwargs: Any) -> None:
|
| 44 |
"""Run when LLM ends running."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def on_llm_end(self, response: str, **kwargs: Any) -> None:
|
| 44 |
"""Run when LLM ends running."""
|
| 45 |
+
|
| 46 |
+
class QueueCallback(BaseCallbackHandler):
|
| 47 |
+
"""Callback handler for streaming LLM responses to a queue."""
|
| 48 |
+
|
| 49 |
+
def __init__(self, q):
|
| 50 |
+
self.q = q
|
| 51 |
+
|
| 52 |
+
def on_llm_new_token(self, token: str, **kwargs: any) -> None:
|
| 53 |
+
self.q.put(token)
|
| 54 |
+
|
| 55 |
+
def on_llm_end(self, *args, **kwargs: any) -> None:
|
| 56 |
+
return self.q.empty()
|