refactor(settings): tighten types on closed choices, containers and bounds

Enum-like settings whose allowed values were only listed in a comment are
now Literal types, so a typo fails at startup with a message naming the
allowed values instead of falling through to a default with a warning
(or, for VECTOR_STORE, failing on first use):

  AUTH_TYPE, VECTOR_STORE, STORAGE_TYPE, URL_STRATEGY, OCR_BACKEND,
  OCR_ENGINE, SANDBOX_BACKEND, DOC_PARSER_ENGINE, TTS_PROVIDER, STT_PROVIDER

Each keeps a before-validator that strips and lower-cases the value, since
the registries that consume them already lower-cased at the use site, and
AUTH_TYPE maps the "None"/"none"/"" spellings a .env file carries to None
(it was the string "None" before, which only worked because nothing
compared against it). An empty TTS/STT provider still means "off".
LLM_PROVIDER stays a plain str because providers are plugin-extensible.

Containers are typed (dict[str, int], list[str], dict[str, Any]) instead
of bare dict/list, six fields that were Optional with a non-None default
are plain, and integer settings whose description already states a range
carry it as a constraint (ge=0 for "0 disables", ge=1 for counts that
cannot be zero, 0 < threshold <= 1).
This commit is contained in:
arc53-machine committed 2026-09-17 11:08:50 +01:00
1 parent 5a5226ebe0
commit 95d0799494
19 files changed
+206 -97

No files matched your search

+13 -6
View File
@@ -2,22 +2,22 @@
from __future__ import annotations
from typing import Optional
from typing import Literal, Optional
from pydantic import Field, field_validator
from docsgpt.core.settings._shared import SettingsGroup, normalize_secret
from docsgpt.core.settings._shared import SettingsGroup, normalize_choice, normalize_secret
class SpeechSettings(SettingsGroup):
"""Voice providers and transcription options."""
TTS_PROVIDER: str = Field(
default="google_tts", description="Text-to-speech provider: google_tts, elevenlabs, or none to switch it off."
TTS_PROVIDER: Literal["google_tts", "elevenlabs", "none"] = Field(
default="google_tts", description="Text-to-speech provider; none switches it off."
)
ELEVENLABS_API_KEY: Optional[str] = Field(default=None, description="ElevenLabs API key.")
STT_PROVIDER: str = Field(
default="openai", description="Speech-to-text provider: openai, faster_whisper, or none to switch it off."
STT_PROVIDER: Literal["openai", "faster_whisper", "none"] = Field(
default="openai", description="Speech-to-text provider; none switches it off."
)
OPENAI_STT_MODEL: str = Field(default="gpt-4o-mini-transcribe", description="OpenAI transcription model.")
STT_LANGUAGE: Optional[str] = Field(default=None, description="Language hint for transcription; unset auto-detects.")
@@ -29,3 +29,10 @@ class SpeechSettings(SettingsGroup):
@classmethod
def _normalize_speech_secrets(cls, v):
return normalize_secret(v)
@field_validator("TTS_PROVIDER", "STT_PROVIDER", mode="before")
@classmethod
def _normalize_speech_providers(cls, v):
# An empty value has always meant "off"; keep that spelling working.
v = normalize_choice(v)
return "none" if v == "" else v