"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
Merge PR #548: feat(ocr): pluggable engine architecture + LLM vision OCR + configurable threshold
Haozhe Wuc1f9f96a60bd
diff --cc agent/src/tools/ocr/engine.pyindex ede9a9431,5f6ac4a62..4f5db4a78--- a/agent/src/tools/ocr/engine.py+++ b/agent/src/tools/ocr/engine.py@@@ -42,22 -97,46 +97,57 @@@ def _get_ocr_choice() -> strreturn get_env_config().ocr.vibe_trading_ocr_engine.strip().lower()+ def _select_first_local(engines: dict[str, type]) -> OcrEngine | None:+ """Return the first available local (non-cloud) engine, sorted by name.++ Instantiates every registered engine to probe :meth:`is_available`, so+ engine ``__init__`` must be cheap (attribute assignment only). Expensive+ work belongs in :meth:`is_available` or :meth:`recognize` (lazy init).+ Cloud engines (``is_cloud=True``) are skipped — privacy red line.+ """+ for name, cls in sorted(engines.items()):+ try:+ engine = cls()+ if engine.is_available() and not engine.is_cloud:+ return engine+ except Exception:+ continue+ return None++def get_ocr_engine() -> OcrEngine | None:- """Return the configured OCR engine, or None if unavailable.+ """Return the configured OCR engine, or None.Engine selection via VIBE_TRADING_OCR_ENGINE:- - "auto" (default): local RapidOCR if installed, else no OCR- - "rapid": RapidOCR only (local, ONNX)- - "qwen-vl": Qwen-VL vision model (cloud, DashScope API)+ - "auto" (default): try all LOCAL (is_cloud=False) engines+ - "<name>": try that specific engine (local or cloud)- "none": disable OCR entirely- Cloud OCR is never auto-selected: document pages leave the machine, so- "qwen-vl" must be an explicit user choice.+ Cloud engines are NEVER auto-selected (privacy: pages leave the machine).+ Plugins override built-in engines on name collision."""choice = _get_ocr_choice()- if choice not in _VALID_ENGINES:- logger.warning("Unknown OCR engine '%s', falling back to 'auto'", choice)- choice = "auto"+ # Apply backward compat aliases (Issue #547)+ if choice in _CHOICE_ALIASES:+ new_name = _CHOICE_ALIASES[choice]++ # The qwen-vl → llm-vision rename is not credential-preserving: the old++ # DashScope-locked engine read DASHSCOPE_API_KEY + a fixed DashScope base++ # URL, whereas llm-vision resolves credentials from the configured++ # LANGCHAIN_PROVIDER. Call that out so DashScope users aren't surprised.++ migration = (++ " llm-vision now uses your configured LANGCHAIN_PROVIDER credentials"++ " instead of DASHSCOPE_API_KEY — set LANGCHAIN_PROVIDER/model to a"++ " vision-capable provider (e.g. dashscope) to keep the same backend."++ if choice == "qwen-vl"++ else ""++ )+ logger.warning(+ "OCR engine '%s' is deprecated; use '%s' instead. "- "Alias will be removed in a future release.",- choice, new_name,++ "Alias will be removed in a future release.%s",++ choice, new_name, migration,+ )+ choice = new_name+ engines = _all_engines()if choice == "none":return None