AiService

Base AI service implementation.

Provides the foundation for all AI services in the Pipecat framework, including model management, settings handling, and frame processing lifecycle methods.

class pipecat.services.ai_service.AIService(**kwargs)[source]

Bases: FrameProcessor

Base class for all AI services.

Provides common functionality for AI services including model management, settings handling, session properties, and frame processing lifecycle. Subclasses should implement specific AI functionality while leveraging this base infrastructure.

Parameters:

**kwargs – Additional arguments passed to the parent FrameProcessor.

property model_name: str

Get the current model name.

Returns:

The name of the AI model being used.

set_model_name(model)[source]

Set the AI model name and update metrics.

Parameters:

model (str) – The name of the AI model to use.

async start(frame)[source]

Start the AI service.

Called when the service should begin processing. Subclasses should override this method to perform service-specific initialization.

Parameters:

frame (StartFrame) – The start frame containing initialization parameters.

async stop(frame)[source]

Stop the AI service.

Called when the service should stop processing. Subclasses should override this method to perform cleanup operations.

Parameters:

frame (EndFrame) – The end frame.

async cancel(frame)[source]

Cancel the AI service.

Called when the service should cancel all operations. Subclasses should override this method to handle cancellation logic.

Parameters:

frame (CancelFrame) – The cancel frame.

async process_frame(frame, direction)[source]

Process frames and handle service lifecycle.

Automatically handles StartFrame, EndFrame, and CancelFrame by calling the appropriate lifecycle methods.

Parameters:
  • frame (Frame) – The frame to process.

  • direction (FrameDirection) – The direction of frame processing.

async process_generator(generator)[source]

Process frames from an async generator.

Takes an async generator that yields frames and processes each one, handling error frames specially by pushing them as errors.

Parameters:

generator (AsyncGenerator[Frame | None, None]) – An async generator that yields Frame objects or None.