Spaces:
Sleeping
Sleeping
Update api/server.py
Browse files101 unmodified lines10210310410510610794 unmodified lines20220320420520620728 unmodified lines236237238239240241101 unmodified lines# preload base reading"rag_chunks": list(MODULE10_CHUNKS_CACHE),"model_name": DEFAULT_MODEL,}return SESSIONS[user_id]94 unmodified linesfor c in (rag_used_chunks or [])]return {"reply": answer,"session_status_md": render_session_status(28 unmodified lineswith open(tmp_path, "wb") as f:f.write(content)# Update topics only for syllabusif doc_type == "Syllabus":class _F:101 unmodified lines10210310410510610710810994 unmodified lines20420520620720820921021121221321421521621721821922022122222322422522622722828 unmodified lines257258259260261262263264265266101 unmodified lines# preload base reading"rag_chunks": list(MODULE10_CHUNKS_CACHE),"model_name": DEFAULT_MODEL,# ✅ NEW: track last syllabus filename for refs fallback"last_syllabus_file": None,}return SESSIONS[user_id]94 unmodified linesfor c in (rag_used_chunks or [])]# ✅ NEW: Syllabus chat should show syllabus in refs (fallback if retrieval didn't hit it)doc_type_norm = (req.doc_type or "").strip().lower()if doc_type_norm == "syllabus":syllabus_name = sess.get("last_syllabus_file") or "uploaded_syllabus"# We consider it a hit if any ref source_file contains the syllabus filenamedef _has_syllabus_ref() -> bool:for r in refs:sf = (r.get("source_file") or "").strip()if not sf:continue# robust matching: exact basename containment OR endswithif syllabus_name in sf or sf.endswith(syllabus_name):return Truereturn Falseif not _has_syllabus_ref():# put syllabus at the front, preserve existing refs afterrefs = [{"source_file": syllabus_name, "section": "syllabus_outline"}] + refsreturn {"reply": answer,"session_status_md": render_session_status(28 unmodified lineswith open(tmp_path, "wb") as f:f.write(content)# ✅ NEW: remember the latest syllabus filename for refs fallbackif doc_type == "Syllabus":sess["last_syllabus_file"] = os.path.basename(file.filename) or safe_name# Update topics only for syllabusif doc_type == "Syllabus":class _F:
api/server.py+25