Clean up config and STT naming
This commit is contained in:
parent
b74aaaa1c4
commit
8c68719041
9 changed files with 42 additions and 98 deletions
|
|
@ -1,22 +1,16 @@
|
|||
import json
|
||||
import os
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def _parse_bool(val: str) -> bool:
|
||||
return val.strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
daemon: dict = field(default_factory=lambda: {"hotkey": "Cmd+m"})
|
||||
recording: dict = field(default_factory=lambda: {"input": ""})
|
||||
transcription: dict = field(default_factory=lambda: {"model": "base", "device": "cpu"})
|
||||
stt: dict = field(default_factory=lambda: {"model": "base", "device": "cpu"})
|
||||
injection: dict = field(default_factory=lambda: {"backend": "clipboard"})
|
||||
ai_cleanup: dict = field(
|
||||
default_factory=lambda: {
|
||||
"enabled": False,
|
||||
"model": "llama3.2:3b",
|
||||
"temperature": 0.0,
|
||||
"base_url": "http://localhost:11434",
|
||||
|
|
@ -36,19 +30,16 @@ def load(path: str | None) -> Config:
|
|||
p = Path(path) if path else default_path()
|
||||
if p.exists():
|
||||
data = json.loads(p.read_text(encoding="utf-8"))
|
||||
if any(k in data for k in ("daemon", "recording", "transcription", "transcribing", "injection", "ai_cleanup", "ai")):
|
||||
if any(k in data for k in ("daemon", "recording", "stt", "injection", "ai_cleanup", "ai")):
|
||||
for k, v in data.items():
|
||||
if hasattr(cfg, k):
|
||||
setattr(cfg, k, v)
|
||||
if "transcribing" in data and "transcription" not in data:
|
||||
cfg.transcription = data.get("transcribing", cfg.transcription)
|
||||
else:
|
||||
cfg.daemon["hotkey"] = data.get("hotkey", cfg.daemon["hotkey"])
|
||||
cfg.recording["input"] = data.get("ffmpeg_input", cfg.recording["input"])
|
||||
cfg.transcription["model"] = data.get("whisper_model", cfg.transcription["model"])
|
||||
cfg.transcription["device"] = data.get("whisper_device", cfg.transcription["device"])
|
||||
cfg.recording["input"] = data.get("input", cfg.recording["input"])
|
||||
cfg.stt["model"] = data.get("whisper_model", cfg.stt["model"])
|
||||
cfg.stt["device"] = data.get("whisper_device", cfg.stt["device"])
|
||||
cfg.injection["backend"] = data.get("injection_backend", cfg.injection["backend"])
|
||||
cfg.ai_cleanup["enabled"] = data.get("ai_enabled", cfg.ai_cleanup["enabled"])
|
||||
cfg.ai_cleanup["model"] = data.get("ai_model", cfg.ai_cleanup["model"])
|
||||
cfg.ai_cleanup["temperature"] = data.get("ai_temperature", cfg.ai_cleanup["temperature"])
|
||||
cfg.ai_cleanup["base_url"] = data.get("ai_base_url", cfg.ai_cleanup["base_url"])
|
||||
|
|
@ -58,13 +49,12 @@ def load(path: str | None) -> Config:
|
|||
cfg.daemon = {"hotkey": "Cmd+m"}
|
||||
if not isinstance(cfg.recording, dict):
|
||||
cfg.recording = {"input": ""}
|
||||
if not isinstance(cfg.transcription, dict):
|
||||
cfg.transcription = {"model": "base", "device": "cpu"}
|
||||
if not isinstance(cfg.stt, dict):
|
||||
cfg.stt = {"model": "base", "device": "cpu"}
|
||||
if not isinstance(cfg.injection, dict):
|
||||
cfg.injection = {"backend": "clipboard"}
|
||||
if not isinstance(cfg.ai_cleanup, dict):
|
||||
cfg.ai_cleanup = {
|
||||
"enabled": False,
|
||||
"model": "llama3.2:3b",
|
||||
"temperature": 0.0,
|
||||
"base_url": "http://localhost:11434",
|
||||
|
|
@ -80,40 +70,6 @@ def load(path: str | None) -> Config:
|
|||
except Exception:
|
||||
pass
|
||||
|
||||
# env overrides
|
||||
if os.getenv("WHISPER_MODEL"):
|
||||
cfg.transcription["model"] = os.environ["WHISPER_MODEL"]
|
||||
if os.getenv("WHISPER_DEVICE"):
|
||||
cfg.transcription["device"] = os.environ["WHISPER_DEVICE"]
|
||||
if os.getenv("WHISPER_FFMPEG_IN"):
|
||||
cfg.recording["input"] = os.environ["WHISPER_FFMPEG_IN"]
|
||||
|
||||
if os.getenv("LEL_HOTKEY"):
|
||||
cfg.daemon["hotkey"] = os.environ["LEL_HOTKEY"]
|
||||
if os.getenv("LEL_INJECTION_BACKEND"):
|
||||
cfg.injection["backend"] = os.environ["LEL_INJECTION_BACKEND"]
|
||||
|
||||
if os.getenv("LEL_AI_CLEANUP_ENABLED"):
|
||||
cfg.ai_cleanup["enabled"] = _parse_bool(os.environ["LEL_AI_CLEANUP_ENABLED"])
|
||||
if os.getenv("LEL_AI_CLEANUP_MODEL"):
|
||||
cfg.ai_cleanup["model"] = os.environ["LEL_AI_CLEANUP_MODEL"]
|
||||
if os.getenv("LEL_AI_CLEANUP_TEMPERATURE"):
|
||||
cfg.ai_cleanup["temperature"] = float(os.environ["LEL_AI_CLEANUP_TEMPERATURE"])
|
||||
if os.getenv("LEL_AI_CLEANUP_BASE_URL"):
|
||||
cfg.ai_cleanup["base_url"] = os.environ["LEL_AI_CLEANUP_BASE_URL"]
|
||||
if os.getenv("LEL_AI_CLEANUP_API_KEY"):
|
||||
cfg.ai_cleanup["api_key"] = os.environ["LEL_AI_CLEANUP_API_KEY"]
|
||||
|
||||
if os.getenv("LEL_AI_ENABLED"):
|
||||
cfg.ai_cleanup["enabled"] = _parse_bool(os.environ["LEL_AI_ENABLED"])
|
||||
if os.getenv("LEL_AI_MODEL"):
|
||||
cfg.ai_cleanup["model"] = os.environ["LEL_AI_MODEL"]
|
||||
if os.getenv("LEL_AI_TEMPERATURE"):
|
||||
cfg.ai_cleanup["temperature"] = float(os.environ["LEL_AI_TEMPERATURE"])
|
||||
if os.getenv("LEL_AI_BASE_URL"):
|
||||
cfg.ai_cleanup["base_url"] = os.environ["LEL_AI_BASE_URL"]
|
||||
if os.getenv("LEL_AI_API_KEY"):
|
||||
cfg.ai_cleanup["api_key"] = os.environ["LEL_AI_API_KEY"]
|
||||
validate(cfg)
|
||||
return cfg
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue