Pipecat: LLM
Generate the reply in a Pipecat pipeline with a Sprag language model, or hold the whole conversation over one realtime session.
SpragLLMService generates the reply in a Pipecat pipeline through
POST /v1/chat/completions. It supports tool use (also called function
calling) and reports token usage as Pipecat metrics.
Setup
from pipecat_sprag.llm import SpragLLMService
llm = SpragLLMService(
settings=SpragLLMService.Settings(
model="symphony",
system_instruction="You are a helpful assistant in a voice conversation. Keep replies brief.",
),
)Add it to the pipeline in the generate position, between the user and assistant context aggregators:
pipeline = Pipeline([
transport.input(),
stt,
user_aggregator,
llm,
tts,
transport.output(),
assistant_aggregator,
])| Argument | Required | Type | Notes |
|---|---|---|---|
settings.model | No | string | A model that answers on POST /v1/chat/completions, from Models. Defaults to symphony. |
settings.system_instruction | No | string | The system prompt. |
settings.temperature, settings.top_p, settings.max_tokens, settings.frequency_penalty, settings.presence_penalty, settings.seed | No | number | Sent as the fields of the same name on POST /v1/chat/completions. |
api_key | No | string | Your Sprag API key. Defaults to SPRAG_API_KEY. |
base_url | No | string | Defaults to https://api.sprag.ai/v1. |
Tool use
Declare tools in the context and register a handler for each with
register_function, as on any Pipecat LLM service. See the Pipecat guide to
function calling.
Usage metrics
If the pipeline runs with PipelineParams(enable_usage_metrics=True), each
reply's prompt and completion token counts arrive as LLMUsageMetricsData.
Realtime LLM
OpenAIRealtimeLLMService replaces the transcribe, generate, and speak
stages with a single WebSocket to a model that listens and speaks. It runs
against Sprag with base_url and api_key passed to the constructor.
import os
from pipecat.services.openai.realtime.llm import OpenAIRealtimeLLMService
llm = OpenAIRealtimeLLMService(
api_key=os.environ["SPRAG_API_KEY"],
base_url="wss://api.sprag.ai/v1/realtime",
settings=OpenAIRealtimeLLMService.Settings(
model="symphony",
system_instruction="Be concise and stay on topic.",
),
)OpenAIRealtimeLLMService builds its own connect URL from settings.model,
so base_url takes no query string.
Add it to a pipeline as transcribe, generate, and speak combined, with no separate STT or TTS stage:
pipeline = Pipeline([
transport.input(),
context_aggregator.user(),
llm,
transport.output(),
])system_instruction maps onto the realtime session's instructions field.
Turn detection follows the same turn_detection settings the raw protocol
takes. See session configuration for
both.
Reference
- Speech to speech has the session's full wire contract: audio format, barge-in, and close codes.
- The Pipecat realtime LLM docs have the service's own event and settings reference.