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
70ec7ce2
Commit
70ec7ce2
authored
Oct 13, 2025
by
SalmaMohammedHamedMustafa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gaster game help response
parent
97fd9871
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
18 deletions
+19
-18
query_handlers.py
..._env/voice_agent/services/agent_helpers/query_handlers.py
+19
-18
No files found.
self_hosted_env/voice_agent/services/agent_helpers/query_handlers.py
View file @
70ec7ce2
...
...
@@ -92,20 +92,28 @@ class QueryHandler:
logger
.
warning
(
f
"Error getting conversation context for {student_id}: {e}"
)
return
"لا يمكن الحصول على سياق المحادثة."
def
classify_query_type
(
self
,
query
:
str
,
student_info
:
Dict
[
str
,
Any
],
student_id
:
str
)
->
str
:
"""Enhanced query classification using LLM with conversation context"""
"""
Enhanced query classification. It first checks for a specific, rule-based
pattern for 'game_help' and then falls back to the LLM for other cases.
"""
q_lower
=
query
.
lower
()
if
"game context:"
in
q_lower
and
"user query:"
in
q_lower
:
logger
.
info
(
"Query classified as 'game_help' by rule-based check."
)
print
(
"Query classified as 'game_help' by rule-based check."
)
return
"game_help"
if
not
self
.
openai_service
.
is_available
():
return
"specific_content"
is_arabic
:
bool
=
student_info
.
get
(
'is_arabic'
,
True
)
grade
:
int
=
student_info
.
get
(
'grade'
,
4
)
# Get recent conversation context
conversation_context
=
self
.
get_recent_conversation_context
(
student_id
,
max_messages
=
5
)
q_lower
=
query
.
lower
()
classification_prompt
=
f
"""
صنف السؤال التالي إلى إحدى الفئات التالية، مع مراعاة سياق المحادثة الأخيرة:
...
...
@@ -113,9 +121,7 @@ class QueryHandler:
2. "overview" - أسئلة عن نظرة عامة على المنهج أو المحتوى الكامل
3. "navigation" - أسئلة عن وحدة أو مفهوم معين
4. "specific_content" - أسئلة محددة عن موضوع علمي معين
5. "game_help:" - أسئلة عن مساعدة او تفاعل في لعبة تعليمية بيكون شكل الرسالة كدا دايما
game context: <context text>
user query: <query text>
{conversation_context}
السؤال الحالي: "{query}"
...
...
@@ -127,12 +133,8 @@ class QueryHandler:
- إذا كان الطالب يتحدث عن موضوع علمي معين وسأل سؤال متعلق به، فهو "specific_content"
- إذا كان السؤال غامض، اعتمد على السياق لتحديد القصد الحقيقي
- مثال: إذا كان يتحدث عن النباتات وسأل "كيف تأكل؟" فهو يقصد تغذية النباتات وليس الطعام العادي
- لو السؤال فيه الصيغة دي:
"game context:" وبعدها "user query:"، فالتصنيف الصحيح دايمًا يكون "game_help" مهما كان المحتوى
"""
classification_prompt
+=
"
\n\n
رد فقط بكلمة واحدة من الفئات المحددة أعلاه"
try
:
...
...
@@ -143,25 +145,24 @@ class QueryHandler:
max_tokens
=
20
)
classification
:
str
=
response
.
choices
[
0
]
.
message
.
content
.
strip
()
.
lower
()
.
strip
(
'"'
)
.
strip
(
"'"
)
valid_classes
=
{
"general_chat"
,
"overview"
,
"navigation"
,
"specific_content"
,
"game_help"
"general_chat"
,
"overview"
,
"navigation"
,
"specific_content"
}
if
classification
in
valid_classes
:
logger
.
info
(
f
"Query classified as: {classification} for query: '{query}'"
)
print
(
f
"Query classified as: {classification} for query: '{query}'"
)
logger
.
info
(
f
"Query classified as: {classification}
by LLM
for query: '{query}'"
)
print
(
f
"Query classified as: {classification}
by LLM
for query: '{query}'"
)
return
classification
else
:
logger
.
warning
(
f
"Unexpected classification '{classification}' for query '{query}', "
f
"Unexpected
LLM
classification '{classification}' for query '{query}', "
"defaulting to 'specific_content'"
)
return
"specific_content"
except
Exception
as
e
:
logger
.
warning
(
f
"Error in query classification: {e}, defaulting to 'specific_content'"
)
logger
.
warning
(
f
"Error in
LLM
query classification: {e}, defaulting to 'specific_content'"
)
return
"specific_content"
...
...
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