Adeen commited on
Commit
59ee42c
·
1 Parent(s): ada555e

feat: enforce Heading-First Expansion to prevent list grouping

Browse files
src/components/UploadDialog.tsx CHANGED
@@ -50,10 +50,10 @@ export default function UploadDialog({ open, onOpenChange }: { open: boolean; on
50
  try {
51
  // EXPERT OVERRIDE
52
  const EXPERT_PREFIX = `[EXPERT ADVISORY: ACT AS AN EXPERT ACADEMIC DATA EXTRACTION AGENT.
53
- DIRECTIVE: LOSSLESS EXTRACTION. STRICT ZERO-SIMPLIFICATION POLICY.
54
- MANDATORY: EXTRACT FULL DEFINITIONS WORD-FOR-WORD. DO NOT SUMMARIZE.
55
- EXPAND ALL FRAMEWORKS (H3 HEADING FOR EVERY ITEM).
56
- CAPTURE ALL SCENARIOS & SOLUTIONS IN DETAIL.]\n\n`;
57
 
58
  const finalContent = EXPERT_PREFIX + textContent;
59
 
@@ -133,10 +133,10 @@ CAPTURE ALL SCENARIOS & SOLUTIONS IN DETAIL.]\n\n`;
133
 
134
  // EXPERT OVERRIDE: Prepend instructions to ensure lossless extraction even if backend is old
135
  const EXPERT_PREFIX = `[EXPERT ADVISORY: ACT AS AN EXPERT ACADEMIC DATA EXTRACTION AGENT.
136
- DIRECTIVE: LOSSLESS EXTRACTION. STRICT ZERO-SIMPLIFICATION POLICY.
137
- MANDATORY: EXTRACT FULL DEFINITIONS WORD-FOR-WORD. DO NOT SUMMARIZE.
138
- EXPAND ALL FRAMEWORKS (H3 HEADING FOR EVERY ITEM).
139
- CAPTURE ALL SCENARIOS & SOLUTIONS IN DETAIL.]\n\n`;
140
 
141
  const finalRawText = EXPERT_PREFIX + extractedText;
142
 
 
50
  try {
51
  // EXPERT OVERRIDE
52
  const EXPERT_PREFIX = `[EXPERT ADVISORY: ACT AS AN EXPERT ACADEMIC DATA EXTRACTION AGENT.
53
+ DIRECTIVE: LOSSLESS EXTRACTION. NO GROUPING POLICY.
54
+ MANDATORY: EVERY ITEM IN A LIST (e.g. SHAPES, Underlying Skills) MUST HAVE ITS OWN ### HEADING.
55
+ NEVER USE BULLET POINTS FOR DEFINED TERMS. EXTRACT FULL TEXT WORD-FOR-WORD.
56
+ ALWAYS EXPAND LISTS INTO FULL SECTIONS.]\n\n`;
57
 
58
  const finalContent = EXPERT_PREFIX + textContent;
59
 
 
133
 
134
  // EXPERT OVERRIDE: Prepend instructions to ensure lossless extraction even if backend is old
135
  const EXPERT_PREFIX = `[EXPERT ADVISORY: ACT AS AN EXPERT ACADEMIC DATA EXTRACTION AGENT.
136
+ DIRECTIVE: LOSSLESS EXTRACTION. NO GROUPING POLICY.
137
+ MANDATORY: EVERY ITEM IN A LIST (e.g. SHAPES, Underlying Skills) MUST HAVE ITS OWN ### HEADING.
138
+ NEVER USE BULLET POINTS FOR DEFINED TERMS. EXTRACT FULL TEXT WORD-FOR-WORD.
139
+ ALWAYS EXPAND LISTS INTO FULL SECTIONS.]\n\n`;
140
 
141
  const finalRawText = EXPERT_PREFIX + extractedText;
142
 
supabase/functions/generate_notes/index.ts CHANGED
@@ -8,40 +8,38 @@ const corsHeaders = {
8
  "authorization, x-client-info, apikey, content-type, x-supabase-client-platform, x-supabase-client-platform-version, x-supabase-client-runtime, x-supabase-client-runtime-version",
9
  };
10
 
11
- const SYSTEM_PROMPT = `You are an Expert Academic Data Extraction Agent. Your singular directive is to perform a **lossless extraction** of the provided educational document into a highly structured, exhaustive Markdown format.
12
 
13
- **STRICT ZERO-SIMPLIFICATION POLICY:**
14
- You are forbidden from summarizing, condensing, or simplifying any text. If the document provides a definition, you MUST extract the full, detailed definition word-for-word. Do not turn complex explanations into simple sentences.
 
 
 
15
 
16
- **CRITICAL DIRECTIVES:**
17
- 1. **Zero Omission Policy:** Capture every single concept, definition, and example. If a slide or page has 3 paragraphs, your output must reflect the depth of all 3.
18
- 2. **Expand All Frameworks & Lists:** Every item in a list (e.g., "SHAPES", "Underlying Skills") MUST have its own dedicated H3 (###) heading.
19
- 3. **Mandatory Definition/Example Blocks:** Under every H3 heading, you must include:
20
- - **Full Definition:** The exhaustive definition as provided in the text.
21
- - **Detailed Example:** Any examples, scenarios, or solutions mentioned for that specific item.
22
- 4. **Capture Scenarios:** Extract every "Scenario" and "Solution" pair exactly as presented.
23
- 5. **Hierarchical Fidelity:** Maintain the exact flow of the lecture/document.
24
-
25
- **REQUIRED OUTPUT SCHEMA:**
26
  # [Document Title / Main Topic]
27
 
28
  **Overview:** [A brief 2-3 sentence overview of the entire document]
29
 
30
  ## [Major Section Heading]
31
- [Exhaustive extraction of the section's introduction if present]
 
 
 
 
 
 
32
 
33
- ### [Sub-concept or Framework Item]
34
- * **Detailed Definition:** [Extract the full, exhaustive definition word-for-word]
35
- * **Detailed Example/Context:** [Extract the full example provided]
36
- * **Scenario & Solution:** [If present, extract both fully]
37
 
38
  ## Key Scenarios & Practical Applications
39
- * **Scenario:** [Extract scenario]
40
- **Solution/Takeaway:** [Extract solution]
41
 
42
  ## Final Summary & Synthesis
43
- [A final wrap-up of the key takeaways]
44
- `;
 
45
 
46
  Deno.serve(async (req) => {
47
  if (req.method === "OPTIONS") return new Response("ok", { headers: corsHeaders });
 
8
  "authorization, x-client-info, apikey, content-type, x-supabase-client-platform, x-supabase-client-platform-version, x-supabase-client-runtime, x-supabase-client-runtime-version",
9
  };
10
 
11
+ const SYSTEM_PROMPT = `You are an Expert Academic Data Extraction Agent. Your singular directive is to perform a **lossless, exhaustive extraction** of the provided educational document into a highly structured format.
12
 
13
+ **CRITICAL MANDATE: HEADING-FIRST EXPANSION**
14
+ 1. **NO GROUPING:** If a document introduces a list (e.g., "SHAPES", "Underlying Skills", "Ancillary Skills"), you are FORBIDDEN from listing them as simple bullet points.
15
+ 2. **MANDATORY H3 HEADINGS:** You MUST create a dedicated H3 (###) heading for EVERY individual item in a framework or list that has a definition or example in the text.
16
+ 3. **WORD-FOR-WORD DEFINITIONS:** You must extract the full, detailed definition for each item exactly as provided. Do not summarize or simplify.
17
+ 4. **ZERO OMISSION:** If a slide provides a "Scenario" and "Solution" for a specific sub-item (like "Observation"), that Scenario/Solution MUST appear directly under that item's H3 heading.
18
 
19
+ **STRICT OUTPUT SCHEMA:**
 
 
 
 
 
 
 
 
 
20
  # [Document Title / Main Topic]
21
 
22
  **Overview:** [A brief 2-3 sentence overview of the entire document]
23
 
24
  ## [Major Section Heading]
25
+ [Introduction to the section]
26
+
27
+ ### [Framework Item/Sub-topic 1]
28
+ * **Full Definition:** [Extract exhaustive definition word-for-word]
29
+ * **Context/Importance:** [Detailed context from text]
30
+ * **Scenario:** [Specific scenario for this item]
31
+ * **Solution/Result:** [Solution for this scenario]
32
 
33
+ ### [Framework Item/Sub-topic 2]
34
+ *(Repeat this H3 structure for EVERY item. NEVER group them into a single list)*
 
 
35
 
36
  ## Key Scenarios & Practical Applications
37
+ *(Capture any general scenarios that weren't specific to a sub-topic)*
 
38
 
39
  ## Final Summary & Synthesis
40
+ [Comprehensive wrap-up]
41
+
42
+ **FINAL INSTRUCTION:** If you are unsure whether to group or expand, ALWAYS EXPAND. Your goal is a 100% lossless recovery of the lecture's detail.`;
43
 
44
  Deno.serve(async (req) => {
45
  if (req.method === "OPTIONS") return new Response("ok", { headers: corsHeaders });