Initial commit
This commit is contained in:
20
templates/extraction/README.md
Normal file
20
templates/extraction/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Extraction Templates
|
||||
|
||||
Templates for data extraction patterns (invoice, resume, receipt, etc.)
|
||||
|
||||
## Pattern Structure
|
||||
|
||||
Each extraction template includes:
|
||||
- Input types (often image or text)
|
||||
- Output class definitions (structured data)
|
||||
- Extraction function with detailed prompt
|
||||
- Validation rules
|
||||
- Example test cases
|
||||
|
||||
## Common Use Cases
|
||||
|
||||
- Invoice extraction
|
||||
- Resume parsing
|
||||
- Receipt processing
|
||||
- Document analysis
|
||||
- Form extraction
|
||||
44
templates/extraction/invoice_extraction.baml
Normal file
44
templates/extraction/invoice_extraction.baml
Normal file
@@ -0,0 +1,44 @@
|
||||
// Example: Invoice Extraction Pattern
|
||||
// This template extracts structured invoice data from images
|
||||
|
||||
class LineItem {
|
||||
description string @description("Item description")
|
||||
quantity int @description("Number of units")
|
||||
unit_price float @description("Price per unit")
|
||||
total float @description("Line item total")
|
||||
}
|
||||
|
||||
class Invoice {
|
||||
invoice_number string @description("Invoice ID")
|
||||
date string @description("Invoice date (YYYY-MM-DD)")
|
||||
vendor_name string
|
||||
items LineItem[] @description("List of line items")
|
||||
subtotal float
|
||||
tax float
|
||||
total float @description("Grand total")
|
||||
}
|
||||
|
||||
client VisionModel {
|
||||
provider "openai"
|
||||
options {
|
||||
model "gpt-4o"
|
||||
temperature 0.0
|
||||
}
|
||||
}
|
||||
|
||||
function ExtractInvoice(invoice_image: image) -> Invoice {
|
||||
client VisionModel
|
||||
|
||||
prompt #"
|
||||
Extract all information from this invoice image.
|
||||
|
||||
{{ invoice_image }}
|
||||
|
||||
IMPORTANT:
|
||||
- Validate that subtotal + tax = total
|
||||
- Extract all line items accurately
|
||||
- Use YYYY-MM-DD format for dates
|
||||
|
||||
{{ ctx.output_format }}
|
||||
"#
|
||||
}
|
||||
Reference in New Issue
Block a user