When using the fallback provider, how can we tell ...
# ask-ai
g
When using the fallback provider, how can we tell which provider is actively being used
t
Thanks for reaching out, Aumesh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! To better assist you, could you please clarify how you'd like to determine the active provider when using the fallback provider? • Are you hoping to access this information programmatically within your code, or is it more for monitoring and debugging purposes? • Could you share a bit about your specific use case? For instance, are you aiming to log which provider handles each request, make decisions based on the active provider, or keep an eye on provider performance? • Also, are you using LiveKit Inference with automatic provider selection, or are you manually setting up multiple LLM instances in your FallbackAdapter? Sources: livekit-agents/livekit/agents/telemetry/traces.py
g
I am trying to access it within code, so I know best how to use which SSML parsing in my TTS node
t
To help you determine the active provider programmatically within your code, here are a couple of friendly approaches you can try: • Monitor Availability Events: The FallbackAdapter sends out
tts_availability_changed
events whenever providers become available or unavailable. By listening to these events, you can easily keep track of which providers are currently ready to use. • Access Internal Provider State: You can also peek into the internal structure of the FallbackAdapter to see the current provider order and their availability. For example, by going through the list of TTS instances and their statuses, you can find the first available provider—that’s your active one! Here’s a simple example to help you track the active provider:
Copy code
class ProviderTracker:
    def __init__(self, fallback_adapter):
        self.fallback_adapter = fallback_adapter
        self.current_provider = None
        fallback_adapter.on("tts_availability_changed", self._on_availability_changed)
    
    def _on_availability_changed(self, event):
        # Update tracking when availability changes
        self._update_current_provider()
    
    def _update_current_provider(self):
        # Find first available provider
        for i, (tts, status) in enumerate(zip(
            self.fallback_adapter._tts_instances, 
            self.fallback_adapter._status
        )):
            if status.available:
                self.current_provider = tts
                return
        self.current_provider = None
    
    def get_current_provider_info(self):
        if self.current_provider:
            return {
                'provider': self.current_provider.provider,
                'label': self.current_provider.label,
                'supports_ssml': hasattr(self.current_provider, '_opts') and 
                                   getattr(self.current_provider._opts, 'enable_ssml_parsing', False)
            }
        return None
This setup will let you dynamically keep an eye on the active provider and whether it supports SSML parsing. If you’d like, I’m here to help you with implementing this or configuring SSML parsing for specific providers—just let me know! Sources: livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/tts.p... | ElevenLabs TTS plugin guide | LiveKit Docs