mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-07-01 08:59:46 +02:00
Fix realtime initial greeting handling (#481)
This commit is contained in:
parent
d9800fddd6
commit
090d042a78
20 changed files with 714 additions and 70 deletions
|
|
@ -5,6 +5,7 @@ import pytest
|
|||
from pipecat.frames.frames import TTSSpeakFrame
|
||||
from pipecat.processors.aggregators.llm_context import LLMContext
|
||||
from pipecat.processors.frame_processor import FrameDirection
|
||||
from pipecat.services.openai.realtime import events
|
||||
|
||||
from api.services.pipecat.realtime.openai_realtime import (
|
||||
DograhOpenAIRealtimeLLMService,
|
||||
|
|
@ -48,17 +49,69 @@ async def test_updated_context_uses_tool_result_path_after_initial_context():
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_tts_greeting_uses_initial_context_handler():
|
||||
async def test_tts_greeting_sends_exact_static_greeting_prompt():
|
||||
service = _make_service()
|
||||
service._context = LLMContext()
|
||||
service._handle_context = AsyncMock()
|
||||
service._api_session_ready = True
|
||||
service.send_client_event = AsyncMock()
|
||||
service.push_frame = AsyncMock()
|
||||
service.start_processing_metrics = AsyncMock()
|
||||
service.start_ttfb_metrics = AsyncMock()
|
||||
|
||||
await service.process_frame(
|
||||
TTSSpeakFrame("hello", append_to_context=True),
|
||||
TTSSpeakFrame("Hi Sam, this is Sarah from Acme.", append_to_context=True),
|
||||
FrameDirection.DOWNSTREAM,
|
||||
)
|
||||
|
||||
service._handle_context.assert_awaited_once_with(service._context)
|
||||
sent_events = [call.args[0] for call in service.send_client_event.await_args_list]
|
||||
assert not any(
|
||||
isinstance(event, events.ConversationItemCreateEvent) for event in sent_events
|
||||
)
|
||||
assert isinstance(sent_events[0], events.SessionUpdateEvent)
|
||||
response_event = sent_events[-1]
|
||||
assert isinstance(response_event, events.ResponseCreateEvent)
|
||||
assert response_event.response.tool_choice == "none"
|
||||
prompt = response_event.response.instructions
|
||||
assert "The phone call has just connected. Greet the caller now:" in prompt
|
||||
assert prompt.endswith('"Hi Sam, this is Sarah from Acme."')
|
||||
assert service._llm_needs_conversation_setup is False
|
||||
service._create_response.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_tts_greeting_waits_for_session_updated_before_sending_prompt():
|
||||
service = _make_service()
|
||||
service._context = LLMContext()
|
||||
|
||||
await service.process_frame(
|
||||
TTSSpeakFrame("Hello from Dograh.", append_to_context=True),
|
||||
FrameDirection.DOWNSTREAM,
|
||||
)
|
||||
|
||||
assert service._handled_initial_context is True
|
||||
assert service._run_llm_when_api_session_ready is True
|
||||
assert service._pending_initial_greeting_text == "Hello from Dograh."
|
||||
|
||||
service.send_client_event = AsyncMock()
|
||||
service.push_frame = AsyncMock()
|
||||
service.start_processing_metrics = AsyncMock()
|
||||
service.start_ttfb_metrics = AsyncMock()
|
||||
|
||||
await service._handle_evt_session_updated(SimpleNamespace())
|
||||
|
||||
sent_events = [call.args[0] for call in service.send_client_event.await_args_list]
|
||||
assert not any(
|
||||
isinstance(event, events.ConversationItemCreateEvent) for event in sent_events
|
||||
)
|
||||
assert isinstance(sent_events[0], events.SessionUpdateEvent)
|
||||
response_event = sent_events[-1]
|
||||
assert isinstance(response_event, events.ResponseCreateEvent)
|
||||
assert response_event.response.tool_choice == "none"
|
||||
prompt = response_event.response.instructions
|
||||
assert prompt.endswith('"Hello from Dograh."')
|
||||
assert service._run_llm_when_api_session_ready is False
|
||||
assert service._pending_initial_greeting_text is None
|
||||
assert service._llm_needs_conversation_setup is False
|
||||
service._create_response.assert_not_awaited()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue