-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory creation task on stream_transcript #997
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,10 +207,21 @@ def _get_or_create_in_progress_memory(segments: List[dict]): | |
redis_db.set_in_progress_memory_id(uid, memory.id) | ||
return memory | ||
|
||
async def create_memory_creation_task(): | ||
nonlocal memory_creation_task | ||
|
||
if memory_creation_task is not None: | ||
await memory_creation_task.cancel() | ||
try: | ||
await memory_creation_task | ||
except asyncio.CancelledError: | ||
print("memory_creation_task is cancelled now") | ||
|
||
memory_creation_task = asyncio.create_task(_trigger_create_memory_with_delay(memory_creation_timeout)) | ||
|
||
def stream_transcript(segments, _): | ||
nonlocal websocket | ||
nonlocal seconds_to_trim | ||
nonlocal memory_creation_task | ||
|
||
if not segments or len(segments) == 0: | ||
return | ||
|
@@ -219,9 +230,7 @@ def stream_transcript(segments, _): | |
if seconds_to_trim is None: | ||
seconds_to_trim = segments[0]["start"] | ||
|
||
if memory_creation_task is not None: | ||
memory_creation_task.cancel() | ||
memory_creation_task = asyncio.create_task(_trigger_create_memory_with_delay(memory_creation_timeout)) | ||
asyncio.run_coroutine_threadsafe(create_memory_creation_task(), loop) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line uses - asyncio.run_coroutine_threadsafe(create_memory_creation_task(), loop)
+ loop.create_task(create_memory_creation_task()) |
||
|
||
# Segments aligning duration seconds. | ||
if seconds_to_add: | ||
|
@@ -333,7 +342,7 @@ async def receive_audio(dg_socket1, dg_socket2, soniox_socket, speechmatics_sock | |
if speechmatics_socket1 is not None: | ||
await speechmatics_socket1.send(data) | ||
|
||
if deepgram_socket is not None: | ||
if dg_socket1 is not None: | ||
elapsed_seconds = time.time() - timer_start | ||
if elapsed_seconds > speech_profile_duration or not dg_socket2: | ||
dg_socket1.send(data) | ||
Comment on lines
342
to
348
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There seems to be a change in variable name from |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entelligence.AI
The
create_memory_creation_task
function is a good addition for managing the memory creation task. However, there's an issue with the cancellation of the task. Thecancel()
method only requests cancellation and doesn't guarantee it. It would be better to handle this in a more robust way by checking if the task was cancelled successfully.