-
Notifications
You must be signed in to change notification settings - Fork 25
Add AssemblyAI universal-3-5-pro with conversation-context carryover #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
66b277e
495841a
5196709
8625800
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||
| """Tests for assistant/pipeline/services.py — service factory functions.""" | ||||
|
|
||||
| from unittest.mock import MagicMock | ||||
| from unittest.mock import AsyncMock, MagicMock | ||||
|
|
||||
| import pytest | ||||
|
|
||||
|
|
@@ -9,6 +9,7 @@ | |||
| _resolve_url, | ||||
| create_stt_service, | ||||
| create_tts_service, | ||||
| update_stt_agent_context, | ||||
| ) | ||||
|
|
||||
|
|
||||
|
|
@@ -54,26 +55,54 @@ def test_unknown_model_raises_with_available_list(self): | |||
| create_stt_service("nonexistent_provider", params={"api_key": "k"}) | ||||
|
|
||||
| def test_assemblyai_service_created(self): | ||||
| svc = create_stt_service("assemblyai", params={"api_key": "k", "model": "u3-rt-pro"}) | ||||
| svc = create_stt_service("assemblyai", params={"api_key": "k", "model": "universal-3-5-pro"}) | ||||
| assert "AssemblyAI" in type(svc).__name__ | ||||
| assert svc._settings.model == "u3-rt-pro" | ||||
| assert svc._settings.model == "universal-3-5-pro" | ||||
|
|
||||
| def test_assemblyai_forwards_optional_settings(self): | ||||
| svc = create_stt_service( | ||||
| "assemblyai", | ||||
| params={ | ||||
| "api_key": "k", | ||||
| "model": "u3-rt-pro", | ||||
| "model": "universal-3-5-pro", | ||||
| "vad_threshold": 0.1, | ||||
| "min_turn_silence": 120, | ||||
| "min_turn_silence": 100, | ||||
| "max_turn_silence": 100, | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my other comment first. Then, to be consistent, should we clean that up too?
Suggested change
We can leave the |
||||
| }, | ||||
| ) | ||||
| assert svc._settings.vad_threshold == 0.1 | ||||
| assert svc._settings.min_turn_silence == 120 | ||||
| assert svc._settings.min_turn_silence == 100 | ||||
| assert svc._settings.max_turn_silence == 100 | ||||
|
|
||||
| def test_assemblyai_vad_force_turn_endpoint_defaults_true(self): | ||||
| """Constructor arg (not a Settings field) — defaults to pipecat-mode (True).""" | ||||
| svc = create_stt_service("assemblyai", params={"api_key": "k", "model": "universal-3-5-pro"}) | ||||
| assert svc._vad_force_turn_endpoint is True | ||||
|
|
||||
| def test_assemblyai_vad_force_turn_endpoint_overridable(self): | ||||
| svc = create_stt_service( | ||||
| "assemblyai", | ||||
| params={"api_key": "k", "model": "universal-3-5-pro", "vad_force_turn_endpoint": False}, | ||||
| ) | ||||
| assert svc._vad_force_turn_endpoint is False | ||||
|
|
||||
| def test_assemblyai_forwards_context_carryover_settings(self): | ||||
| """Conversation-context carryover settings (pipecat >= 1.4.0) forward through.""" | ||||
| svc = create_stt_service( | ||||
| "assemblyai", | ||||
| params={ | ||||
| "api_key": "k", | ||||
| "model": "universal-3-5-pro", | ||||
| "agent_context": "Booking confirmed for flight AA123.", | ||||
| "previous_context_n_turns": 0, | ||||
| }, | ||||
| ) | ||||
| assert svc._settings.agent_context == "Booking confirmed for flight AA123." | ||||
| assert svc._settings.previous_context_n_turns == 0 | ||||
|
|
||||
| def test_assemblyai_ignores_unspecified_settings(self): | ||||
| """Keys absent from params must not be forwarded, so library defaults apply.""" | ||||
| svc = create_stt_service("assemblyai", params={"api_key": "k", "model": "u3-rt-pro"}) | ||||
| svc = create_stt_service("assemblyai", params={"api_key": "k", "model": "universal-3-5-pro"}) | ||||
| assert svc._settings.vad_threshold is None | ||||
|
|
||||
| def test_nvidia_requires_url(self): | ||||
|
|
@@ -127,6 +156,30 @@ def test_cartesia_service_created(self): | |||
| assert "Cartesia" in type(svc).__name__ | ||||
|
|
||||
|
|
||||
| class TestUpdateSttAgentContext: | ||||
| """Conversation-context carryover hook (AssemblyAI Universal-3 Pro).""" | ||||
|
|
||||
| async def test_forwards_text_when_supported(self): | ||||
| stt = MagicMock() | ||||
| stt.update_agent_context = AsyncMock() | ||||
| await update_stt_agent_context(stt, "The agent's latest reply.") | ||||
| stt.update_agent_context.assert_awaited_once_with("The agent's latest reply.") | ||||
|
|
||||
| async def test_noop_when_capability_absent(self): | ||||
| """STT services without the method (Deepgram, Cartesia, …) are skipped silently.""" | ||||
| stt = MagicMock(spec=[]) # no attributes → getattr returns None | ||||
| await update_stt_agent_context(stt, "ignored") # must not raise | ||||
|
|
||||
| async def test_noop_for_empty_text(self): | ||||
| stt = MagicMock() | ||||
| stt.update_agent_context = AsyncMock() | ||||
| await update_stt_agent_context(stt, "") | ||||
| stt.update_agent_context.assert_not_awaited() | ||||
|
|
||||
| async def test_noop_for_none_stt(self): | ||||
| await update_stt_agent_context(None, "anything") # must not raise | ||||
|
|
||||
|
|
||||
| class TestCreateTtsService: | ||||
| def test_none_disables_tts(self): | ||||
| assert create_tts_service(None) is None | ||||
|
|
||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
"vad_force_turn_endpoint": true(the default), if we setmax_turn_silencelike this, we get this warning:So, should we clean that up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also,
"min_turn_silence": 100is the default, so we could consider giving a more relevant example, or remove it too. What do you think?