Update app.py
Browse files
app.py
CHANGED
|
@@ -51,14 +51,14 @@ def user_message(message: str, history: list):
|
|
| 51 |
if _agent is None:
|
| 52 |
return history + [
|
| 53 |
{"role": "user", "content": message},
|
| 54 |
-
{"role": "assistant", "content": "Please click
|
| 55 |
], ""
|
| 56 |
|
| 57 |
# Block messages after exam is finished
|
| 58 |
if _agent.exam_finished:
|
| 59 |
return history + [
|
| 60 |
{"role": "user", "content": message},
|
| 61 |
-
{"role": "assistant", "content": "The exam is already finished. Click
|
| 62 |
], ""
|
| 63 |
|
| 64 |
history = history + [{"role": "user", "content": message}]
|
|
@@ -73,8 +73,14 @@ def user_message(message: str, history: list):
|
|
| 73 |
reply = "Invalid API key. Please restart and enter a valid Groq key."
|
| 74 |
elif "connection" in err.lower() or "timeout" in err.lower():
|
| 75 |
reply = "Connection error. Please check your internet and try again."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
else:
|
| 77 |
-
reply = f"
|
| 78 |
|
| 79 |
history = history + [{"role": "assistant", "content": reply}]
|
| 80 |
return history, ""
|
|
@@ -158,7 +164,7 @@ with gr.Blocks(title="AI Examiner Agent") as demo:
|
|
| 158 |
5. Get your score & feedback
|
| 159 |
<br><br>
|
| 160 |
<strong>Demo students</strong><br>
|
| 161 |
-
test@test.com / test
|
| 162 |
</div>
|
| 163 |
""")
|
| 164 |
|
|
|
|
| 51 |
if _agent is None:
|
| 52 |
return history + [
|
| 53 |
{"role": "user", "content": message},
|
| 54 |
+
{"role": "assistant", "content": "Please click Start Exam first."},
|
| 55 |
], ""
|
| 56 |
|
| 57 |
# Block messages after exam is finished
|
| 58 |
if _agent.exam_finished:
|
| 59 |
return history + [
|
| 60 |
{"role": "user", "content": message},
|
| 61 |
+
{"role": "assistant", "content": "The exam is already finished. Click Start Exam to begin a new session."},
|
| 62 |
], ""
|
| 63 |
|
| 64 |
history = history + [{"role": "user", "content": message}]
|
|
|
|
| 73 |
reply = "Invalid API key. Please restart and enter a valid Groq key."
|
| 74 |
elif "connection" in err.lower() or "timeout" in err.lower():
|
| 75 |
reply = "Connection error. Please check your internet and try again."
|
| 76 |
+
elif "tool_use_failed" in err or "Failed to call a function" in err:
|
| 77 |
+
# Leaked function call that wasn't caught — restart agent turn
|
| 78 |
+
try:
|
| 79 |
+
reply = _agent.chat("Please continue.")
|
| 80 |
+
except Exception:
|
| 81 |
+
reply = "Model error. Please try sending your message again."
|
| 82 |
else:
|
| 83 |
+
reply = f"Error: {e}"
|
| 84 |
|
| 85 |
history = history + [{"role": "assistant", "content": reply}]
|
| 86 |
return history, ""
|
|
|
|
| 164 |
5. Get your score & feedback
|
| 165 |
<br><br>
|
| 166 |
<strong>Demo students</strong><br>
|
| 167 |
+
test@test.com / test
|
| 168 |
</div>
|
| 169 |
""")
|
| 170 |
|