witty-kangaroo-6889
10/03/2025, 6:53 AMtall-airline-16756
10/03/2025, 6:53 AMtall-airline-16756
10/03/2025, 6:53 AM.on() method is being called on a string rather than an actual LiveKit component instance. No worries—this is a common hiccup! To get this sorted, just make sure you’re using the correct object that’s returned when you instantiate or load the component.
For example, if you’re working with an LLM instance, here’s how it should look:
from livekit.plugins import openai
llm = openai.LLM(model="gpt-4o-mini") # Instantiate the LLM object
def metrics_callback(event):
print("Metrics collected:", event)
llm.on("metrics_collected", metrics_callback) # Register the listener
Just double-check that you’re not using a string like "openai.LLM" instead of the actual object. If you’re still running into trouble, please feel free to share which component you’re working with, and I’ll be happy to help you further!
Sources: metrics/metrics_vad.py | livekit-agents/livekit/agents/voice/agent_activity.py | Events and error handling | LiveKit Docswitty-kangaroo-6889
10/03/2025, 6:54 AMtall-airline-16756
10/03/2025, 6:54 AMfrom livekit.plugins import deepgram
stt = deepgram.STT() # This creates the STT object for you
def stt_metrics_callback(event):
print("STT Metrics:", event)
stt.on("metrics_collected", stt_metrics_callback)
For LLM:
from livekit.plugins import openai
llm = openai.LLM(model="gpt-4o-mini") # Here we instantiate the LLM object
def llm_metrics_callback(event):
print("LLM Metrics:", event)
llm.on("metrics_collected", llm_metrics_callback)
For TTS:
from livekit.plugins import google
tts = google.TTS() # And this sets up the TTS object
def tts_metrics_callback(event):
print("TTS Metrics:", event)
tts.on("metrics_collected", tts_metrics_callback)
Just make sure to swap out any string assignments with these object creations as shown. If anything feels unclear or you want me to walk you through any part in more detail, please don’t hesitate to ask—I’m here to help!witty-kangaroo-6889
10/03/2025, 6:55 AMtall-airline-16756
10/03/2025, 6:55 AM