Skip to content

Commit

Permalink
refactor: use try except block in lg callback
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejmajek committed Mar 7, 2025
1 parent e474164 commit 72bde7b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/rai_core/rai/agents/langchain/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

from rai.communication.hri_connector import HRIConnector, HRIMessage

logger = logging.getLogger(__name__)


class HRICallbackHandler(BaseCallbackHandler):
def __init__(
Expand All @@ -39,14 +37,18 @@ def __init__(
self.chunks_buffer = ""
self.max_buffer_size = max_buffer_size
self._buffer_lock = threading.Lock()
self.logger = logging.getLogger(__name__)

def _should_split(self, token: str) -> bool:
return token in self.splitting_chars

def _send_all_targets(self, token: str):
for connector_name, connector in self.connectors.items():
connector.send_all_targets(AIMessage(content=token))
logger.debug(f"Sent token to {connector_name}")
try:
connector.send_all_targets(AIMessage(content=token))
self.logger.debug(f"Sent token to {connector_name}")
except Exception as e:
self.logger.error(f"Failed to send token to {connector_name}: {e}")

def on_llm_new_token(self, token: str, **kwargs):
if token == "":
Expand Down

0 comments on commit 72bde7b

Please sign in to comment.