Files
DocsGPT/docsgpt/core/settings/speech.py
T
arc53-machine 5578039c19 refactor(settings): treat unset spellings of every optional string as None
Review follow-up. The per-group secret validators normalised a hand-picked
list of API keys, which left other optional credentials and overrides
(OPEN_ROUTER_API_KEY, S3 and Daytona keys, ELASTIC_PASSWORD, the OIDC
trio, connector client ids, MICROSOFT_AUTHORITY, MCP_OAUTH_REDIRECT_URI)
holding the literal "None" or "" a .env file spells "unset" with, so
truthiness checks and fallbacks downstream saw a value. One rule on the
group base replaces those lists: every Optional[str] field maps "", "None"
and whitespace to None and strips real values. Plain str fields are left
alone. The OIDC required-settings check therefore also rejects those
spellings.

EMBEDDINGS_POOLING is Literal["cls", "mean"] with case-insensitive
parsing; its consumer silently ignored anything else.

Bounds added where the consumer rejects or misbehaves on the value:
SCHEDULE_RUN_OUTPUT_RETENTION_DAYS and MESSAGE_EVENTS_RETENTION_DAYS (the
cleanup repositories raise on <= 0), EMBEDDINGS_DELEGATE_TIMEOUT, the
remote-device idle/pairing/invocation TTLs and CELERY_VISIBILITY_TIMEOUT
(> 0), REMOTE_DEVICE_CMD_QUEUE_TTL_SECONDS (> 605, the documented drain
deadline), GRAPHRAG_MAX_CHUNKS_FOR_EXTRACTION (>= 0; negative would slice
the pending list from the end).

The generated reference now renders generic type arguments
(dict[str, int] rather than dict).
2026-09-17 11:37:57 +01:00

34 lines
1.6 KiB
Python

"""Text-to-speech and speech-to-text."""
from __future__ import annotations
from typing import Literal, Optional
from pydantic import Field, field_validator
from docsgpt.core.settings._shared import SettingsGroup, normalize_choice
class SpeechSettings(SettingsGroup):
"""Voice providers and transcription options."""
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: 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.")
STT_MAX_FILE_SIZE_MB: int = Field(default=50, description="Cap on an audio file accepted for transcription.")
STT_ENABLE_TIMESTAMPS: bool = Field(default=False, description="Return word/segment timestamps.")
STT_ENABLE_DIARIZATION: bool = Field(default=False, description="Label speakers in the transcript.")
@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