Skip to content

Commit

Permalink
Merge pull request #2 from steveandroulakis/brendan-bedrock-sample
Browse files Browse the repository at this point in the history
log warning if messages received while chat is closed
  • Loading branch information
brendan-myers authored Jun 7, 2024
2 parents a6947f2 + c5cc046 commit 0eeccc6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bedrock/entity/get_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
5 changes: 5 additions & 0 deletions bedrock/entity/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions bedrock/signals_and_queries/get_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
7 changes: 7 additions & 0 deletions bedrock/signals_and_queries/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0eeccc6

Please sign in to comment.