update: upload fix
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""Transaction data extraction: LLM Vision + persistence."""
|
||||
|
||||
from app.models import Transaction
|
||||
from app.models.database import async_session_maker
|
||||
import app.models.database as db_module
|
||||
from app.schemas.transaction import TransactionExtractItem, TransactionResponse
|
||||
from app.services.llm import get_llm_provider
|
||||
|
||||
@@ -10,15 +10,26 @@ async def extract_and_save(
|
||||
case_id: int,
|
||||
screenshot_id: int,
|
||||
image_bytes: bytes,
|
||||
progress_hook=None,
|
||||
) -> list[TransactionResponse]:
|
||||
"""
|
||||
Run vision extraction on image and persist transactions to DB.
|
||||
Returns list of created transactions; low-confidence items are still saved but flagged.
|
||||
"""
|
||||
if progress_hook:
|
||||
await progress_hook("init", 5, "初始化识别上下文")
|
||||
provider = get_llm_provider()
|
||||
if progress_hook:
|
||||
await progress_hook("provider_ready", 15, f"已加载模型提供商: {type(provider).__name__}")
|
||||
if progress_hook:
|
||||
await progress_hook("calling_model", 35, "调用视觉模型识别截图中交易")
|
||||
items: list[TransactionExtractItem] = await provider.extract_from_image(image_bytes)
|
||||
if progress_hook:
|
||||
await progress_hook("model_returned", 70, f"模型返回 {len(items)} 条交易")
|
||||
results: list[TransactionResponse] = []
|
||||
async with async_session_maker() as session:
|
||||
async with db_module.async_session_maker() as session:
|
||||
if progress_hook:
|
||||
await progress_hook("db_writing", 85, "写入交易记录到数据库")
|
||||
for it in items:
|
||||
t = Transaction(
|
||||
case_id=case_id,
|
||||
@@ -39,4 +50,6 @@ async def extract_and_save(
|
||||
await session.flush()
|
||||
results.append(TransactionResponse.model_validate(t))
|
||||
await session.commit()
|
||||
if progress_hook:
|
||||
await progress_hook("completed", 100, "识别完成")
|
||||
return results
|
||||
|
||||
Reference in New Issue
Block a user