fix(types): use is_given at call sites pyright flagged

Replace direct identity checks against NOT_GIVEN with is_given() at
sites where pyright's inability to narrow on non-singleton sentinels
was causing type errors.

- adapters/services/anthropic_adapter.py: narrow converted.system for
  _resolve_system_instruction.
- services/openai/llm.py: narrow params.service_tier using OpenAI's
  is_given.
- services/sarvam/llm.py: narrow tools / tool_choice using OpenAI's
  is_given (aliased as openai_is_given alongside the existing
  settings.is_given import).
- services/sarvam/tts.py: narrow settings.voice using settings.is_given.
This commit is contained in:
Paul Kompfner
2026-04-23 16:15:07 -04:00
parent 1624d7a474
commit 356618b448
4 changed files with 9 additions and 7 deletions

View File

@@ -91,7 +91,7 @@ class AnthropicLLMAdapter(BaseLLMAdapter[AnthropicLLMInvocationParams]):
self.get_messages(context), system_instruction=system_instruction
)
system = self._resolve_system_instruction(
converted.system if converted.system is not NOT_GIVEN else None,
converted.system if is_given(converted.system) else None,
system_instruction,
discard_context_system=True,
)

View File

@@ -8,6 +8,7 @@
from openai import NOT_GIVEN
from pipecat.adapters.services.open_ai_adapter import is_given
from pipecat.services.openai.base_llm import BaseOpenAILLMService
@@ -71,7 +72,7 @@ class OpenAILLMService(BaseOpenAILLMService):
default_settings.model = model
# Handle service_tier from deprecated params
if params is not None and not settings and params.service_tier is not NOT_GIVEN:
if params is not None and not settings and is_given(params.service_tier):
service_tier = service_tier or params.service_tier
# 3. Apply params overrides — only if settings not provided

View File

@@ -14,6 +14,7 @@ from loguru import logger
from openai import NOT_GIVEN
from pipecat.adapters.services.open_ai_adapter import OpenAILLMInvocationParams
from pipecat.adapters.services.open_ai_adapter import is_given as openai_is_given
from pipecat.services.openai.base_llm import OpenAILLMSettings
from pipecat.services.openai.llm import OpenAILLMService
from pipecat.services.sarvam._sdk import sdk_headers
@@ -158,11 +159,11 @@ class SarvamLLMService(OpenAILLMService):
tool_choice = params_from_context.get("tool_choice", NOT_GIVEN)
has_tools = (
tools is not NOT_GIVEN
openai_is_given(tools)
and tools is not None
and (not isinstance(tools, list) or len(tools) > 0)
)
has_tool_choice = tool_choice is not NOT_GIVEN and tool_choice is not None
has_tool_choice = openai_is_given(tool_choice) and tool_choice is not None
if has_tool_choice and not has_tools:
raise ValueError("Sarvam requires non-empty `tools` when `tool_choice` is provided.")

View File

@@ -59,7 +59,7 @@ from pipecat.frames.frames import (
TTSStoppedFrame,
)
from pipecat.services.sarvam._sdk import sdk_headers
from pipecat.services.settings import NOT_GIVEN, TTSSettings, _NotGiven
from pipecat.services.settings import NOT_GIVEN, TTSSettings, _NotGiven, is_given
from pipecat.services.tts_service import InterruptibleTTSService, TextAggregationMode, TTSService
from pipecat.transcriptions.language import Language, resolve_language
from pipecat.utils.tracing.service_decorators import traced_tts
@@ -501,7 +501,7 @@ class SarvamHttpTTSService(TTSService):
sample_rate = self._config.default_sample_rate
# Set default voice based on model if not specified via any mechanism
if voice_id is None and (settings is None or settings.voice is NOT_GIVEN):
if voice_id is None and (settings is None or not is_given(settings.voice)):
default_settings.voice = self._config.default_speaker
# Validate and clamp pace to model's valid range
@@ -919,7 +919,7 @@ class SarvamTTSService(InterruptibleTTSService):
sample_rate = self._config.default_sample_rate
# Set default voice based on model if not specified via any mechanism
if voice_id is None and (settings is None or settings.voice is NOT_GIVEN):
if voice_id is None and (settings is None or not is_given(settings.voice)):
default_settings.voice = self._config.default_speaker
# Validate and clamp pace to model's valid range