llm
Google Gemini integration for Pipecat.
This module provides Google Gemini integration for the Pipecat framework, including LLM services, context management, and message aggregation.
- class pipecat.services.google.llm.GoogleThinkingConfig(*, thinking_budget: int | None = None, thinking_level: Literal['low', 'high', 'medium', 'minimal'] | str | None = None, include_thoughts: bool | None = None)[source]
Bases:
BaseModelConfiguration for controlling the model’s internal “thinking” process used before generating a response.
Gemini 2.5 and 3 series models have this thinking process. Set either
thinking_levelorthinking_budget, never both.- Parameters:
thinking_level – Thinking level, for Gemini 3 models. Gemini 3 Flash accepts “minimal”, “low”, “medium”, and “high”, except Gemini 3.7 Flash and Gemini 3.8 Flash, which accept only “low”, “medium”, and “high”. Gemini 3 Pro accepts “low” and “high”. If not provided, the flash models default to “medium” and Pro defaults to “high”. Note: Gemini 2.5 series must use thinking_budget instead.
thinking_budget – Token budget for thinking, for the Gemini 2.5 series. -1 for dynamic thinking (model decides), 0 to disable thinking, or a specific token count (e.g., 128-32768 for 2.5 Pro). If not provided, most models today default to dynamic thinking. See https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/thinking#gemini-2-5-and-earlier-models for default values and allowed ranges. Note: Gemini 3 models must use thinking_level instead.
include_thoughts – Whether to include thought summaries in the response. Today’s models default to not including thoughts (False).
- class pipecat.services.google.llm.GoogleLLMSettings(model: str | None | NotGiven = <factory>, extra: dict[str, Any]=<factory>, system_instruction: str | None | NotGiven = <factory>, temperature: float | None | NotGiven = <factory>, max_tokens: int | None | NotGiven = <factory>, top_p: float | None | NotGiven = <factory>, top_k: int | None | NotGiven = <factory>, frequency_penalty: float | None | NotGiven = <factory>, presence_penalty: float | None | NotGiven = <factory>, seed: int | None | NotGiven = <factory>, filter_incomplete_user_turns: bool | None | NotGiven = <factory>, user_turn_completion_config: UserTurnCompletionConfig | None | NotGiven = <factory>, use_provider_thinking_default: bool | NotGiven = <factory>, thinking: GoogleLLMService.ThinkingConfig | None | NotGiven = <factory>, safety_settings: list[SafetySetting] | None | NotGiven = <factory>)[source]
Bases:
LLMSettingsSettings for GoogleLLMService.
- Parameters:
thinking – Thinking configuration. If this is not provided, Pipecat sends the lowest thinking setting Google documents for the model, for the fastest responses, and logs what it sent. Models Pipecat doesn’t list, and any model when
use_provider_thinking_defaultis set, run at Google’s default.safety_settings – Content safety filters, as a list of
SafetySetting. Each entry pairs a harm category with the threshold at which content is blocked. Categories left unspecified keep the Gemini API defaults.
- classmethod from_mapping(settings)[source]
Convert a plain dict to settings, coercing thinking and safety dicts.
For backward compatibility, a
thinkingvalue that is a plain dict is converted to aGoogleLLMService.ThinkingConfig, and anysafety_settingsentry that is a plain dict is converted to aSafetySetting.
- class pipecat.services.google.llm.GoogleLLMService(*, api_key: str, model: str | None = None, params: InputParams | None = None, settings: GoogleLLMSettings | None = None, system_instruction: str | None = None, tools: list[dict[str, Any]] | None = None, tool_config: dict[str, Any] | None = None, http_options: HttpOptions | None = None, stream_idle_timeout_secs: float | None = 20.0, retry_timeout_secs: float | None = 5.0, retry_on_timeout: bool | None = False, **kwargs)[source]
Bases:
LLMService[GeminiLLMAdapter]Google AI (Gemini) LLM service implementation.
This class implements inference with Google’s AI models, translating internally from an LLMContext to the messages format expected by the Google AI model.
- Settings
alias of
GoogleLLMSettings
- adapter_class
alias of
GeminiLLMAdapter
- supports_response_schema: bool = True
Whether the provider can enforce a response schema in
run_inference().Services whose provider can set this to
True. When only some of its models can, they also overridemodel_supports_response_schema().
- ThinkingConfig
alias of
GoogleThinkingConfig
- class InputParams(**kwargs)[source]
Bases:
BaseModelInput parameters for Google AI models.
Deprecated since version 0.0.105: Use
settings=GoogleLLMService.Settings(...)instead. Will be removed in 2.0.0.- Parameters:
max_tokens – Maximum number of tokens to generate.
temperature – Sampling temperature between 0.0 and 2.0.
top_k – Top-k sampling parameter.
top_p – Top-p sampling parameter between 0.0 and 1.0.
thinking – Thinking configuration with thinking_budget, thinking_level, and include_thoughts. Used to control the model’s internal “thinking” process used before generating a response. Gemini 2.5 series models use thinking_budget; Gemini 3 models use thinking_level. If this is not provided, Pipecat sends the lowest thinking setting Google documents for the model, for the fastest responses, and logs what it sent. Models Pipecat doesn’t list run at Google’s default.
extra – Additional parameters as a dictionary.
- thinking: GoogleThinkingConfig | None
- __init__(*, api_key: str, model: str | None = None, params: InputParams | None = None, settings: GoogleLLMSettings | None = None, system_instruction: str | None = None, tools: list[dict[str, Any]] | None = None, tool_config: dict[str, Any] | None = None, http_options: HttpOptions | None = None, stream_idle_timeout_secs: float | None = 20.0, retry_timeout_secs: float | None = 5.0, retry_on_timeout: bool | None = False, **kwargs)[source]
Initialize the Google LLM service.
- Parameters:
api_key – Google AI API key for authentication.
model –
Model name to use.
Deprecated since version 0.0.105: Use
settings=GoogleLLMService.Settings(model=...)instead. Will be removed in 2.0.0.params –
Optional model parameters for inference.
Deprecated since version 0.0.105: Use
settings=GoogleLLMService.Settings(...)instead. Will be removed in 2.0.0.settings – Runtime-updatable settings for this service. When both deprecated parameters and settings are provided, settings values take precedence.
system_instruction –
System instruction/prompt for the model.
Deprecated since version 0.0.105: Use
settings=GoogleLLMService.Settings(system_instruction=...)instead. Will be removed in 2.0.0.tools – List of available tools/functions.
tool_config – Configuration for tool usage.
http_options – HTTP options for the client.
stream_idle_timeout_secs – How long to wait for the next chunk of a streamed response before giving up on it. Bounds the wait when the API accepts a request and then stops producing without closing the stream. This is a gap between chunks, not a limit on how long a response may take overall. The first chunk is the slowest, since its wait spans the whole round trip including any thinking the model does before it emits anything; raise this for models configured to think at length. Set to
Noneto wait indefinitely.retry_timeout_secs – How long to wait for the first chunk before giving up on the request and re-issuing it, when
retry_on_timeoutis set. Like the first-chunk wait above, this window spans the whole round trip including any thinking, so it is only a good fit for models that start emitting quickly.retry_on_timeout – Whether to re-issue the request once if the first chunk doesn’t arrive within
retry_timeout_secs. Only the first chunk is retried: once a chunk has been pushed downstream, re-issuing would duplicate the response.**kwargs – Additional arguments passed to parent class.
- can_generate_metrics() bool[source]
Check if the service can generate usage metrics.
- Returns:
True, as Google AI provides token usage metrics.
- static model_supports_response_schema(model: str) bool[source]
Whether a model can enforce a response schema.
Gemini takes a JSON schema from the 2.5 models on. A model id without a version is assumed to support it.
- Parameters:
model – The model name.
- async run_inference(context: LLMContext, max_tokens: int | None = None, system_instruction: str | None = None, response_schema: dict[str, Any] | None = None) str | None[source]
Run a one-shot, out-of-band (i.e. out-of-pipeline) inference with the given LLM context.
- Parameters:
context – The LLM context containing conversation history.
max_tokens – Optional maximum number of tokens to generate. If provided, overrides the service’s default max_tokens setting.
system_instruction – Optional system instruction to use for this inference. If provided, overrides any system instruction in the context.
response_schema – Optional JSON schema the reply must follow. The service asks the provider to enforce it, so the reply is JSON text matching the schema.
- Returns:
The LLM’s response as a string, or None if no response is generated.
- async process_frame(frame: Frame, direction: FrameDirection)[source]
Process incoming frames and handle different frame types.
- Parameters:
frame – The frame to process.
direction – Direction of frame processing.