🔧 chore(callback.py): refactor StreamingLLMCallbackHandler constructor to improve code readability and maintainability

🐛 fix(callback.py): assign websocket attribute from chat_service.active_connections to self.websocket to avoid potential bugs
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-10-04 17:42:12 -03:00
commit 79334a10de

View file

@ -124,7 +124,9 @@ class StreamingLLMCallbackHandler(BaseCallbackHandler):
"""Callback handler for streaming LLM responses."""
def __init__(self, client_id: str):
self.chat_service = get_chat_service()
self.client_id = client_id
self.websocket = self.chat_service.active_connections[self.client_id]
def on_llm_new_token(self, token: str, **kwargs: Any) -> None:
resp = ChatResponse(message=token, type="stream", intermediate_steps="")