mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-07-10 11:12:13 +02:00
feat(tts): add xAI as a Voice (TTS) provider (#476)
* feat(tts): add xAI as a Voice (TTS) provider pipecat already ships an xAI TTS service (XAITTSService, WebSocket streaming) but dograh never wired it into the service configuration, so xAI could not be selected as a Voice provider in the cascading pipeline. Wire it through: - registry: ServiceProviders.XAI + XAITTSConfiguration (voices eve/ara/leo/rex/sal, language, computed model) registered in TTSConfig - service_factory: build XAITTSService in create_tts_service - check_validity: api-key validation hook - tests for the factory + docs The Voice provider dropdown is schema-driven, so xAI appears with no UI changes. * fix(tts): validate xAI API key and drop misleading auto-language hint Addresses review feedback on the xAI Voice provider: - check_validity: replace the no-op xAI key check with real validation against xAI's OpenAI-compatible API (models.list on https://api.x.ai/v1), so a bad BYOK key is caught at configuration time instead of at call time. - registry: remove the "auto" language hint from the field description. pipecat's Language enum has no "auto" member, so the factory fell back to English silently; the description no longer advertises detection we don't do. - tests: cover xAI key validation (registered, accepts valid, rejects bad). * fix(tts): validate xAI key against the TTS voices endpoint xAI supports endpoint-scoped API keys, so a key scoped to Text-to-Speech may lack the /v1/models ACL and would be wrongly rejected by the previous models.list() check. Validate against GET /v1/tts/voices instead — the scope the key actually needs for TTS — treating 401/403 as an invalid key and connection errors as a clean, actionable message. * fix: harden xAI TTS integration --------- Co-authored-by: Sabiha Khan <sabihak89@gmail.com> Co-authored-by: Sabiha Khan <87858386+chewwbaka@users.noreply.github.com>
This commit is contained in:
parent
fdb7f92fcc
commit
a2240db45a
7 changed files with 271 additions and 3 deletions
|
|
@ -64,6 +64,7 @@ class UserConfigurationValidator:
|
|||
ServiceProviders.RIME.value: self._check_rime_api_key,
|
||||
ServiceProviders.MINIMAX.value: self._check_minimax_api_key,
|
||||
ServiceProviders.SMALLEST.value: self._check_smallest_api_key,
|
||||
ServiceProviders.XAI.value: self._check_xai_api_key,
|
||||
}
|
||||
|
||||
async def validate(
|
||||
|
|
@ -376,6 +377,32 @@ class UserConfigurationValidator:
|
|||
def _check_grok_realtime_api_key(self, model: str, api_key: str) -> bool:
|
||||
return True
|
||||
|
||||
def _check_xai_api_key(self, model: str, api_key: str) -> bool:
|
||||
# Use the TTS voices endpoint as a best-effort smoke test. Some xAI keys
|
||||
# can be scoped in ways that block listing voices even though the key is
|
||||
# still intended for TTS usage, so only a clear auth failure rejects save.
|
||||
try:
|
||||
response = httpx.get(
|
||||
"https://api.x.ai/v1/tts/voices",
|
||||
headers={"Authorization": f"Bearer {api_key}"},
|
||||
timeout=10.0,
|
||||
)
|
||||
except httpx.RequestError:
|
||||
raise ValueError(
|
||||
"Could not connect to the xAI API. Please check your network "
|
||||
"connection and try again."
|
||||
)
|
||||
if response.status_code == 200:
|
||||
return True
|
||||
if response.status_code == 401:
|
||||
raise ValueError(
|
||||
"Invalid xAI API key. The key was rejected by the xAI API. "
|
||||
"Please check that your API key is correct and active. "
|
||||
"You can verify your keys at "
|
||||
"https://console.x.ai."
|
||||
)
|
||||
return True
|
||||
|
||||
def _check_ultravox_realtime_api_key(self, model: str, api_key: str) -> bool:
|
||||
return True
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue