Hamdy005 commited on
Commit
c19fa3c
Β·
1 Parent(s): 2d3a0d2

refactor: improve markdown parsing, update summary export formatting, and refine UI loading states for material summaries

Browse files
Files changed (2) hide show
  1. store.py +12 -12
  2. summary_generator/summary.py +3 -3
store.py CHANGED
@@ -125,7 +125,7 @@ def list_materials(user_id: str) -> list[dict]:
125
  client = _db()
126
  if client is not None:
127
  try:
128
- result = client.table("materials").select("*").eq("user_id", user_id).order("created_at").execute()
129
  return list(reversed(result.data))
130
  except Exception:
131
  pass
@@ -144,7 +144,7 @@ def create_material(user_id: str, source_type: str, title: str,
144
  data["file_path"] = file_path
145
  if url:
146
  data["url"] = url
147
- result = _table_supabase("materials").insert(data).execute()
148
  return result.data[0]
149
 
150
 
@@ -159,7 +159,7 @@ def update_material_status(material_id: str, status: str,
159
  def get_material(material_id: str) -> Optional[dict]:
160
  if material_id.startswith("temp-"):
161
  return None
162
- result = _table_supabase("materials").select("*").eq("id", material_id).execute()
163
  return result.data[0] if result.data else None
164
 
165
 
@@ -178,19 +178,19 @@ def delete_material(material_id: str):
178
  # Due to cascading or manual deletion, we delete child records first
179
 
180
  # chat_messages don't have material_id, so we must fetch session_ids first
181
- sessions_res = _table_supabase("chat_sessions").select("id").eq("material_id", material_id).execute()
182
  session_ids = [s["id"] for s in sessions_res.data] if sessions_res.data else []
183
 
184
  for sid in session_ids:
185
- _table_supabase("chat_messages").delete().eq("session_id", sid).execute()
186
 
187
- _table_supabase("chat_sessions").delete().eq("material_id", material_id).execute()
188
- _table_supabase("summaries").delete().eq("material_id", material_id).execute()
189
- _table_supabase("quizzes").delete().eq("material_id", material_id).execute()
190
  # Delete embeddings before chunks (FK dependency)
191
- _table_supabase("material_embeddings").delete().eq("material_id", material_id).execute()
192
- _table_supabase("material_chunks").delete().eq("material_id", material_id).execute()
193
- _table_supabase("materials").delete().eq("id", material_id).execute()
194
 
195
 
196
  # ── Material Chunks ────────────────────────────────────
@@ -200,7 +200,7 @@ def save_chunks(material_id: str, chunks: list[str]) -> list[str]:
200
  {"material_id": material_id, "chunk_index": i, "content": c}
201
  for i, c in enumerate(chunks)
202
  ]
203
- result = _table_supabase("material_chunks").insert(records).execute()
204
  return [r["id"] for r in result.data]
205
 
206
 
 
125
  client = _db()
126
  if client is not None:
127
  try:
128
+ result = _robust_execute(client.table("materials").select("*").eq("user_id", user_id).order("created_at"))
129
  return list(reversed(result.data))
130
  except Exception:
131
  pass
 
144
  data["file_path"] = file_path
145
  if url:
146
  data["url"] = url
147
+ result = _robust_execute(_table_supabase("materials").insert(data))
148
  return result.data[0]
149
 
150
 
 
159
  def get_material(material_id: str) -> Optional[dict]:
160
  if material_id.startswith("temp-"):
161
  return None
162
+ result = _robust_execute(_table_supabase("materials").select("*").eq("id", material_id))
163
  return result.data[0] if result.data else None
164
 
165
 
 
178
  # Due to cascading or manual deletion, we delete child records first
179
 
180
  # chat_messages don't have material_id, so we must fetch session_ids first
181
+ sessions_res = _robust_execute(_table_supabase("chat_sessions").select("id").eq("material_id", material_id))
182
  session_ids = [s["id"] for s in sessions_res.data] if sessions_res.data else []
183
 
184
  for sid in session_ids:
185
+ _robust_execute(_table_supabase("chat_messages").delete().eq("session_id", sid))
186
 
187
+ _robust_execute(_table_supabase("chat_sessions").delete().eq("material_id", material_id))
188
+ _robust_execute(_table_supabase("summaries").delete().eq("material_id", material_id))
189
+ _robust_execute(_table_supabase("quizzes").delete().eq("material_id", material_id))
190
  # Delete embeddings before chunks (FK dependency)
191
+ _robust_execute(_table_supabase("material_embeddings").delete().eq("material_id", material_id))
192
+ _robust_execute(_table_supabase("material_chunks").delete().eq("material_id", material_id))
193
+ _robust_execute(_table_supabase("materials").delete().eq("id", material_id))
194
 
195
 
196
  # ── Material Chunks ────────────────────────────────────
 
200
  {"material_id": material_id, "chunk_index": i, "content": c}
201
  for i, c in enumerate(chunks)
202
  ]
203
+ result = _robust_execute(_table_supabase("material_chunks").insert(records))
204
  return [r["id"] for r in result.data]
205
 
206
 
summary_generator/summary.py CHANGED
@@ -28,9 +28,9 @@ You are an expert academic assistant tasked with creating a comprehensive and we
28
  **FORMATTING RULES:**
29
  - Do NOT use markdown tables or pipe characters (|)
30
  - Do NOT use separator lines (---, ===)
31
- - Use ### for Main Section Headings (e.g. ### Detailed Summary)
32
- - Use #### for Sub-topics or Sub-headings inside a section (e.g. #### 1. Introduction)
33
- - Do NOT put punctuation (like colons or periods) at the end of headings.
34
  - Use **Text** for important keywords, topics, or terms you want to highlight within paragraphs.
35
  - Use numbered lists or bullet points instead of tables
36
 
 
28
  **FORMATTING RULES:**
29
  - Do NOT use markdown tables or pipe characters (|)
30
  - Do NOT use separator lines (---, ===)
31
+ - Use [[[### HEADER ###]]] for Main Section Headings (e.g. [[[### Detailed Summary ###]]])
32
+ - Use [[[>>> HEADER <<<]]] for Sub-topics or Sub-headings inside a section (e.g. [[[>>> Introduction <<<]]])
33
+ - Do NOT put punctuation (like colons or periods) at the end of the text inside the markers.
34
  - Use **Text** for important keywords, topics, or terms you want to highlight within paragraphs.
35
  - Use numbered lists or bullet points instead of tables
36