Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions unity/conversation_manager_2/prompt_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from collections import deque


Expand All @@ -10,18 +12,22 @@ class NotificationBar:
def __init__(self):
self.notifs = []

def push_notif(self, n, timestamp=None):
def push_notif(self, type, n, timestamp=None):
if timestamp:
timestamp = timestamp.strftime("%A, %B %d, %Y at %I:%M %p")
str_timestamp = timestamp.strftime("%A, %B %d, %Y at %I:%M %p")

self.notifs.append({"content": n, "timestamp": timestamp})
self.notifs.append({"type": type, "content": n, "str_timestamp": str_timestamp, "timestamp": timestamp})

def clear(self):
self.notifs = []
def clear(self, timestamp=None):
if timestamp:
# print("comparing to", timestamp)
self.notifs = [n for n in self.notifs if n["timestamp"] > timestamp]
else:
self.notifs = []

def __str__(self):
return "\n".join(
[f"[Notification @ {n['timestamp']}] {n['content']}" for n in self.notifs]
[f"[{n['type'].title()} Notification @ {n['str_timestamp']}] {n['content']}" for n in self.notifs]
)


Expand Down
71 changes: 42 additions & 29 deletions unity/conversation_manager_2/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,29 @@ def __init__(self, phone_contacts_map: dict, email_contacts_map: dict):
def push_notif(self, notif, timestamp=None):
self.notifications.push_notif(notif, timestamp)

def clear_notifications(self):
self.notifications.clear()
def clear_notifications(self, timestamp=None):
print(self.notifications.notifs)
self.notifications.clear(timestamp=timestamp)

def push_event(self, event: Event):
contact = self.phone_contacts_map.get(
event.contact
) or self.email_contacts_map.get(event.contact)
if not contact:
# will deal with this later
# but in general probably either create a new contact here or
# add a new anon contact
...
contact_added = False
if not self.is_contact_in_active_conversations(contact=contact):
on_phone = False
if isinstance(event, PhoneCallStarted):
on_phone = True
self.add_contact_to_active_conversations(contact, on_phone, event.timestamp)
contact_added = True

active_c = self.active_conversations[contact.id]
if hasattr(event, "contact"):
contact = self.phone_contacts_map.get(
event.contact
) or self.email_contacts_map.get(event.contact)
if not contact:
# will deal with this later
# but in general probably either create a new contact here or
# add a new anon contact
...
contact_added = False
if not self.is_contact_in_active_conversations(contact=contact):
on_phone = False
if isinstance(event, PhoneCallStarted):
on_phone = True
self.add_contact_to_active_conversations(contact, on_phone, event.timestamp)
contact_added = True

active_c = self.active_conversations[contact.id]

if isinstance(event, PhoneCallInitiated):
active_c.push_message(
Expand All @@ -53,7 +55,7 @@ def push_event(self, event: Event):
),
)
self.notifications.push_notif(
f"Phone Call Initiated by '{contact.name}'", event.timestamp
"comms", f"Phone Call Initiated by '{contact.name}'", event.timestamp
)
elif isinstance(event, PhoneCallStarted):
active_c.push_message(
Expand All @@ -63,15 +65,15 @@ def push_event(self, event: Event):
),
)
self.notifications.push_notif(
f"Phone Call Started with '{contact.name}'", event.timestamp
"comms", f"Phone Call Started with '{contact.name}'", event.timestamp
)
elif isinstance(event, PhoneUtterance):
active_c.push_message(
"phone",
message=ThreadMessage(contact.name, event.content, event.timestamp),
)
self.notifications.push_notif(
f"Phone utterance recieved from '{contact.name}'", event.timestamp
"comms", f"Phone utterance recieved from '{contact.name}'", event.timestamp
)
elif isinstance(event, PhoneCallEnded):
active_c.push_message(
Expand All @@ -81,7 +83,7 @@ def push_event(self, event: Event):
),
)
self.notifications.push_notif(
f"Phone Call Ended with '{contact.name}'", event.timestamp
"comms", f"Phone Call Ended with '{contact.name}'", event.timestamp
)

elif isinstance(event, SMSRecieved):
Expand All @@ -90,7 +92,7 @@ def push_event(self, event: Event):
message=ThreadMessage(contact.name, event.content, event.timestamp),
)
self.notifications.push_notif(
f"SMS recieved recieved from '{contact.name}'", event.timestamp
"comms", f"SMS recieved recieved from '{contact.name}'", event.timestamp
)
elif isinstance(event, EmailRecieved):
...
Expand All @@ -100,14 +102,25 @@ def push_event(self, event: Event):
"sms", message=ThreadMessage("You", event.content, event.timestamp)
)
self.notifications.push_notif(
f"SMS sent to '{contact.name}'", event.timestamp
"comms", f"SMS sent to '{contact.name}'", event.timestamp
)

if contact_added:

elif isinstance(event, ConductorQuerySent):
self.notifications.push_notif(
"conductor", f"Query '{event.query}' with id={event.id} sent and recieved by conductor and is being processed...",
event.timestamp
)

elif isinstance(event, ConductorResult):
self.notifications.push_notif(
f"Added contact '{contact.name}' to active conversations",
event.timestamp,
"conductor", f"Query with id={event.id} result: {event.result}", event.timestamp
)
if hasattr(event, "contact"):
if contact_added:
self.notifications.push_notif(
"comms", f"Added contact '{contact.name}' to active conversations",
event.timestamp,
)

def add_contact_to_active_conversations(
self, contact, on_phone=False, timestamp=None
Expand Down
Loading