fix: increase timeout and parallelize receipt processing
- ab_ai_bot: raise requests.post timeout 120s -> 600s so long OCR+LLM runs don't silently drop the reply in Discuss - upload: run parse_upload in ThreadPoolExecutor so tesseract OCR doesn't block the FastAPI event loop - expenses_agent: parse all receipts concurrently with asyncio.gather (Ollama semaphore caps parallelism at 2); reduces 13-receipt LLM time from ~39s sequential to ~20s parallel Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,12 +31,18 @@ async def upload(
|
||||
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
detail='Agent service not ready')
|
||||
|
||||
import asyncio
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
_ocr_executor = ThreadPoolExecutor(max_workers=2)
|
||||
|
||||
receipts: list[dict] = []
|
||||
loop = asyncio.get_event_loop()
|
||||
for f in files:
|
||||
data = await f.read()
|
||||
filename = f.filename or 'receipt'
|
||||
try:
|
||||
parsed = parse_upload(filename, data)
|
||||
# parse_upload may run OCR (CPU-bound) — offload to thread pool
|
||||
parsed = await loop.run_in_executor(_ocr_executor, parse_upload, filename, data)
|
||||
receipts.extend(parsed)
|
||||
logger.info('upload: parsed %s → %d receipt(s)', filename, len(parsed))
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user