diff --git a/src/ingest/canonical.py b/src/ingest/canonical.py index ac7cb8f..6b13c01 100644 --- a/src/ingest/canonical.py +++ b/src/ingest/canonical.py @@ -118,8 +118,8 @@ def build_canonical(path: str, sinif: str, ders: str, *, if vlm: from .visual_caption import caption_visual_units, merge_visual_units if captioner is None: - from ..providers.vlm import VLMCaptioner - captioner = VLMCaptioner() + from ..providers.vlm import default_captioner + captioner = default_captioner() vunits = caption_visual_units(path, doc_id=doc_id, sinif=sinif, ders=ders, kaynak_turu=kaynak_turu, page_visual=page_visual, captioner=captioner) diff --git a/src/providers/vlm.py b/src/providers/vlm.py index 262d34f..a4b35d3 100644 --- a/src/providers/vlm.py +++ b/src/providers/vlm.py @@ -94,3 +94,22 @@ class VLMCaptioner: def caption(self, image_png: bytes, **kw) -> str: """Yalnız betim metni (maliyet gerekmezse).""" return self.caption_with_usage(image_png, **kw).text + + +# DeepSeek API'nin görsel modeli (canlı /models ile doğrulandı 2026-09-06); mevcut +# DEEPSEEK_API_KEY ile çalışır — ayrı vision key gerekmez. +DEEPSEEK_VISION_MODEL = "deepseek-v4-flash-vision-exp" +DEEPSEEK_BASE = "https://api.deepseek.com" + + +def default_captioner(timeout: float = 120.0) -> VLMCaptioner: + """Sağlayıcı seçimi: VLM_* env verilmişse ONU kullanır (herhangi OpenAI-uyumlu + VLM); yoksa mevcut `DEEPSEEK_API_KEY` ile DeepSeek-VL'e düşer (yeni key yok). + İkisi de yoksa kullanılamaz captioner (zarif degradasyon).""" + if os.environ.get("VLM_API_KEY") and os.environ.get("VLM_BASE_URL") and os.environ.get("VLM_MODEL"): + return VLMCaptioner(timeout=timeout) + dk = os.environ.get("DEEPSEEK_API_KEY") + if dk: + return VLMCaptioner(model=DEEPSEEK_VISION_MODEL, base_url=DEEPSEEK_BASE, + api_key=dk, timeout=timeout) + return VLMCaptioner()