Skip to content

Latest commit

 

History

History
65 lines (49 loc) · 2.99 KB

File metadata and controls

65 lines (49 loc) · 2.99 KB

LLM Processing

This folder contains the server-side AI integration for CV optimization and HTML translation.

Main entry point

File guide

Provider switching

Use .env or server env vars only:

  • AI_PROVIDER=openai
  • AI_PROVIDER=gemini
  • AI_PROVIDER=openrouter

Required variables:

  • AI_PROVIDER
  • AI_PROVIDER_API_KEY
  • AI_PROVIDER_MODEL

Optional variables:

  • AI_PROVIDER_BASE_URL
  • AI_TEMPERATURE
  • AI_MAX_OUTPUT_TOKENS
  • AI_TOP_P
  • AI_OPENROUTER_HTTP_REFERER
  • AI_OPENROUTER_TITLE

Data flow

flowchart TD
    Upload["/api/upload or /api/translate"] --> Facade["ai-provider-service.ts"]
    Facade --> Shared["OpenAI-compatible chat builder/client"]
    Facade --> GeminiPdf["Gemini native PDF adapter"]
    Facade --> PdfFallback["Validated PDF text fallback workflow"]
    Shared --> Providers["OpenAI | Gemini OpenAI endpoint | OpenRouter"]
    GeminiPdf --> Gemini["Gemini Files API + generateContent"]
    PdfFallback --> PdfExtract["Page-by-page extraction + quality gates"]
    PdfExtract --> Providers
Loading

Important behavior

  • Browser translation still runs first in the client; the server provider is only the fallback.
  • The remote translation fallback reuses AI_PROVIDER_MODEL; there is no separate translation model env var anymore.
  • Gemini-specific naming from the previous integration was removed from the public service layer.
  • PDF handling is provider-aware:
    • gemini: native Files API branch first, then validated text fallback when the failure is explicitly file/PDF-related
    • openai and openrouter: OpenAI-compatible file content parts first, then validated text fallback when the failure is explicitly file/PDF-related
  • Generic provider failures do not trigger PDF fallback.
  • If extracted PDF text looks incomplete or unreliable, the workflow fails with an explicit no-OCR error instead of sending partial text to the LLM.
  • There is no provider fallback chain. Missing env vars or unsupported models return explicit errors.