Files
fund-tracer/backend/app/prompts/extract_transaction.py
2026-03-09 14:46:56 +08:00

42 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Prompt for extracting transactions from billing screenshots."""
EXTRACT_TRANSACTION_SYSTEM = """你是一个专业的金融交易数据提取助手专门用于从手机APP账单或交易记录截图中提取结构化信息。"""
EXTRACT_TRANSACTION_USER = """请分析这张手机APP账单/交易记录截图,提取所有可见的交易记录。
要求:
1. 只返回一个JSON数组不要包含其他说明文字。
2. 数组的每个元素是一条交易,包含以下字段(若截图中无该信息则填 null
- app_source: stringAPP来源"微信支付""支付宝""XX银行""XX钱包"
- transaction_type: string交易类型"转出""转入""消费""收款""提现""充值"
- amount: number金额数字不含货币符号
- currency: string币种"CNY""USDT",默认 "CNY"
- counterparty_name: string | null对方名称/姓名
- counterparty_account: string | null对方账号、卡号尾号、钱包地址等
- order_number: string | null订单号/交易号
- transaction_time: string | null交易时间请用 ISO 8601 格式,如 "2024-01-15T14:30:00"
- remark: string | null备注/摘要
- confidence: string识别置信度"high""medium""low" 之一
3. 注意区分转入和转出方向;金额统一为正数,方向由 transaction_type 体现。
4. 若截图中没有交易记录或无法识别,返回空数组 []。
直接输出JSON数组不要用 markdown 代码块包裹。"""
def get_extract_messages(image_b64: str) -> list[dict]:
"""Build messages for vision API: system + user with image."""
return [
{"role": "system", "content": EXTRACT_TRANSACTION_SYSTEM},
{
"role": "user",
"content": [
{"type": "text", "text": EXTRACT_TRANSACTION_USER},
{
"type": "image_url",
"image_url": {"url": f"data:image/jpeg;base64,{image_b64}"},
},
],
},
]