From 51a8a28a991be8e3ae8d651f03abc0c97537730c Mon Sep 17 00:00:00 2001 From: Paul Kompfner Date: Wed, 11 Mar 2026 12:34:10 -0400 Subject: [PATCH] Prefer Service.ThinkingConfig over raw ThinkingConfig class names in Anthropic and Google services and examples --- examples/foundational/49a-thinking-anthropic.py | 4 ++-- examples/foundational/49b-thinking-google.py | 4 ++-- .../foundational/49c-thinking-functions-anthropic.py | 4 ++-- .../foundational/49d-thinking-functions-google.py | 4 ++-- src/pipecat/services/anthropic/llm.py | 12 ++++++++---- src/pipecat/services/google/llm.py | 12 +++++++----- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/examples/foundational/49a-thinking-anthropic.py b/examples/foundational/49a-thinking-anthropic.py index 8825ce7c5..727e8e0a7 100644 --- a/examples/foundational/49a-thinking-anthropic.py +++ b/examples/foundational/49a-thinking-anthropic.py @@ -22,7 +22,7 @@ from pipecat.processors.aggregators.llm_response_universal import ( ) from pipecat.runner.types import RunnerArguments from pipecat.runner.utils import create_transport -from pipecat.services.anthropic.llm import AnthropicLLMService, AnthropicThinkingConfig +from pipecat.services.anthropic.llm import AnthropicLLMService from pipecat.services.cartesia.tts import CartesiaTTSService from pipecat.services.deepgram.stt import DeepgramSTTService from pipecat.transports.base_transport import BaseTransport, TransportParams @@ -64,7 +64,7 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): llm = AnthropicLLMService( api_key=os.getenv("ANTHROPIC_API_KEY"), settings=AnthropicLLMService.Settings( - thinking=AnthropicThinkingConfig( + thinking=AnthropicLLMService.ThinkingConfig( type="enabled", budget_tokens=2048, ), diff --git a/examples/foundational/49b-thinking-google.py b/examples/foundational/49b-thinking-google.py index ed7a393b0..b2b44d59a 100644 --- a/examples/foundational/49b-thinking-google.py +++ b/examples/foundational/49b-thinking-google.py @@ -24,7 +24,7 @@ from pipecat.runner.types import RunnerArguments from pipecat.runner.utils import create_transport from pipecat.services.cartesia.tts import CartesiaTTSService from pipecat.services.deepgram.stt import DeepgramSTTService -from pipecat.services.google.llm import GoogleLLMService, GoogleThinkingConfig +from pipecat.services.google.llm import GoogleLLMService from pipecat.transports.base_transport import BaseTransport, TransportParams from pipecat.transports.daily.transport import DailyParams from pipecat.transports.websocket.fastapi import FastAPIWebsocketParams @@ -65,7 +65,7 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): api_key=os.getenv("GOOGLE_API_KEY"), # model="gemini-3-pro-preview", # A more powerful reasoning model, but slower settings=GoogleLLMService.Settings( - thinking=GoogleThinkingConfig( + thinking=GoogleLLMService.ThinkingConfig( thinking_budget=-1, # Dynamic thinking include_thoughts=True, ), diff --git a/examples/foundational/49c-thinking-functions-anthropic.py b/examples/foundational/49c-thinking-functions-anthropic.py index bc9f334c8..d6b2749e1 100644 --- a/examples/foundational/49c-thinking-functions-anthropic.py +++ b/examples/foundational/49c-thinking-functions-anthropic.py @@ -23,7 +23,7 @@ from pipecat.processors.aggregators.llm_response_universal import ( ) from pipecat.runner.types import RunnerArguments from pipecat.runner.utils import create_transport -from pipecat.services.anthropic.llm import AnthropicLLMService, AnthropicThinkingConfig +from pipecat.services.anthropic.llm import AnthropicLLMService from pipecat.services.cartesia.tts import CartesiaTTSService from pipecat.services.deepgram.stt import DeepgramSTTService from pipecat.services.llm_service import FunctionCallParams @@ -85,7 +85,7 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): llm = AnthropicLLMService( api_key=os.getenv("ANTHROPIC_API_KEY"), settings=AnthropicLLMService.Settings( - thinking=AnthropicThinkingConfig( + thinking=AnthropicLLMService.ThinkingConfig( type="enabled", budget_tokens=2048, ), diff --git a/examples/foundational/49d-thinking-functions-google.py b/examples/foundational/49d-thinking-functions-google.py index e8ecefcdd..f5b9a1d20 100644 --- a/examples/foundational/49d-thinking-functions-google.py +++ b/examples/foundational/49d-thinking-functions-google.py @@ -25,7 +25,7 @@ from pipecat.runner.types import RunnerArguments from pipecat.runner.utils import create_transport from pipecat.services.cartesia.tts import CartesiaTTSService from pipecat.services.deepgram.stt import DeepgramSTTService -from pipecat.services.google.llm import GoogleLLMService, GoogleThinkingConfig +from pipecat.services.google.llm import GoogleLLMService from pipecat.services.llm_service import FunctionCallParams from pipecat.transports.base_transport import BaseTransport, TransportParams from pipecat.transports.daily.transport import DailyParams @@ -86,7 +86,7 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): api_key=os.getenv("GOOGLE_API_KEY"), # model="gemini-3-pro-preview", # A more powerful reasoning model, but slower settings=GoogleLLMService.Settings( - thinking=GoogleThinkingConfig( + thinking=GoogleLLMService.ThinkingConfig( thinking_budget=-1, # Dynamic thinking include_thoughts=True, ), diff --git a/src/pipecat/services/anthropic/llm.py b/src/pipecat/services/anthropic/llm.py index 0c6d436e1..2f77e1665 100644 --- a/src/pipecat/services/anthropic/llm.py +++ b/src/pipecat/services/anthropic/llm.py @@ -98,18 +98,20 @@ class AnthropicLLMSettings(LLMSettings): """ enable_prompt_caching: bool | _NotGiven = field(default_factory=lambda: _NOT_GIVEN) - thinking: AnthropicThinkingConfig | _NotGiven = field(default_factory=lambda: _NOT_GIVEN) + thinking: Union["AnthropicLLMService.ThinkingConfig", _NotGiven] = field( + default_factory=lambda: _NOT_GIVEN + ) @classmethod def from_mapping(cls, settings): """Convert a plain dict to settings, coercing thinking dicts. For backward compatibility, a ``thinking`` value that is a plain dict - is converted to a :class:`AnthropicThinkingConfig`. + is converted to a :class:`AnthropicLLMService.ThinkingConfig`. """ instance = super().from_mapping(settings) if is_given(instance.thinking) and isinstance(instance.thinking, dict): - instance.thinking = AnthropicThinkingConfig(**instance.thinking) + instance.thinking = AnthropicLLMService.ThinkingConfig(**instance.thinking) return instance @@ -199,7 +201,9 @@ class AnthropicLLMService(LLMService): temperature: Optional[float] = Field(default_factory=lambda: NOT_GIVEN, ge=0.0, le=1.0) top_k: Optional[int] = Field(default_factory=lambda: NOT_GIVEN, ge=0) top_p: Optional[float] = Field(default_factory=lambda: NOT_GIVEN, ge=0.0, le=1.0) - thinking: Optional[AnthropicThinkingConfig] = Field(default_factory=lambda: NOT_GIVEN) + thinking: Optional["AnthropicLLMService.ThinkingConfig"] = Field( + default_factory=lambda: NOT_GIVEN + ) extra: Optional[Dict[str, Any]] = Field(default_factory=dict) def model_post_init(self, __context): diff --git a/src/pipecat/services/google/llm.py b/src/pipecat/services/google/llm.py index 2ade23906..02b5a5c19 100644 --- a/src/pipecat/services/google/llm.py +++ b/src/pipecat/services/google/llm.py @@ -16,7 +16,7 @@ import json import os import uuid from dataclasses import dataclass, field -from typing import Any, AsyncIterator, Dict, List, Literal, Optional +from typing import Any, AsyncIterator, Dict, List, Literal, Optional, Union from loguru import logger from PIL import Image @@ -719,18 +719,20 @@ class GoogleLLMSettings(LLMSettings): thinking: Thinking configuration. """ - thinking: GoogleThinkingConfig | _NotGiven = field(default_factory=lambda: NOT_GIVEN) + thinking: Union["GoogleLLMService.ThinkingConfig", _NotGiven] = field( + default_factory=lambda: NOT_GIVEN + ) @classmethod def from_mapping(cls, settings): """Convert a plain dict to settings, coercing thinking dicts. For backward compatibility, a ``thinking`` value that is a plain dict - is converted to a :class:`GoogleThinkingConfig`. + is converted to a :class:`GoogleLLMService.ThinkingConfig`. """ instance = super().from_mapping(settings) if is_given(instance.thinking) and isinstance(instance.thinking, dict): - instance.thinking = GoogleThinkingConfig(**instance.thinking) + instance.thinking = GoogleLLMService.ThinkingConfig(**instance.thinking) return instance @@ -775,7 +777,7 @@ class GoogleLLMService(LLMService): temperature: Optional[float] = Field(default=None, ge=0.0, le=2.0) top_k: Optional[int] = Field(default=None, ge=0) top_p: Optional[float] = Field(default=None, ge=0.0, le=1.0) - thinking: Optional[GoogleThinkingConfig] = Field(default=None) + thinking: Optional["GoogleLLMService.ThinkingConfig"] = Field(default=None) extra: Optional[Dict[str, Any]] = Field(default_factory=dict) def __init__(