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
60ce4a8c
Commit
60ce4a8c
authored
Dec 04, 2025
by
salma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
faster and cheeper mcq generation
parent
67972c15
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
24 deletions
+32
-24
mcq_service.py
self_hosted_env/voice_agent/services/mcq_service.py
+4
-0
pgvector_service.py
self_hosted_env/voice_agent/services/pgvector_service.py
+28
-24
No files found.
self_hosted_env/voice_agent/services/mcq_service.py
View file @
60ce4a8c
...
...
@@ -98,12 +98,16 @@ class MCQService:
# Slice to exact number requested (in case we generated extras)
final_set
=
accepted_mcqs
[:
num_questions
]
self
.
pgvector
.
insert_mcqs
(
final_set
)
for
q
in
final_set
:
q
.
pop
(
'embedding'
,
None
)
return
final_set
# If we failed to generate enough
if
not
accepted_mcqs
:
logger
.
warning
(
f
"Could not generate unique questions for {concept} after {attempts} attempts."
)
return
[]
return
accepted_mcqs
...
...
self_hosted_env/voice_agent/services/pgvector_service.py
View file @
60ce4a8c
...
...
@@ -546,31 +546,35 @@ class PGVectorService:
def
get_mcqs
(
self
,
curriculum
:
str
,
grade
:
str
,
subject
:
str
,
unit
:
str
,
concept
:
str
,
is_arabic
:
bool
,
limit
:
Optional
[
int
]
=
10
)
->
List
[
Dict
]:
"""
Retrieves MCQs for a specific topic and language, now filtering by curriculum.
If limit is None, it retrieves all matching questions.
"""
with
self
.
pool_handler
.
get_connection
()
as
conn
:
with
conn
.
cursor
(
cursor_factory
=
RealDictCursor
)
as
cur
:
# --- UPDATED SELECT AND WHERE CLAUSE ---
query
=
"""
SELECT *
FROM mcq_questions
WHERE curriculum =
%
s AND grade =
%
s AND subject =
%
s AND unit =
%
s AND concept =
%
s AND is_arabic =
%
s
ORDER BY created_at DESC
"""
params
=
(
curriculum
,
grade
,
subject
,
unit
,
concept
,
is_arabic
)
if
limit
is
not
None
:
query
+=
" LIMIT
%
s;"
params
+=
(
limit
,)
else
:
query
+=
";"
"""
Retrieves MCQs for a specific topic and language.
Removes the 'embedding' field to prevent JSON serialization errors with ndarrays.
"""
with
self
.
pool_handler
.
get_connection
()
as
conn
:
with
conn
.
cursor
(
cursor_factory
=
RealDictCursor
)
as
cur
:
query
=
"""
SELECT *
FROM mcq_questions
WHERE curriculum =
%
s AND grade =
%
s AND subject =
%
s AND unit =
%
s AND concept =
%
s AND is_arabic =
%
s
ORDER BY created_at DESC
"""
params
=
(
curriculum
,
grade
,
subject
,
unit
,
concept
,
is_arabic
)
if
limit
is
not
None
:
query
+=
" LIMIT
%
s;"
params
+=
(
limit
,)
else
:
query
+=
";"
cur
.
execute
(
query
,
params
)
return
cur
.
fetchall
()
cur
.
execute
(
query
,
params
)
results
=
cur
.
fetchall
()
for
row
in
results
:
row
.
pop
(
'embedding'
,
None
)
return
results
def
get_distinct_curricula_from_structure
(
self
)
->
List
[
str
]:
...
...
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