feat(backend): add PDF extraction with OCR fallback and cache
This commit is contained in:
1 parent
1b860dc599
commit
b75b746a40
8 files changed
+647
No files matched your search
@@ -0,0 +1,83 @@
|
||||
"""Configuração do backend via variáveis de ambiente."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Configuração lida do ambiente ou do arquivo .env."""
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=(".env", "../.env"),
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
# Caminhos
|
||||
pdf_dir: Path = Path("/data/pdfs")
|
||||
vector_db_dir: Path = Path("/data/vector_db")
|
||||
|
||||
# Provedor de LLM: ollama | openai | groq | anthropic | stub
|
||||
llm_provider: str = "ollama"
|
||||
ollama_base_url: str = "http://ollama:11434"
|
||||
ollama_model: str = "qwen2.5:1.5b"
|
||||
openai_base_url: str = "https://api.openai.com/v1"
|
||||
openai_model: str = "gpt-4o-mini"
|
||||
openai_api_key: str = ""
|
||||
groq_base_url: str = "https://api.groq.com/openai/v1"
|
||||
groq_model: str = "llama-3.3-70b-versatile"
|
||||
groq_api_key: str = ""
|
||||
anthropic_base_url: str = "https://api.anthropic.com"
|
||||
anthropic_model: str = "claude-sonnet-4-5"
|
||||
anthropic_api_key: str = ""
|
||||
|
||||
# Embeddings
|
||||
embedding_model: str = "paraphrase-multilingual-MiniLM-L12-v2"
|
||||
embedding_batch_size: int = 32
|
||||
|
||||
# Busca
|
||||
top_k: int = 6
|
||||
min_similarity: float = 0.35
|
||||
collection_name: str = "biblia"
|
||||
|
||||
# OCR
|
||||
ocr_dpi: int = 200
|
||||
ocr_language: str = "por+eng"
|
||||
ocr_timeout: int = 120
|
||||
ocr_workers: int = 4
|
||||
min_legible_ratio: float = 0.35
|
||||
|
||||
# API
|
||||
cors_origins: str = "http://localhost:8080,http://127.0.0.1:8080"
|
||||
reindex_token: str = ""
|
||||
max_message_length: int = 4000
|
||||
max_history_turns: int = 10
|
||||
|
||||
# Limites de ingestão
|
||||
max_pdf_bytes: int = 200 * 1024 * 1024
|
||||
|
||||
@property
|
||||
def ocr_cache_dir(self) -> Path:
|
||||
return self.vector_db_dir / "ocr_cache"
|
||||
|
||||
@property
|
||||
def manifest_path(self) -> Path:
|
||||
return self.vector_db_dir / "manifest.json"
|
||||
|
||||
@property
|
||||
def book_index_path(self) -> Path:
|
||||
return self.vector_db_dir / "book_index.json"
|
||||
|
||||
@property
|
||||
def cors_origin_list(self) -> list[str]:
|
||||
return [origin.strip() for origin in self.cors_origins.split(",") if origin.strip()]
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_settings() -> Settings:
|
||||
"""Devolve as settings singleton do processo."""
|
||||
return Settings()
|
||||
Reference in new issue
Block a user