fix(llm): adapt async tool results for compatible APIs
This commit is contained in:
@@ -4,13 +4,61 @@ import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from models import AssistantConfig
|
||||
from pipecat.processors.aggregators.llm_context import LLMContext
|
||||
from services.pipecat.service_factory import (
|
||||
HTTP_TTS_STOP_FRAME_TIMEOUT_S,
|
||||
WEBSOCKET_TTS_STOP_FRAME_TIMEOUT_S,
|
||||
create_llm,
|
||||
create_tts,
|
||||
)
|
||||
|
||||
|
||||
class LLMServiceFactoryTest(unittest.TestCase):
|
||||
def test_openai_compatible_llm_converts_async_tool_developer_result(self):
|
||||
service = create_llm(
|
||||
AssistantConfig(
|
||||
llm_interface_type="openai-llm",
|
||||
model="deepseek-chat",
|
||||
llm_api_key="test-key",
|
||||
llm_base_url="https://llm.example.test/v1",
|
||||
)
|
||||
)
|
||||
context = LLMContext(
|
||||
messages=[
|
||||
{"role": "system", "content": "你是助手"},
|
||||
{
|
||||
"role": "developer",
|
||||
"content": '{"type":"async_tool","status":"finished"}',
|
||||
},
|
||||
{"role": "user", "content": "ok"},
|
||||
]
|
||||
)
|
||||
|
||||
params = service.get_llm_adapter().get_llm_invocation_params(
|
||||
context,
|
||||
convert_developer_to_user=not service.supports_developer_role,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
[message["role"] for message in params["messages"]],
|
||||
["system", "user", "user"],
|
||||
)
|
||||
self.assertNotIn("developer", str(params["messages"]))
|
||||
|
||||
def test_provider_can_explicitly_enable_developer_role(self):
|
||||
service = create_llm(
|
||||
AssistantConfig(
|
||||
llm_interface_type="openai-llm",
|
||||
model="gpt-compatible",
|
||||
llm_api_key="test-key",
|
||||
llm_base_url="https://llm.example.test/v1",
|
||||
llm_values={"supportsDeveloperRole": True},
|
||||
)
|
||||
)
|
||||
|
||||
self.assertTrue(service.supports_developer_role)
|
||||
|
||||
|
||||
class TTSServiceFactoryTest(unittest.TestCase):
|
||||
def test_http_tts_keeps_wider_audio_chunk_timeout(self):
|
||||
config = AssistantConfig(
|
||||
|
||||
Reference in New Issue
Block a user