Prefer Service.ThinkingConfig over raw ThinkingConfig class names in Anthropic and Google services and examples
This commit is contained in:
@@ -22,7 +22,7 @@ from pipecat.processors.aggregators.llm_response_universal import (
|
|||||||
)
|
)
|
||||||
from pipecat.runner.types import RunnerArguments
|
from pipecat.runner.types import RunnerArguments
|
||||||
from pipecat.runner.utils import create_transport
|
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.cartesia.tts import CartesiaTTSService
|
||||||
from pipecat.services.deepgram.stt import DeepgramSTTService
|
from pipecat.services.deepgram.stt import DeepgramSTTService
|
||||||
from pipecat.transports.base_transport import BaseTransport, TransportParams
|
from pipecat.transports.base_transport import BaseTransport, TransportParams
|
||||||
@@ -64,7 +64,7 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
llm = AnthropicLLMService(
|
llm = AnthropicLLMService(
|
||||||
api_key=os.getenv("ANTHROPIC_API_KEY"),
|
api_key=os.getenv("ANTHROPIC_API_KEY"),
|
||||||
settings=AnthropicLLMService.Settings(
|
settings=AnthropicLLMService.Settings(
|
||||||
thinking=AnthropicThinkingConfig(
|
thinking=AnthropicLLMService.ThinkingConfig(
|
||||||
type="enabled",
|
type="enabled",
|
||||||
budget_tokens=2048,
|
budget_tokens=2048,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from pipecat.runner.types import RunnerArguments
|
|||||||
from pipecat.runner.utils import create_transport
|
from pipecat.runner.utils import create_transport
|
||||||
from pipecat.services.cartesia.tts import CartesiaTTSService
|
from pipecat.services.cartesia.tts import CartesiaTTSService
|
||||||
from pipecat.services.deepgram.stt import DeepgramSTTService
|
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.base_transport import BaseTransport, TransportParams
|
||||||
from pipecat.transports.daily.transport import DailyParams
|
from pipecat.transports.daily.transport import DailyParams
|
||||||
from pipecat.transports.websocket.fastapi import FastAPIWebsocketParams
|
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"),
|
api_key=os.getenv("GOOGLE_API_KEY"),
|
||||||
# model="gemini-3-pro-preview", # A more powerful reasoning model, but slower
|
# model="gemini-3-pro-preview", # A more powerful reasoning model, but slower
|
||||||
settings=GoogleLLMService.Settings(
|
settings=GoogleLLMService.Settings(
|
||||||
thinking=GoogleThinkingConfig(
|
thinking=GoogleLLMService.ThinkingConfig(
|
||||||
thinking_budget=-1, # Dynamic thinking
|
thinking_budget=-1, # Dynamic thinking
|
||||||
include_thoughts=True,
|
include_thoughts=True,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from pipecat.processors.aggregators.llm_response_universal import (
|
|||||||
)
|
)
|
||||||
from pipecat.runner.types import RunnerArguments
|
from pipecat.runner.types import RunnerArguments
|
||||||
from pipecat.runner.utils import create_transport
|
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.cartesia.tts import CartesiaTTSService
|
||||||
from pipecat.services.deepgram.stt import DeepgramSTTService
|
from pipecat.services.deepgram.stt import DeepgramSTTService
|
||||||
from pipecat.services.llm_service import FunctionCallParams
|
from pipecat.services.llm_service import FunctionCallParams
|
||||||
@@ -85,7 +85,7 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
llm = AnthropicLLMService(
|
llm = AnthropicLLMService(
|
||||||
api_key=os.getenv("ANTHROPIC_API_KEY"),
|
api_key=os.getenv("ANTHROPIC_API_KEY"),
|
||||||
settings=AnthropicLLMService.Settings(
|
settings=AnthropicLLMService.Settings(
|
||||||
thinking=AnthropicThinkingConfig(
|
thinking=AnthropicLLMService.ThinkingConfig(
|
||||||
type="enabled",
|
type="enabled",
|
||||||
budget_tokens=2048,
|
budget_tokens=2048,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ from pipecat.runner.types import RunnerArguments
|
|||||||
from pipecat.runner.utils import create_transport
|
from pipecat.runner.utils import create_transport
|
||||||
from pipecat.services.cartesia.tts import CartesiaTTSService
|
from pipecat.services.cartesia.tts import CartesiaTTSService
|
||||||
from pipecat.services.deepgram.stt import DeepgramSTTService
|
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.services.llm_service import FunctionCallParams
|
||||||
from pipecat.transports.base_transport import BaseTransport, TransportParams
|
from pipecat.transports.base_transport import BaseTransport, TransportParams
|
||||||
from pipecat.transports.daily.transport import DailyParams
|
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"),
|
api_key=os.getenv("GOOGLE_API_KEY"),
|
||||||
# model="gemini-3-pro-preview", # A more powerful reasoning model, but slower
|
# model="gemini-3-pro-preview", # A more powerful reasoning model, but slower
|
||||||
settings=GoogleLLMService.Settings(
|
settings=GoogleLLMService.Settings(
|
||||||
thinking=GoogleThinkingConfig(
|
thinking=GoogleLLMService.ThinkingConfig(
|
||||||
thinking_budget=-1, # Dynamic thinking
|
thinking_budget=-1, # Dynamic thinking
|
||||||
include_thoughts=True,
|
include_thoughts=True,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -98,18 +98,20 @@ class AnthropicLLMSettings(LLMSettings):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
enable_prompt_caching: bool | _NotGiven = field(default_factory=lambda: _NOT_GIVEN)
|
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
|
@classmethod
|
||||||
def from_mapping(cls, settings):
|
def from_mapping(cls, settings):
|
||||||
"""Convert a plain dict to settings, coercing thinking dicts.
|
"""Convert a plain dict to settings, coercing thinking dicts.
|
||||||
|
|
||||||
For backward compatibility, a ``thinking`` value that is a plain dict
|
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)
|
instance = super().from_mapping(settings)
|
||||||
if is_given(instance.thinking) and isinstance(instance.thinking, dict):
|
if is_given(instance.thinking) and isinstance(instance.thinking, dict):
|
||||||
instance.thinking = AnthropicThinkingConfig(**instance.thinking)
|
instance.thinking = AnthropicLLMService.ThinkingConfig(**instance.thinking)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
@@ -199,7 +201,9 @@ class AnthropicLLMService(LLMService):
|
|||||||
temperature: Optional[float] = Field(default_factory=lambda: NOT_GIVEN, ge=0.0, le=1.0)
|
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_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)
|
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)
|
extra: Optional[Dict[str, Any]] = Field(default_factory=dict)
|
||||||
|
|
||||||
def model_post_init(self, __context):
|
def model_post_init(self, __context):
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
from dataclasses import dataclass, field
|
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 loguru import logger
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@@ -719,18 +719,20 @@ class GoogleLLMSettings(LLMSettings):
|
|||||||
thinking: Thinking configuration.
|
thinking: Thinking configuration.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
thinking: GoogleThinkingConfig | _NotGiven = field(default_factory=lambda: NOT_GIVEN)
|
thinking: Union["GoogleLLMService.ThinkingConfig", _NotGiven] = field(
|
||||||
|
default_factory=lambda: NOT_GIVEN
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_mapping(cls, settings):
|
def from_mapping(cls, settings):
|
||||||
"""Convert a plain dict to settings, coercing thinking dicts.
|
"""Convert a plain dict to settings, coercing thinking dicts.
|
||||||
|
|
||||||
For backward compatibility, a ``thinking`` value that is a plain dict
|
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)
|
instance = super().from_mapping(settings)
|
||||||
if is_given(instance.thinking) and isinstance(instance.thinking, dict):
|
if is_given(instance.thinking) and isinstance(instance.thinking, dict):
|
||||||
instance.thinking = GoogleThinkingConfig(**instance.thinking)
|
instance.thinking = GoogleLLMService.ThinkingConfig(**instance.thinking)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
@@ -775,7 +777,7 @@ class GoogleLLMService(LLMService):
|
|||||||
temperature: Optional[float] = Field(default=None, ge=0.0, le=2.0)
|
temperature: Optional[float] = Field(default=None, ge=0.0, le=2.0)
|
||||||
top_k: Optional[int] = Field(default=None, ge=0)
|
top_k: Optional[int] = Field(default=None, ge=0)
|
||||||
top_p: Optional[float] = Field(default=None, ge=0.0, le=1.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)
|
extra: Optional[Dict[str, Any]] = Field(default_factory=dict)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|||||||
Reference in New Issue
Block a user