Spaces:
Sleeping
Sleeping
File size: 1,842 Bytes
d9ec52f a4807ce d9ec52f 0f06d06 d9ec52f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | """
ccpu_parser.config
------------------
Gestion centralisée de la configuration (variables d'environnement) pour
le parser CCPU.
"""
from __future__ import annotations
import os
from functools import lru_cache
class Settings:
"""Objet de configuration simple, chargé à partir des variables d'environnement."""
def __init__(self) -> None:
self.LLM_PROVIDER: str = os.getenv("LLM_PROVIDER", "deepinfra").lower()
self.LLM_MODEL: str = os.getenv(
"LLM_MODEL",
"NousResearch/Hermes-3-Llama-3.1-70B",
)
self.LLM_ENDPOINT: str | None = os.getenv("LLM_ENDPOINT") or None
self.LLM_API_KEY: str | None = os.getenv("LLM_API_KEY") or None
self.LLM_TEMPERATURE: float = float(os.getenv("LLM_TEMPERATURE", "0.1"))
self.LLM_MAX_NEW_TOKENS: int = int(os.getenv("LLM_MAX_NEW_TOKENS", "2048"))
self.MAX_PROMPT_CHARS: int = int(os.getenv("MAX_PROMPT_CHARS", "30000"))
self.HTTP_TIMEOUT_SECONDS: int = int(
os.getenv("HTTP_TIMEOUT_SECONDS", "120")
)
@property
def resolved_llm_endpoint(self) -> str:
"""Détermine l'endpoint HTTP final pour le LLM en fonction du provider."""
if self.LLM_ENDPOINT:
return self.LLM_ENDPOINT
if self.LLM_PROVIDER == "huggingface":
# API Inference standard
return f"https://api-inference.huggingface.co/models/{self.LLM_MODEL}"
if self.LLM_PROVIDER == "deepinfra":
# Endpoint DeepInfra générique (à ajuster si besoin)
return f"https://api.deepinfra.com/v1/inference/{self.LLM_MODEL}"
raise RuntimeError(f"Unknown LLM_PROVIDER: {self.LLM_PROVIDER!r}")
@lru_cache(maxsize=1)
def get_settings() -> Settings:
"""Retourne un singleton Settings (caché)."""
return Settings()
|