Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
AI Tutor
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Salma Mohammed Hamed
AI Tutor
Commits
ec252519
Commit
ec252519
authored
Oct 16, 2025
by
SalmaMohammedHamedMustafa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add life span manager to guarantee graceful db shutdown
parent
5b55ec50
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
92 additions
and
152 deletions
+92
-152
good_test.wav
self_hosted_env/good_test.wav
+0
-0
test_0.3.wav
self_hosted_env/test_0.3.wav
+0
-0
test_sequence.wav
self_hosted_env/test_sequence.wav
+0
-0
curriculum_structure.py
self_hosted_env/voice_agent/curriculum_structure.py
+1
-1
main.py
self_hosted_env/voice_agent/main.py
+73
-131
agent_service.py
self_hosted_env/voice_agent/services/agent_service.py
+0
-3
response_manager.py
self_hosted_env/voice_agent/services/response_manager.py
+18
-17
No files found.
self_hosted_env/good_test.wav
deleted
100644 → 0
View file @
5b55ec50
File deleted
self_hosted_env/test_0.3.wav
deleted
100644 → 0
View file @
5b55ec50
File deleted
self_hosted_env/test_sequence.wav
deleted
100644 → 0
View file @
5b55ec50
File deleted
self_hosted_env/voice_agent/curriculum_structure.py
View file @
ec252519
self_hosted_env/voice_agent/main.py
View file @
ec252519
This diff is collapsed.
Click to expand it.
self_hosted_env/voice_agent/services/agent_service.py
View file @
ec252519
...
...
@@ -293,6 +293,3 @@ class AgentService:
except
Exception
as
e
:
logger
.
error
(
f
"Error closing connection pools: {e}"
)
def
__del__
(
self
):
"""Destructor to ensure connection pools are closed"""
self
.
close
()
\ No newline at end of file
self_hosted_env/voice_agent/services/response_manager.py
View file @
ec252519
...
...
@@ -40,43 +40,44 @@ class ResponseManager:
def
get_response
(
self
,
student_id
:
str
)
->
Dict
:
"""
Atomically gets the response for a student and removes it from Redis
to ensure it's claimed only once.
Gets the response for a student without deleting it.
This allows the client to safely retry the request if it fails.
The key will be cleaned up automatically by Redis when its TTL expires.
"""
key
=
self
.
_get_key
(
student_id
)
# Use a pipeline to get and delete the key in a single, atomic operation
pipe
=
self
.
redis
.
pipeline
()
pipe
.
get
(
key
)
pipe
.
delete
(
key
)
results
=
pipe
.
execute
()
json_value
=
results
[
0
]
# 1. Use a simple, non-destructive GET command. No pipeline needed.
json_value
=
self
.
redis
.
get
(
key
)
if
not
json_value
:
# If nothing was found, return the same empty structure as the old class
return
{
"text"
:
None
,
"audio_filename"
:
None
,
"audio_bytes"
:
None
}
return
{
"text"
:
None
,
"audio_filepath"
:
None
,
"audio_bytes"
:
None
}
#
If data was found, decode it
#
2. Decode the payload as before.
payload
=
json
.
loads
(
json_value
)
# Decode the Base64 string back into binary audio data
if
payload
.
get
(
"audio_bytes_b64"
):
payload
[
"audio_bytes"
]
=
base64
.
b64decode
(
payload
[
"audio_bytes_b64"
])
else
:
payload
[
"audio_bytes"
]
=
None
# Remove the temporary key before returning
del
payload
[
"audio_bytes_b64"
]
return
payload
def
clear_response
(
self
,
student_id
:
str
)
->
None
:
"""Clears a response for a specific student from Redis."""
"""
Clears a response for a specific student from Redis.
This is still important to call at the *beginning* of a new /chat request
to ensure old data is invalidated immediately.
"""
key
=
self
.
_get_key
(
student_id
)
self
.
redis
.
delete
(
key
)
def
is_response_fresh
(
self
,
student_id
:
str
,
max_age_seconds
:
int
=
300
)
->
bool
:
"""Checks if a response exists in Redis for the given student."""
def
is_response_fresh
(
self
,
student_id
:
str
)
->
bool
:
"""
Checks if a response exists in Redis for the given student.
This is much simpler and more reliable now.
"""
key
=
self
.
_get_key
(
student_id
)
# redis.exists()
is the direct equivalent of checking if the key is present
# redis.exists()
returns the number of keys that exist (0 or 1 in this case).
return
self
.
redis
.
exists
(
key
)
>
0
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment