File size: 1,823 Bytes
ac1f51b
74bb5fe
 
ac1f51b
 
74bb5fe
 
 
ac1f51b
74bb5fe
ac1f51b
74bb5fe
ac1f51b
74bb5fe
 
 
 
ac1f51b
 
 
74bb5fe
ac1f51b
 
 
74bb5fe
ac1f51b
 
 
 
 
 
 
 
74bb5fe
 
ac1f51b
74bb5fe
ac1f51b
74bb5fe
 
 
ac1f51b
 
 
 
 
 
 
74bb5fe
 
ac1f51b
 
74bb5fe
 
 
 
 
 
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
57
58
# utils/config.py
from __future__ import annotations
import os
from typing import Optional
from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic import Field

class Settings(BaseSettings):
    # --- Core LLM backend ---
    BACKEND_LLM: str = Field(default="llamacpp")  # 'llamacpp' | 'openai' | 'groq'
    LLAMACPP_MODEL_PATH: Optional[str] = Field(default=None)

    # llama.cpp runtime knobs
    N_CTX: int = 4096
    N_THREADS: int = 4
    N_GPU_LAYERS: int = 0

    # ASR / TTS
    ASR_DEVICE: str = "cpu"  # 'mps' | 'cpu'
    TTS_ENGINE: str = "pyttsx3"  # 'pyttsx3' | 'say' | 'piper'

    # Piper specifics (optional, only used if TTS_ENGINE='piper')
    PIPER_MODEL: Optional[str] = None           # e.g. "models/piper/en_US-amy-medium.onnx"
    PIPER_BIN: str = "piper"                    # executable name or absolute path

    # Where we persist session audio (created elsewhere if missing)
    VOICE_AUDIO_DIR: str = "runtime/audio"

    # Cloud keys (optional)
    OPENAI_API_KEY: Optional[str] = None
    GROQ_API_KEY: Optional[str] = None

    # App flags
    IS_HF_SPACE: bool = False
    DEBUG: bool = True
    CAFE_UNRELATED_LIMIT: int = 3

    model_config = SettingsConfigDict(env_file=".env", extra="ignore")

    def pretty(self) -> dict:
        d = self.model_dump()
        # Mask secrets
        for k in ("OPENAI_API_KEY", "GROQ_API_KEY"):
            if d.get(k):
                d[k] = True
        # Expand absolute path preview for convenience (doesn't change real value)
        if d.get("VOICE_AUDIO_DIR"):
            d["VOICE_AUDIO_DIR"] = os.path.abspath(d["VOICE_AUDIO_DIR"])
        return d


_settings: Optional[Settings] = None

def get_settings() -> Settings:
    global _settings
    if _settings is None:
        _settings = Settings()
    return _settings