Spaces:
Sleeping
Sleeping
Update src/app.py
Browse files- src/app.py +25 -17
src/app.py
CHANGED
|
@@ -510,24 +510,32 @@ with tab3:
|
|
| 510 |
|
| 511 |
# MODE B: DOCUMENTS
|
| 512 |
else:
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
question_text, usage = query_model_universal(
|
| 521 |
-
msgs, 300, model_choice, st.session_state.get("user_openai_key")
|
| 522 |
-
)
|
| 523 |
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
|
| 532 |
# 3. QUIZ INTERFACE
|
| 533 |
if qs["active"]:
|
|
|
|
| 510 |
|
| 511 |
# MODE B: DOCUMENTS
|
| 512 |
else:
|
| 513 |
+
# Retry logic for the LLM's "SKIP" response
|
| 514 |
+
valid_question_found = False
|
| 515 |
+
attempts = 0
|
| 516 |
+
|
| 517 |
+
while not valid_question_found and attempts < 3:
|
| 518 |
+
attempts += 1
|
| 519 |
+
q_ctx = quiz.get_document_context(st.session_state.username)
|
|
|
|
|
|
|
|
|
|
| 520 |
|
| 521 |
+
if q_ctx:
|
| 522 |
+
prompt = quiz.construct_question_generation_prompt(q_ctx["context_text"])
|
| 523 |
+
question_text, usage = query_model_universal(
|
| 524 |
+
[{"role": "user", "content": prompt}],
|
| 525 |
+
300, model_choice, st.session_state.get("user_openai_key")
|
| 526 |
+
)
|
| 527 |
+
|
| 528 |
+
# If LLM liked the chunk, it gave us a question. If not, it said "SKIP".
|
| 529 |
+
if "SKIP" not in question_text and len(question_text) > 10:
|
| 530 |
+
valid_question_found = True
|
| 531 |
+
qs["active"] = True
|
| 532 |
+
qs["question_data"] = q_ctx
|
| 533 |
+
qs["generated_question_text"] = question_text
|
| 534 |
+
qs["feedback"] = None
|
| 535 |
+
st.rerun()
|
| 536 |
+
|
| 537 |
+
if not valid_question_found:
|
| 538 |
+
st.warning("Tried to find a good engineering question but the available text was too administrative. Try uploading denser technical notes!")
|
| 539 |
|
| 540 |
# 3. QUIZ INTERFACE
|
| 541 |
if qs["active"]:
|