From c5cc046646345b4357dced4574a3d278f416c664 Mon Sep 17 00:00:00 2001 From: Steve Androulakis Date: Fri, 7 Jun 2024 23:17:13 +0000 Subject: [PATCH] log warning if messages received while chat is closed --- bedrock/entity/get_history.py | 5 +++-- bedrock/entity/workflows.py | 5 +++++ bedrock/signals_and_queries/get_history.py | 7 +++++++ bedrock/signals_and_queries/workflows.py | 7 +++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/bedrock/entity/get_history.py b/bedrock/entity/get_history.py index 2314dbce..1600886e 100644 --- a/bedrock/entity/get_history.py +++ b/bedrock/entity/get_history.py @@ -22,8 +22,9 @@ async def main(): # Queries the workflow for the conversation summary summary = await handle.query(EntityBedrockWorkflow.get_summary_from_history) - print("Conversation Summary:") - print(summary) + if summary is not None: + print("Conversation Summary:") + print(summary) if __name__ == "__main__": diff --git a/bedrock/entity/workflows.py b/bedrock/entity/workflows.py index 51c1de93..e782935e 100644 --- a/bedrock/entity/workflows.py +++ b/bedrock/entity/workflows.py @@ -122,6 +122,11 @@ async def run( @workflow.signal async def user_prompt(self, prompt: str) -> None: + # Chat ended but the workflow is waiting for a chat summary to be generated + if self.chat_ended: + workflow.logger.warn(f"Message dropped due to chat closed: {prompt}") + return + self.prompt_queue.append(prompt) @workflow.signal diff --git a/bedrock/signals_and_queries/get_history.py b/bedrock/signals_and_queries/get_history.py index 0dd19c43..2eed3717 100644 --- a/bedrock/signals_and_queries/get_history.py +++ b/bedrock/signals_and_queries/get_history.py @@ -18,6 +18,13 @@ async def main(): print( *(f"{speaker.title()}: {message}\n" for speaker, message in history), sep="\n" ) + + # Queries the workflow for the conversation summary + summary = await handle.query(SignalQueryBedrockWorkflow.get_summary_from_history) + + if summary is not None: + print("Conversation Summary:") + print(summary) if __name__ == "__main__": diff --git a/bedrock/signals_and_queries/workflows.py b/bedrock/signals_and_queries/workflows.py index 93059667..adeffa10 100644 --- a/bedrock/signals_and_queries/workflows.py +++ b/bedrock/signals_and_queries/workflows.py @@ -16,6 +16,7 @@ def __init__(self) -> None: self.conversation_history: List[Tuple[str, str]] = [] self.prompt_queue: Deque[str] = deque() self.conversation_summary = "" + self.chat_timeout: bool = False @workflow.run async def run(self, inactivity_timeout_minutes: int) -> str: @@ -33,6 +34,7 @@ async def run(self, inactivity_timeout_minutes: int) -> str: ) # If timeout was reached except asyncio.TimeoutError: + self.chat_timeout = True workflow.logger.info("Chat closed due to inactivity") # End the workflow break @@ -68,6 +70,11 @@ async def run(self, inactivity_timeout_minutes: int) -> str: @workflow.signal async def user_prompt(self, prompt: str) -> None: + # Chat timed out but the workflow is waiting for a chat summary to be generated + if self.chat_timeout: + workflow.logger.warn(f"Message dropped due to chat closed: {prompt}") + return + self.prompt_queue.append(prompt) @workflow.query