# app/schemas.py from pydantic import BaseModel, Field from typing import List, Optional # --- 分类结果模型 --- class ClassificationResult(BaseModel): """Defines the structured output for the classification agent.""" category: str = Field(description="The category of the document, must be one of ['LETTER', 'INVOICE', 'RECEIPT', 'CONTRACT', 'OTHER']") language: str = Field(description="The detected primary language of the document as a two-letter code (e.g., 'en', 'zh', 'es').") # --- 现有模型 (无变化) --- class ReceiptItem(BaseModel): name: str = Field(description="购买的项目或服务名称") quantity: float = Field(description="项目数量") price: float = Field(description="项目单价") class ReceiptInfo(BaseModel): merchant_name: Optional[str] = Field(None, description="商户或店铺的名称") transaction_date: Optional[str] = Field(None, description="交易日期,格式为 YYYY-MM-DD") total_amount: Optional[float] = Field(None, description="收据上的总金额") items: Optional[List[ReceiptItem]] = Field(None, description="购买的所有项目列表") # --- 新增: 发票行项目模型 --- class LineItem(BaseModel): """Defines a single line item from an invoice.""" description: Optional[str] = Field("", description="The description of the product or service.") quantity: Optional[float] = Field(None, description="The quantity of the item.") unit_price: Optional[float] = Field(None, description="The price for a single unit of the item.") total_price: Optional[float] = Field(None, description="The total price for this line item (quantity * unit_price).") # --- 发票模型 (已更新) --- class InvoiceInfo(BaseModel): """Defines the detailed, structured information to be extracted from an invoice.""" date: Optional[str] = Field("", description="Extract in YYYY-MM-DD format. If unclear, leave as an empty string.") invoice_number: Optional[str] = Field("", description="If not found or unclear, leave as an empty string.") supplier_number: Optional[str] = Field("", description="It's the organisation number. If not found or unclear, leave as an empty string.") biller_name: Optional[str] = Field("", description="It's the sender's name. If not found or unclear, leave as an empty string.") amount: Optional[float] = Field(None, description="Extract and format to decimal. If not present, leave as null.") customer_name: Optional[str] = Field("", description="It's the receiver's name. Clean any special chars from the name. If not found or unclear, leave as an empty string.") customer_address: Optional[str] = Field("", description="It's the receiver's address. Put it in one line. If not found or unclear, leave as an empty string.") customer_address_line: Optional[str] = Field("", description="It's the receiver's address line, not the whole address. If not found or unclear, leave as an empty string.") customer_address_city: Optional[str] = Field("", description="It's the receiver's address city. If not found, find a city in the document. If unclear, leave as an empty string.") customer_address_country: Optional[str] = Field("", description="It's the receiver's address country. If not found, find the country of the extracted city. If unclear, leave as an empty string.") customer_address_postal_code: Optional[str] = Field("", description="It's the receiver's address postal code. If not found or unclear, leave as an empty string.") customer_address_apartment: Optional[str] = Field("", description="It's the receiver's address apartment or suite. If not found or unclear, leave as an empty string.") customer_address_region: Optional[str] = Field("", description="It's the receiver's address region. If not found, find the region of the extracted city or country. If unclear, leave as an empty string.") customer_address_care_of: Optional[str] = Field("", description="It's the receiver's address care of. If not found or unclear, leave as an empty string.") billo_id: Optional[str] = Field("", description="Extract from customer_address if it exists, following the format 'LLL NNN-A'. If not found or unclear, leave as an empty string.") line_items: List[LineItem] = Field([], description="A list of all line items from the invoice.")