test, refactor: follow-ups to LLMService generic refactor

Two follow-ups now that LLMService is generic over its adapter:

- Add an explicit backward-compat test verifying that an LLMService
  subclass with no generic parameter (the third-party-provider
  pattern) instantiates and returns a usable adapter. The existing
  MockLLMService (declared without brackets) already exercised this
  implicitly, but it's worth a named assertion.

- Drop the now-redundant `params: SomeLLMInvocationParams = ...`
  variable annotations on `adapter.get_llm_invocation_params()`
  results. Since `get_llm_adapter()` now returns the precise adapter
  type, and `BaseLLMAdapter` is generic in its invocation-params
  type, the call already infers the right TypedDict.
This commit is contained in:
Paul Kompfner
2026-04-28 09:43:07 -04:00
parent 49068ff557
commit c4f5f1ebbb
5 changed files with 29 additions and 8 deletions

View File

@@ -7,6 +7,8 @@
import unittest
from unittest.mock import AsyncMock, patch
from pipecat.adapters.base_llm_adapter import BaseLLMAdapter
from pipecat.adapters.services.open_ai_adapter import OpenAILLMAdapter
from pipecat.frames.frames import (
FunctionCallFromLLM,
FunctionCallInProgressFrame,
@@ -39,6 +41,25 @@ class MockLLMService(LLMService):
super().__init__(settings=settings, **kwargs)
class TestUnparameterizedSubclass(unittest.TestCase):
"""Backward-compat coverage: third-party providers subclass LLMService
without specifying a generic adapter parameter. That should keep working
after LLMService became `Generic[TAdapter]`.
"""
def test_unparameterized_subclass_instantiates(self):
# MockLLMService is declared as `class MockLLMService(LLMService):`
# — no generic bracket. The TypeVar's `bound=BaseLLMAdapter` should
# resolve TAdapter to BaseLLMAdapter for callers that don't opt in.
service = MockLLMService()
adapter = service.get_llm_adapter()
# Default adapter_class is OpenAILLMAdapter; the runtime instance
# should reflect that, regardless of how generics are erased.
self.assertIsInstance(adapter, OpenAILLMAdapter)
self.assertIsInstance(adapter, BaseLLMAdapter)
class TestLLMService(unittest.IsolatedAsyncioTestCase):
async def _run_function_calls_inline(self, service: MockLLMService):
async def run_inline(runner_items):