Coverage for src/fastoai/settings.py: 100%

1 from functools import lru_cache

2 from pathlib import Path

3 from typing import Annotated

4

5 from pydantic import Field

6 from pydantic_settings import BaseSettings

7

8

9 class OpenAISettings(BaseSettings, env_prefix="openai_", frozen=True): # type: ignore

10 """OpenAI settings."""

11

12 api_key: str

13 base_url: str = "https://api.openai.com/v1"

14

15

16 class Settings(BaseSettings, env_prefix="fastoai_", frozen=True): # type: ignore

17 """Settings."""

18

19 openai: Annotated[OpenAISettings, Field(default_factory=OpenAISettings)] # type: ignore

20 base_url: str = "http://127.0.0.1:8000"

21 database_url: str = "sqlite+aiosqlite:///"

22 upload_dir: Path = Path.home() / ".fastoai" / "uploads"

23 generate_models: bool = False

24

25 def model_post_init(self, __context):

26 self.upload_dir.mkdir(parents=True, exist_ok=True)

27

28

29@lru_cache

30 def get_settings() -> Settings:

31 """Get settings."""

32 return Settings() # type: ignore