-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from bolna-ai/feat/BOLNA-15/web-calling-with-…
…deepgram-enhancements Feat/bolna 15/web calling with deepgram enhancements
- Loading branch information
Showing
22 changed files
with
633 additions
and
352 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from bolna.helpers.logger_config import configure_logger | ||
|
||
logger = configure_logger(__name__) | ||
|
||
class MarkEventMetaData: | ||
def __init__(self): | ||
self.mark_event_meta_data = {} | ||
|
||
def update_data(self, mark_id, value): | ||
logger.info(f"Updating mark_id = {mark_id} with value = {value}") | ||
self.mark_event_meta_data[mark_id] = value | ||
|
||
def fetch_data(self, mark_id): | ||
logger.info(f"Fetching meta data details for mark_id = {mark_id}") | ||
return self.mark_event_meta_data.pop(mark_id, {}) | ||
|
||
def clear_data(self): | ||
logger.info(f"Clearing mark meta data dict") | ||
self.mark_event_meta_data = {} | ||
|
||
def __str__(self): | ||
return f"{self.mark_event_meta_data}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import asyncio | ||
import inspect | ||
from bolna.helpers.logger_config import configure_logger | ||
|
||
logger = configure_logger(__name__) | ||
|
||
class ObservableVariable: | ||
def __init__(self, value): | ||
self._value = value | ||
self._observers = [] | ||
|
||
def add_observer(self, observer): | ||
""" | ||
Register an observer function. | ||
The observer can be a synchronous function or an async function. | ||
""" | ||
self._observers.append(observer) | ||
|
||
@property | ||
def value(self): | ||
"""Getter for the observable variable.""" | ||
return self._value | ||
|
||
@value.setter | ||
def value(self, new_value): | ||
"""Setter that updates the variable and notifies observers if the value changes.""" | ||
if self._value != new_value: | ||
self._value = new_value | ||
self._notify_observers(new_value) | ||
|
||
def _notify_observers(self, new_value): | ||
""" | ||
Notify each observer about the new value. | ||
Async observers are scheduled appropriately. | ||
""" | ||
for observer in self._observers: | ||
if inspect.iscoroutinefunction(observer): | ||
try: | ||
# If an event loop is already running, schedule the async observer | ||
loop = asyncio.get_running_loop() | ||
loop.create_task(observer(new_value)) | ||
except RuntimeError: | ||
# No running loop; run the async function in a temporary event loop | ||
asyncio.run(observer(new_value)) | ||
else: | ||
# Synchronous observer: call it directly | ||
observer(new_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.