diff --git a/README.md b/README.md index 071dc22..27442e4 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,12 @@ heuristic generator remains the fallback. The FastAPI settings object also accepts `llm_provider` and `llm_model`. By default `llm_provider` is unset, so analysis is fully offline and deterministic. +Environment variables use the `REPO_REGISTRY_` prefix: + +```bash +REPO_REGISTRY_LLM_PROVIDER=gemini +REPO_REGISTRY_LLM_MODEL=gemini-2.5-flash +``` ## Agent-Facing Endpoints diff --git a/src/repo_registry/web_api/app.py b/src/repo_registry/web_api/app.py index cfbe85d..695fe83 100644 --- a/src/repo_registry/web_api/app.py +++ b/src/repo_registry/web_api/app.py @@ -5,6 +5,7 @@ from pathlib import Path from fastapi import Depends, FastAPI, HTTPException from pydantic import BaseModel, Field +from pydantic_settings import BaseSettings, SettingsConfigDict from repo_registry.core.service import RegistryService from repo_registry.llm_extraction import LLMCandidateExtractor, create_llm_connect_adapter @@ -12,7 +13,9 @@ from repo_registry.repo_ingestion.git import GitIngestionService from repo_registry.storage.sqlite import NotFoundError, RegistryStore -class Settings(BaseModel): +class Settings(BaseSettings): + model_config = SettingsConfigDict(env_prefix="REPO_REGISTRY_") + database_path: str = Field(default="var/repo-registry.sqlite3") checkout_root: str = Field(default="var/checkouts") llm_provider: str | None = Field(default=None) diff --git a/tests/test_web_api.py b/tests/test_web_api.py index dea7197..5c2f689 100644 --- a/tests/test_web_api.py +++ b/tests/test_web_api.py @@ -193,6 +193,20 @@ def test_api_service_settings_can_enable_llm_extractor(monkeypatch, tmp_path): assert service.llm_extractor is not None +def test_settings_can_load_from_environment(monkeypatch): + monkeypatch.setenv("REPO_REGISTRY_DATABASE_PATH", "var/env.sqlite3") + monkeypatch.setenv("REPO_REGISTRY_CHECKOUT_ROOT", "var/env-checkouts") + monkeypatch.setenv("REPO_REGISTRY_LLM_PROVIDER", "mock") + monkeypatch.setenv("REPO_REGISTRY_LLM_MODEL", "demo-model") + + settings = Settings() + + assert settings.database_path == "var/env.sqlite3" + assert settings.checkout_root == "var/env-checkouts" + assert settings.llm_provider == "mock" + assert settings.llm_model == "demo-model" + + def test_api_analysis_run_loop(tmp_path): source = tmp_path / "repo" source.mkdir()