Spaces:
Sleeping
Sleeping
Persist full assistant chat history
Browse filesFiles changed (3)
312 unmodified lines3133143153163173183193 unmodified lines323324325326327328329312 unmodified linesdef _format_chat_history(chat_history: list) -> str:"""Format chat history for text file."""if not chat_history:return "ΧΧ ΧΧ©ΧͺΧΧ© ΧΧΧΧ ΧΧΧ\n"3 unmodified linesfor i, msg in enumerate(chat_history, 1):question = msg.get('question') or msg.get('summary', 'N/A')hint_summary = msg.get('hint_summary') or msg.get('summary', '')lines.append(f"ΧΧΧ Χ #{i}\n")lines.append("-" * 40 + "\n")lines.append(f"Χ©ΧΧΧ: {question}\n\n")lines.append(f"ΧͺΧ©ΧΧΧ:\n{msg.get('response', 'N/A')}\n\n")312 unmodified lines3133143153163173183193 unmodified lines323324325326327328329330331312 unmodified linesdef _format_chat_history(chat_history: list) -> str:"""Format full chat history for text file."""if not chat_history:return "ΧΧ ΧΧ©ΧͺΧΧ© ΧΧΧΧ ΧΧΧ\n"3 unmodified linesfor i, msg in enumerate(chat_history, 1):question = msg.get('question') or msg.get('summary', 'N/A')hint_summary = msg.get('hint_summary') or msg.get('summary', '')gave_hint = msg.get('gave_hint')title = f"ΧΧΧ Χ #{i}" if gave_hint is True else f"Χ©ΧΧΧ #{i}"lines.append(f"{title}\n")lines.append("-" * 40 + "\n")lines.append(f"Χ©ΧΧΧ: {question}\n\n")lines.append(f"ΧͺΧ©ΧΧΧ:\n{msg.get('response', 'N/A')}\n\n")
194 unmodified lines195196197198199200201194 unmodified linesif chat_history:chat_text = "\n\n".join([(f"ΧΧΧ Χ #{i+1}:\n"f"Χ©ΧΧΧ: {msg.get('question') or msg.get('summary', 'N/A')}\n"f"ΧͺΧ©ΧΧΧ: {msg.get('response', 'N/A')}")194 unmodified lines195196197198199200201194 unmodified linesif chat_history:chat_text = "\n\n".join([(f"{'ΧΧΧ Χ' if msg.get('gave_hint') is True else 'Χ©ΧΧΧ'} #{i+1}:\n"f"Χ©ΧΧΧ: {msg.get('question') or msg.get('summary', 'N/A')}\n"f"ΧͺΧ©ΧΧΧ: {msg.get('response', 'N/A')}")
1094 unmodified lines10951096109710981099110044 unmodified lines114511461147114811491150115197 unmodified lines124912501251125212531254427 unmodified lines168216831684168516861687168861 unmodified lines17501751175217531754175537 unmodified lines179317941795179617971798179922 unmodified lines182218231824182518261827182834 unmodified lines186318641865186618671868186918701871187218731874187518761877187812 unmodified lines1891189218931894189518964 unmodified lines190119021903190419051906190716 unmodified lines19241925192619271928192919309 unmodified lines194019411942194319441945194619471948194919501951195237 unmodified lines199019911992199319941995121 unmodified lines211721182119212021212122212348 unmodified lines21722173217421752176217728 unmodified lines22062207220822092210221122129 unmodified lines222222232224222522262227222819 unmodified lines22482249225022512252225322542255225622579 unmodified lines2267226822692270227122724 unmodified lines227722782279228022812282228311 unmodified lines22952296229722982299230023016 unmodified lines23082309231023112312231323142315231623172318231923201094 unmodified linessubmitted_code: str,result: dict,hints_used: int,hint_log: list,attempt_number: int,debug_logs: str,44 unmodified lines"submission": {"attempt_number": attempt_number,"hints_used": hints_used,"chat_history": hint_log or [],"student_code": submitted_code,"student_diff": _plain_diff_text(cs.sabotaged_code,97 unmodified linesworkspace_state = gr.State("")hints_used_state = gr.State(0)submission_count_state = gr.State(0)hint_log_state = gr.State([])confirmation_pending_state = gr.State(False)timer_trigger = gr.Number(value=0, visible=False)427 unmodified linescs.reset_target()return cs.sabotaged_code, gr.update(selected=1)def on_submit(trigger, hints_used, submit_count, workspace_path, hint_log, user_name, code, rel_path):logger.info(f"=== SUBMIT CHALLENGE ===")logger.info(f"Trigger: {trigger}, User: {user_name}, Hints: {hints_used}, Submit#: {submit_count}")logger.info(f"Workspace: {workspace_path}")61 unmodified linessubmitted_code=submitted_code,result=result,hints_used=hints_used,hint_log=hint_log or [],attempt_number=new_count,debug_logs=debug_logs,37 unmodified linestotal_tests=result["total_tests"],passed_tests=result["passed"],all_passed=result["all_passed"],chat_history=hint_log or [],submission_record=submission_record,)if sheets_ok:22 unmodified linesoriginal_code=cs.original_code,buggy_code=cs.sabotaged_code,student_code=submitted_code,chat_history=hint_log or [],score=result["total_score"],total_tests=result["total_tests"],passed_tests=result["passed"],34 unmodified linesfinally:sys.stdout = original_stdout # Always restore stdoutdef on_send(message, history, hints_used, submit_count, workspace_path, hint_log, confirmation_pending):if not message.strip():penalty = PENALTY_TABLE[min(hints_used, len(PENALTY_TABLE) - 1)]return history, "", hints_used, _hint_md(hints_used, penalty), hint_log, confirmation_pendingif not workspace_path:history = list(history or []) + [{"role": "user", "content": message},{"role": "assistant", "content": "No challenge loaded yet."},]return history, "", hints_used, _hint_md(hints_used, 0), hint_log, Falsecs = ChallengeState(workspace_path)result = get_hint(user_message=message,12 unmodified lines{"role": "user", "content": message},{"role": "assistant", "content": result["response"]},]new_hints = hints_used + (1 if gave_hint else 0)penalty = PENALTY_TABLE[min(new_hints, len(PENALTY_TABLE) - 1)]new_log = list(hint_log or [])4 unmodified lines"hint_summary": result.get("hint_summary", ""),"summary": result.get("hint_summary", ""),})return history, "", new_hints, _hint_md(new_hints, penalty), new_log, new_confirmation_pending# ββ Wiring ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ16 unmodified linessubmit_btn.click(on_submit,inputs=[submit_trigger, hints_used_state, submission_count_state,workspace_state, hint_log_state, user_name_state, code_editor, file_dropdown],outputs=[challenge_page, # Hide challenge pageresults_page, # Show results page9 unmodified linessend_btn.click(on_send,inputs=[chat_input, chatbot, hints_used_state, submission_count_state, workspace_state, hint_log_state, confirmation_pending_state],outputs=[chatbot, chat_input, hints_used_state, hint_counter, hint_log_state, confirmation_pending_state],)chat_input.submit(on_send,inputs=[chat_input, chatbot, hints_used_state, submission_count_state, workspace_state, hint_log_state, confirmation_pending_state],outputs=[chatbot, chat_input, hints_used_state, hint_counter, hint_log_state, confirmation_pending_state],)# CRITICAL: Enable queue for generator functions to work on production servers37 unmodified lineshints_used_state = gr.State(0)submission_count_state = gr.State(0)hint_log_state = gr.State([])confirmation_pending_state = gr.State(False)121 unmodified linescs.reset_target()return cs.sabotaged_code, gr.update(selected=1)def on_submit(hints_used, submit_count, hint_log, code, rel_path):# Capture all print statements for debug consolelog_capture = StringIO()original_stdout = sys.stdout48 unmodified linessubmitted_code=submitted_code,result=result,hints_used=hints_used,hint_log=hint_log or [],attempt_number=new_count,debug_logs=debug_logs,28 unmodified linestotal_tests=result["total_tests"],passed_tests=result["passed"],all_passed=result["all_passed"],chat_history=hint_log or [],)print(f"β Logged to Google Sheets: {student_name}")except Exception as e:9 unmodified linesoriginal_code=cs.original_code,buggy_code=cs.sabotaged_code,student_code=submitted_code,chat_history=hint_log or [],score=result["total_score"],total_tests=result["total_tests"],passed_tests=result["passed"],19 unmodified linesfinally:sys.stdout = original_stdout # Always restore stdoutdef on_send(message, history, hints_used, submit_count, hint_log, confirmation_pending):if not message.strip():penalty = PENALTY_TABLE[min(hints_used, len(PENALTY_TABLE) - 1)]return history, "", hints_used, _hint_md(hints_used, penalty), hint_log, confirmation_pendingresult = get_hint(user_message=message, history=history,hints_used=hints_used, submission_attempts=submit_count,9 unmodified lines{"role": "user", "content": message},{"role": "assistant", "content": result["response"]},]new_hints = hints_used + (1 if gave_hint else 0)penalty = PENALTY_TABLE[min(new_hints, len(PENALTY_TABLE) - 1)]new_log = list(hint_log or [])4 unmodified lines"hint_summary": result.get("hint_summary", ""),"summary": result.get("hint_summary", ""),})return history, "", new_hints, _hint_md(new_hints, penalty), new_log, new_confirmation_pending# ββ Wiring ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ11 unmodified linessubmit_btn.click(on_submit,inputs=[hints_used_state, submission_count_state, hint_log_state, code_editor, file_dropdown],outputs=[challenge_col, results_col,score_summary_html,6 unmodified lines)send_btn.click(on_send,inputs=[chat_input, chatbot, hints_used_state, submission_count_state, hint_log_state, confirmation_pending_state],outputs=[chatbot, chat_input, hints_used_state, hint_counter, hint_log_state, confirmation_pending_state],)chat_input.submit(on_send,inputs=[chat_input, chatbot, hints_used_state, submission_count_state, hint_log_state, confirmation_pending_state],outputs=[chatbot, chat_input, hints_used_state, hint_counter, hint_log_state, confirmation_pending_state],)# CRITICAL: Enable queue for generator functions to work on production servers1094 unmodified lines109510961097109810991100110144 unmodified lines1146114711481149115011511152115397 unmodified lines1251125212531254125512561257427 unmodified lines168516861687168816891690169161 unmodified lines175317541755175617571758175937 unmodified lines179717981799180018011802180322 unmodified lines182618271828182918301831183234 unmodified lines1867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188912 unmodified lines19021903190419051906190719081909191019111912191319144 unmodified lines191919201921192219231924192516 unmodified lines19421943194419451946194719489 unmodified lines195819591960196119621963196419651966196719681969197037 unmodified lines2008200920102011201220132014121 unmodified lines213621372138213921402141214248 unmodified lines219121922193219421952196219728 unmodified lines22262227222822292230223122329 unmodified lines224222432244224522462247224819 unmodified lines22682269227022712272227322742275227622779 unmodified lines22872288228922902291229222932294229522962297229822994 unmodified lines230423052306230723082309231011 unmodified lines23222323232423252326232723286 unmodified lines23352336233723382339234023412342234323442345234623471094 unmodified linessubmitted_code: str,result: dict,hints_used: int,chat_log: list,hint_log: list,attempt_number: int,debug_logs: str,44 unmodified lines"submission": {"attempt_number": attempt_number,"hints_used": hints_used,"chat_history": chat_log or [],"hint_history": hint_log or [],"student_code": submitted_code,"student_diff": _plain_diff_text(cs.sabotaged_code,97 unmodified linesworkspace_state = gr.State("")hints_used_state = gr.State(0)submission_count_state = gr.State(0)chat_log_state = gr.State([])hint_log_state = gr.State([])confirmation_pending_state = gr.State(False)timer_trigger = gr.Number(value=0, visible=False)427 unmodified linescs.reset_target()return cs.sabotaged_code, gr.update(selected=1)def on_submit(trigger, hints_used, submit_count, workspace_path, chat_log, hint_log, user_name, code, rel_path):logger.info(f"=== SUBMIT CHALLENGE ===")logger.info(f"Trigger: {trigger}, User: {user_name}, Hints: {hints_used}, Submit#: {submit_count}")logger.info(f"Workspace: {workspace_path}")61 unmodified linessubmitted_code=submitted_code,result=result,hints_used=hints_used,chat_log=chat_log or [],hint_log=hint_log or [],attempt_number=new_count,debug_logs=debug_logs,37 unmodified linestotal_tests=result["total_tests"],passed_tests=result["passed"],all_passed=result["all_passed"],chat_history=chat_log or [],submission_record=submission_record,)if sheets_ok:22 unmodified linesoriginal_code=cs.original_code,buggy_code=cs.sabotaged_code,student_code=submitted_code,chat_history=chat_log or [],score=result["total_score"],total_tests=result["total_tests"],passed_tests=result["passed"],34 unmodified linesfinally:sys.stdout = original_stdout # Always restore stdoutdef on_send(message, history, hints_used, submit_count, workspace_path, chat_log, hint_log, confirmation_pending):if not message.strip():penalty = PENALTY_TABLE[min(hints_used, len(PENALTY_TABLE) - 1)]return history, "", hints_used, _hint_md(hints_used, penalty), chat_log, hint_log, confirmation_pendingif not workspace_path:history = list(history or []) + [{"role": "user", "content": message},{"role": "assistant", "content": "No challenge loaded yet."},]new_chat_log = list(chat_log or [])new_chat_log.append({"question": message,"response": "No challenge loaded yet.","gave_hint": False,"hint_summary": "",})return history, "", hints_used, _hint_md(hints_used, 0), new_chat_log, hint_log, Falsecs = ChallengeState(workspace_path)result = get_hint(user_message=message,12 unmodified lines{"role": "user", "content": message},{"role": "assistant", "content": result["response"]},]new_chat_log = list(chat_log or [])new_chat_log.append({"question": message,"response": result["response"],"gave_hint": gave_hint,"hint_summary": result.get("hint_summary", ""),})new_hints = hints_used + (1 if gave_hint else 0)penalty = PENALTY_TABLE[min(new_hints, len(PENALTY_TABLE) - 1)]new_log = list(hint_log or [])4 unmodified lines"hint_summary": result.get("hint_summary", ""),"summary": result.get("hint_summary", ""),})return history, "", new_hints, _hint_md(new_hints, penalty), new_chat_log, new_log, new_confirmation_pending# ββ Wiring ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ16 unmodified linessubmit_btn.click(on_submit,inputs=[submit_trigger, hints_used_state, submission_count_state,workspace_state, chat_log_state, hint_log_state, user_name_state, code_editor, file_dropdown],outputs=[challenge_page, # Hide challenge pageresults_page, # Show results page9 unmodified linessend_btn.click(on_send,inputs=[chat_input, chatbot, hints_used_state, submission_count_state, workspace_state, chat_log_state, hint_log_state, confirmation_pending_state],outputs=[chatbot, chat_input, hints_used_state, hint_counter, chat_log_state, hint_log_state, confirmation_pending_state],)chat_input.submit(on_send,inputs=[chat_input, chatbot, hints_used_state, submission_count_state, workspace_state, chat_log_state, hint_log_state, confirmation_pending_state],outputs=[chatbot, chat_input, hints_used_state, hint_counter, chat_log_state, hint_log_state, confirmation_pending_state],)# CRITICAL: Enable queue for generator functions to work on production servers37 unmodified lineshints_used_state = gr.State(0)submission_count_state = gr.State(0)chat_log_state = gr.State([])hint_log_state = gr.State([])confirmation_pending_state = gr.State(False)121 unmodified linescs.reset_target()return cs.sabotaged_code, gr.update(selected=1)def on_submit(hints_used, submit_count, chat_log, hint_log, code, rel_path):# Capture all print statements for debug consolelog_capture = StringIO()original_stdout = sys.stdout48 unmodified linessubmitted_code=submitted_code,result=result,hints_used=hints_used,chat_log=chat_log or [],hint_log=hint_log or [],attempt_number=new_count,debug_logs=debug_logs,28 unmodified linestotal_tests=result["total_tests"],passed_tests=result["passed"],all_passed=result["all_passed"],chat_history=chat_log or [],)print(f"β Logged to Google Sheets: {student_name}")except Exception as e:9 unmodified linesoriginal_code=cs.original_code,buggy_code=cs.sabotaged_code,student_code=submitted_code,chat_history=chat_log or [],score=result["total_score"],total_tests=result["total_tests"],passed_tests=result["passed"],19 unmodified linesfinally:sys.stdout = original_stdout # Always restore stdoutdef on_send(message, history, hints_used, submit_count, chat_log, hint_log, confirmation_pending):if not message.strip():penalty = PENALTY_TABLE[min(hints_used, len(PENALTY_TABLE) - 1)]return history, "", hints_used, _hint_md(hints_used, penalty), chat_log, hint_log, confirmation_pendingresult = get_hint(user_message=message, history=history,hints_used=hints_used, submission_attempts=submit_count,9 unmodified lines{"role": "user", "content": message},{"role": "assistant", "content": result["response"]},]new_chat_log = list(chat_log or [])new_chat_log.append({"question": message,"response": result["response"],"gave_hint": gave_hint,"hint_summary": result.get("hint_summary", ""),})new_hints = hints_used + (1 if gave_hint else 0)penalty = PENALTY_TABLE[min(new_hints, len(PENALTY_TABLE) - 1)]new_log = list(hint_log or [])4 unmodified lines"hint_summary": result.get("hint_summary", ""),"summary": result.get("hint_summary", ""),})return history, "", new_hints, _hint_md(new_hints, penalty), new_chat_log, new_log, new_confirmation_pending# ββ Wiring ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ11 unmodified linessubmit_btn.click(on_submit,inputs=[hints_used_state, submission_count_state, chat_log_state, hint_log_state, code_editor, file_dropdown],outputs=[challenge_col, results_col,score_summary_html,6 unmodified lines)send_btn.click(on_send,inputs=[chat_input, chatbot, hints_used_state, submission_count_state, chat_log_state, hint_log_state, confirmation_pending_state],outputs=[chatbot, chat_input, hints_used_state, hint_counter, chat_log_state, hint_log_state, confirmation_pending_state],)chat_input.submit(on_send,inputs=[chat_input, chatbot, hints_used_state, submission_count_state, chat_log_state, hint_log_state, confirmation_pending_state],outputs=[chatbot, chat_input, hints_used_state, hint_counter, chat_log_state, hint_log_state, confirmation_pending_state],)# CRITICAL: Enable queue for generator functions to work on production servers
git_submissions_logger.py+4-2
google_sheets_logger.py+1-1
student_interface.py+51-24