classifier
Classifier backed by any Pipecat LLM service.
Every question about a state goes to the LLM in one out-of-pipeline call,
through the service’s run_inference(). The LLM is asked for one JSON
object with an answer per question, and the object is parsed into results.
- class pipecat.classifiers.llm.classifier.LLMClassifier(*, llm: LLMService[Any], instructions: str | None = None, max_tokens: int | None = None, timeout: float = 10.0, **kwargs)[source]
Bases:
BaseClassifierAnswers questions by asking an LLM for a JSON object.
The probabilities are whatever the LLM wrote, so they are not calibrated. Any service that implements
run_inference()can back a classifier; realtime services cannot. The reply’s shape is enforced by the provider where the service supports a reply schema, and otherwise asked for in the prompt and parsed from the reply.Example:
classifier = LLMClassifier(llm=OpenAILLMService(model="gpt-4o-mini")) results = await classifier.yes_no( "Hi, you've reached Dana. Leave a message.", {"voicemail": YesNoQuestion(instructions="is this a voicemail greeting?")}, ) results["voicemail"].probability
- __init__(*, llm: LLMService[Any], instructions: str | None = None, max_tokens: int | None = None, timeout: float = 10.0, **kwargs)[source]
Initialize the classifier.
- Parameters:
llm – The LLM that answers the questions.
instructions – System instructions for the LLM. The default asks for one JSON object with an answer per question.
max_tokens – Cap on the reply’s length, for services that take one.
timeout – Seconds to wait for the LLM’s reply before giving up.
**kwargs – Additional arguments passed to the parent class.
- property llm: LLMService[Any]
The LLM that answers the questions.