-
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
Conversation
WalkthroughThis update refactors the Changes
Uplevel your code reviews with Entelligence.AI ProEntelligence.AI ProIf you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, Entelligence.AI Pro is free for open source projects. |
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.
Files selected (1)
- backend/routers/transcribe_v2.py (3)
Review comments generated (4)
- Review: 3
- LGTM: 1
Tips
Chat with Entelligence.AI Bot (@Entelligence.AI
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@Entelligence.AI
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@Entelligence.AI: ignore
anywhere in the PR description to pause further reviews from the bot.
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)) | ||
|
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.
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. The cancel()
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.
if memory_creation_task is not None:
memory_creation_task.cancel()
try:
await memory_creation_task
except asyncio.CancelledError:
print("memory_creation_task is cancelled now")
+ if not memory_creation_task.cancelled():
+ print("Failed to cancel memory_creation_task")
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This line uses asyncio.run_coroutine_threadsafe
which is generally used when you want to schedule a coroutine from a different thread. If this code is running within an event loop, it would be more appropriate to use asyncio.create_task
or loop.create_task
. Please ensure that this usage is necessary and correct in your context.
- asyncio.run_coroutine_threadsafe(create_memory_creation_task(), loop)
+ loop.create_task(create_memory_creation_task())
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) |
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.
Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [345-349]
There seems to be a change in variable name from deepgram_socket
to dg_socket1
. This change itself is not an issue, but please make sure that all references to deepgram_socket
are updated to dg_socket1
to maintain consistency and avoid potential NameErrors.
Summary by Entelligence.AI
stream_transcript
function intranscribe_v2.py
for better task management and error handling. This update improves the stability and reliability of the transcription service.receive_audio
function to optimize socket usage, enhancing the performance and efficiency of audio data transmission.