feat(stt): support multi-model STT with parallel execution and consensus NLU extraction
This commit is contained in:
@@ -37,9 +37,30 @@ class Settings(BaseSettings):
|
||||
LLM_MODEL: str = "gpt-4o-mini"
|
||||
LLM_TIMEOUT_SECONDS: float = 60.0
|
||||
|
||||
# STT provider — any OpenAI-compatible /audio/transcriptions endpoint.
|
||||
# Falls back to the LLM provider when unset. Note: some providers
|
||||
# (e.g. DeepSeek) have no audio API — voice stays disabled gracefully.
|
||||
# STT providers — support multiple models/APIs in parallel.
|
||||
# 1. JSON list: [{"name": "m1", "base_url": "...", "api_key": "...", "model": "..."}, ...]
|
||||
STT_PROVIDERS_JSON: str = ""
|
||||
|
||||
# 2. Individual provider variables (up to 3 distinct STT models)
|
||||
STT_PROVIDER_1_NAME: str = "model-1"
|
||||
STT_PROVIDER_1_BASE_URL: str = ""
|
||||
STT_PROVIDER_1_API_KEY: str = ""
|
||||
STT_PROVIDER_1_MODEL: str = ""
|
||||
STT_PROVIDER_1_LANGUAGE: str = "fa"
|
||||
|
||||
STT_PROVIDER_2_NAME: str = "model-2"
|
||||
STT_PROVIDER_2_BASE_URL: str = ""
|
||||
STT_PROVIDER_2_API_KEY: str = ""
|
||||
STT_PROVIDER_2_MODEL: str = ""
|
||||
STT_PROVIDER_2_LANGUAGE: str = "fa"
|
||||
|
||||
STT_PROVIDER_3_NAME: str = "model-3"
|
||||
STT_PROVIDER_3_BASE_URL: str = ""
|
||||
STT_PROVIDER_3_API_KEY: str = ""
|
||||
STT_PROVIDER_3_MODEL: str = ""
|
||||
STT_PROVIDER_3_LANGUAGE: str = "fa"
|
||||
|
||||
# Legacy single STT provider fallback:
|
||||
STT_BASE_URL: str = ""
|
||||
STT_API_KEY: str = ""
|
||||
STT_MODEL: str = "whisper-1"
|
||||
@@ -53,6 +74,49 @@ class Settings(BaseSettings):
|
||||
def stt_api_key(self) -> str:
|
||||
return self.STT_API_KEY or self.AI_API_KEY
|
||||
|
||||
@property
|
||||
def stt_providers(self) -> list[dict]:
|
||||
import json
|
||||
if self.STT_PROVIDERS_JSON:
|
||||
try:
|
||||
data = json.loads(self.STT_PROVIDERS_JSON)
|
||||
if isinstance(data, list) and len(data) > 0:
|
||||
return data
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Check explicit STT_PROVIDER_1 / 2 / 3
|
||||
custom_list: list[dict] = []
|
||||
for idx in (1, 2, 3):
|
||||
b_url = getattr(self, f"STT_PROVIDER_{idx}_BASE_URL")
|
||||
key = getattr(self, f"STT_PROVIDER_{idx}_API_KEY")
|
||||
model = getattr(self, f"STT_PROVIDER_{idx}_MODEL")
|
||||
name = getattr(self, f"STT_PROVIDER_{idx}_NAME")
|
||||
lang = getattr(self, f"STT_PROVIDER_{idx}_LANGUAGE") or "fa"
|
||||
if b_url and key:
|
||||
custom_list.append({
|
||||
"name": name or f"model-{idx}",
|
||||
"base_url": b_url,
|
||||
"api_key": key,
|
||||
"model": model or self.STT_MODEL,
|
||||
"language": lang,
|
||||
"timeout": 30.0,
|
||||
})
|
||||
if custom_list:
|
||||
return custom_list
|
||||
|
||||
# Fallback to single legacy STT provider if set
|
||||
if self.stt_base_url and self.stt_api_key:
|
||||
return [{
|
||||
"name": "default",
|
||||
"base_url": self.stt_base_url,
|
||||
"api_key": self.stt_api_key,
|
||||
"model": self.STT_MODEL,
|
||||
"language": self.STT_LANGUAGE,
|
||||
"timeout": 30.0,
|
||||
}]
|
||||
return []
|
||||
|
||||
# PostgreSQL — same instance/database as the api service.
|
||||
DATABASE_URL: str = "postgresql+asyncpg://postgres:postgres@localhost:5432/procurement"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user