NavyDevilDoc commited on
Commit
5b91370
·
verified ·
1 Parent(s): 74a6e3b

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +25 -17
src/app.py CHANGED
@@ -510,24 +510,32 @@ with tab3:
510
 
511
  # MODE B: DOCUMENTS
512
  else:
513
- q_ctx = quiz.get_document_context(st.session_state.username)
514
- if q_ctx:
515
- # We have the text, now we need the LLM to write the question
516
- prompt = quiz.construct_question_generation_prompt(q_ctx["context_text"])
517
-
518
- # Generate Question using your existing query helper
519
- msgs = [{"role": "user", "content": prompt}]
520
- question_text, usage = query_model_universal(
521
- msgs, 300, model_choice, st.session_state.get("user_openai_key")
522
- )
523
 
524
- qs["active"] = True
525
- qs["question_data"] = q_ctx
526
- qs["generated_question_text"] = question_text # Store the LLM-generated question
527
- qs["feedback"] = None
528
- st.rerun()
529
- else:
530
- st.error("No documents found! Upload some .txt or .md files first.")
 
 
 
 
 
 
 
 
 
 
 
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"]: