Add settings as canonical init arg for all AIService descendants, deprecate redundant model/voice/params args

ServiceSettings types were introduced for runtime updates via ServiceUpdateSettingsFrame, but there was tension between init-time and runtime APIs: overlapping-but-different InputParams vs ServiceSettings classes, and runtime-updatable fields like `model` and `voice` scattered as direct init args rather than living in a settings object. This unifies them so developers use the same settings type at both init and runtime, improving ergonomics and consistency.

Every concrete AIService subclass (LLM, TTS, STT, ImageGen, Vision, Video) now accepts a `settings` parameter for runtime-updatable config. Old init args (`model`, `voice_id`, `params`/`InputParams`) still work but emit DeprecationWarnings pointing to the new API. When both are provided, `settings` takes precedence. Leaf classes emit warnings; base classes do not, avoiding double warnings in inheritance chains.
This commit is contained in:
Paul Kompfner
2026-02-27 21:46:03 -05:00
committed by Mark Backman
parent 691d1d309e
commit 398db55ec6
84 changed files with 3431 additions and 1182 deletions

View File

@@ -12,6 +12,7 @@ and context aggregation functionality.
"""
from dataclasses import dataclass
from typing import Optional
from loguru import logger
@@ -22,11 +23,13 @@ from pipecat.processors.aggregators.llm_response import (
LLMUserAggregatorParams,
)
from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext
from pipecat.services.openai.base_llm import OpenAILLMSettings
from pipecat.services.openai.llm import (
OpenAIAssistantContextAggregator,
OpenAILLMService,
OpenAIUserContextAggregator,
)
from pipecat.services.settings import _warn_deprecated_param
@dataclass
@@ -81,7 +84,8 @@ class GrokLLMService(OpenAILLMService):
*,
api_key: str,
base_url: str = "https://api.x.ai/v1",
model: str = "grok-3-beta",
model: Optional[str] = None,
settings: Optional[OpenAILLMSettings] = None,
**kwargs,
):
"""Initialize the GrokLLMService with API key and model.
@@ -90,9 +94,22 @@ class GrokLLMService(OpenAILLMService):
api_key: The API key for accessing Grok's API.
base_url: The base URL for Grok API. Defaults to "https://api.x.ai/v1".
model: The model identifier to use. Defaults to "grok-3-beta".
.. deprecated:: 1.0
Use ``settings=OpenAILLMSettings(model=...)`` instead.
settings: Runtime-updatable settings. When provided alongside deprecated
parameters, ``settings`` values take precedence.
**kwargs: Additional keyword arguments passed to OpenAILLMService.
"""
super().__init__(api_key=api_key, base_url=base_url, model=model, **kwargs)
if model is not None:
_warn_deprecated_param("model", "OpenAILLMSettings", "model")
default_settings = OpenAILLMSettings(model=model or "grok-3-beta")
if settings is not None:
default_settings.apply_update(settings)
super().__init__(api_key=api_key, base_url=base_url, settings=default_settings, **kwargs)
# Initialize counters for token usage metrics
self._prompt_tokens = 0
self._completion_tokens = 0