Spaces:
Sleeping
Sleeping
iteration-2
Browse filesfine-tuned prompt template
- prompts.py +34 -34
prompts.py
CHANGED
|
@@ -1,46 +1,46 @@
|
|
| 1 |
-
# prompts.py
|
| 2 |
-
# Qwen-2.5 Compatible Prompts
|
| 3 |
|
| 4 |
def get_ocr_extraction_prompt(raw_text: str) -> str:
|
| 5 |
-
return f"""<|im_start|>system
|
| 6 |
-
You are a precise Data Extraction Engine.
|
| 7 |
-
Extract data from the text below and return a JSON object.
|
| 8 |
-
Fields: contact_name, total_amount, currency, invoice_date, line_items (name, quantity, rate).
|
| 9 |
-
Output ONLY JSON. No markdown.
|
| 10 |
-
<|im_end|>
|
| 11 |
-
<|im_start|>user
|
| 12 |
-
Input Text:
|
| 13 |
-
{raw_text[:3000]}
|
| 14 |
-
|
| 15 |
-
Return the JSON:
|
| 16 |
-
<|im_end|>
|
| 17 |
-
<|im_start|>assistant
|
| 18 |
-
"""
|
| 19 |
-
|
| 20 |
-
def get_agent_prompt(history_text: str, user_message: str) -> str:
|
| 21 |
"""
|
| 22 |
-
|
| 23 |
"""
|
| 24 |
return f"""<|im_start|>system
|
| 25 |
-
You are
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
1.
|
| 29 |
-
2.
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
<|im_end|>
|
|
|
|
| 38 |
<|im_start|>user
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
| 43 |
-
{user_message}
|
| 44 |
<|im_end|>
|
| 45 |
<|im_start|>assistant
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
def get_ocr_extraction_prompt(raw_text: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
"""
|
| 4 |
+
Returns a strict prompt with SOP and One-Shot example (City of Auburn invoice).
|
| 5 |
"""
|
| 6 |
return f"""<|im_start|>system
|
| 7 |
+
You are a specialized Invoice Extraction Agent.
|
| 8 |
+
Your task is to extract structured data from OCR text into a CANONICAL JSON format.
|
| 9 |
|
| 10 |
+
### STANDARD OPERATING PROCEDURE (SOP):
|
| 11 |
+
1. **Sanitization**: Ignore page headers, footers, and marketing messages.
|
| 12 |
+
2. **Dates**: Convert all dates to YYYY-MM-DD format.
|
| 13 |
+
3. **Null Handling**: If a field is not found, set it to null. DO NOT invent data.
|
| 14 |
+
4. **Line Items**: Extract the table of goods/services accurately.
|
| 15 |
+
5. **Output**: Return ONLY valid JSON. No Markdown. No commentary.
|
| 16 |
|
| 17 |
+
### ONE-SHOT EXAMPLE:
|
| 18 |
+
**Input OCR**:
|
| 19 |
+
"CITY OF AUBURN... Account Number: 076248-000... Due Date: 01/07/25...
|
| 20 |
+
Water Total $649.69... Sewer Total $1,333.45... Total New Charges $2,363.39"
|
| 21 |
+
|
| 22 |
+
**Correct JSON Output**:
|
| 23 |
+
{{
|
| 24 |
+
"invoice_number": "076248-000",
|
| 25 |
+
"vendor_name": "City of Auburn",
|
| 26 |
+
"invoice_date": "2024-12-18",
|
| 27 |
+
"due_date": "2025-01-07",
|
| 28 |
+
"total_amount": 2363.39,
|
| 29 |
+
"currency": "USD",
|
| 30 |
+
"line_items": [
|
| 31 |
+
{{"description": "Water Total", "amount": 649.69}},
|
| 32 |
+
{{"description": "Sewer Total", "amount": 1333.45}},
|
| 33 |
+
{{"description": "Storm Water Total", "amount": 380.25}}
|
| 34 |
+
]
|
| 35 |
+
}}
|
| 36 |
<|im_end|>
|
| 37 |
+
|
| 38 |
<|im_start|>user
|
| 39 |
+
### CURRENT TASK:
|
| 40 |
+
Extract JSON from the following OCR text:
|
| 41 |
|
| 42 |
+
{raw_text[:4000]}
|
|
|
|
| 43 |
<|im_end|>
|
| 44 |
<|im_start|>assistant
|
| 45 |
+
{{
|
| 46 |
+
""" # Pre-fill brace to force JSON mode
|