From a4ea060a6e87fa346dc923fdad7c70997c77813a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kadir=20Y=C3=B6nak?= Date: Sun, 6 Sep 2026 01:34:51 +0300 Subject: [PATCH] =?UTF-8?q?feat(ingest):=20DeepSeek-VL=20varsay=C4=B1lan?= =?UTF-8?q?=20captioner=20(mevcut=20key,=20yeni=20key=20yok)=20=E2=80=94?= =?UTF-8?q?=20Refs=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ingest/canonical.py | 4 ++-- src/providers/vlm.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) 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()