-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(elevenlabs): support keyterms, no_verbatim, enable_logging on STT realtime #5618
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
Open
BkSouX
wants to merge
4
commits into
livekit:main
Choose a base branch
from
BkSouX:feat/elevenlabs-realtime-keyterms-no-verbatim
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+61
−4
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5ea857d
feat(elevenlabs): support keyterms, no_verbatim, enable_logging on ST…
BkSouX a10ba97
fix(elevenlabs): trigger stream reconnect when realtime params updated
BkSouX 1b9783c
docs(elevenlabs): clarify keyterms limits for batch vs realtime
BkSouX 2f4d360
feat: delete test file
BkSouX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
BkSouX marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| """Tests for ElevenLabs STT plugin configuration options.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import AsyncMock, MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from livekit.agents.types import NOT_GIVEN | ||
| from livekit.plugins.elevenlabs import STT | ||
|
|
||
|
|
||
| def test_keyterms_default(): | ||
| stt = STT(api_key="test-key") | ||
| assert stt._opts.keyterms is NOT_GIVEN | ||
|
|
||
|
|
||
| def test_keyterms_set(): | ||
| stt = STT(api_key="test-key", keyterms=["LiveKit", "Scribe"]) | ||
| assert stt._opts.keyterms == ["LiveKit", "Scribe"] | ||
|
|
||
|
|
||
| def test_keyterms_update(): | ||
| stt = STT(api_key="test-key") | ||
| stt.update_options(keyterms=["foo", "bar"]) | ||
| assert stt._opts.keyterms == ["foo", "bar"] | ||
|
|
||
|
|
||
| def test_no_verbatim_default(): | ||
| stt = STT(api_key="test-key") | ||
| assert stt._opts.no_verbatim is NOT_GIVEN | ||
|
|
||
|
|
||
| def test_no_verbatim_set(): | ||
| stt = STT(api_key="test-key", no_verbatim=True) | ||
| assert stt._opts.no_verbatim is True | ||
|
|
||
|
|
||
| def test_no_verbatim_update(): | ||
| stt = STT(api_key="test-key") | ||
| stt.update_options(no_verbatim=False) | ||
| assert stt._opts.no_verbatim is False | ||
|
|
||
|
|
||
| def test_enable_logging_default(): | ||
| stt = STT(api_key="test-key") | ||
| assert stt._opts.enable_logging is NOT_GIVEN | ||
|
|
||
|
|
||
| def test_enable_logging_set(): | ||
| stt = STT(api_key="test-key", enable_logging=False) | ||
| assert stt._opts.enable_logging is False | ||
|
|
||
|
|
||
| def test_enable_logging_update(): | ||
| stt = STT(api_key="test-key") | ||
| stt.update_options(enable_logging=True) | ||
| assert stt._opts.enable_logging is True | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_update_options_triggers_stream_reconnect(): | ||
| """Updating keyterms/no_verbatim/enable_logging on STT must trigger active stream reconnect.""" | ||
| captured: dict[str, str] = {} | ||
| stt = STT( | ||
| api_key="test-key", | ||
| model_id="scribe_v2_realtime", | ||
| language_code="en", | ||
| http_session=_make_session_mock(captured), | ||
| ) | ||
| stream = stt.stream() | ||
| try: | ||
| assert not stream._reconnect_event.is_set() | ||
| stt.update_options(keyterms=["foo"]) | ||
| assert stream._reconnect_event.is_set() | ||
| assert stream._opts.keyterms == ["foo"] | ||
|
|
||
| stream._reconnect_event.clear() | ||
| stt.update_options(no_verbatim=True) | ||
| assert stream._reconnect_event.is_set() | ||
| assert stream._opts.no_verbatim is True | ||
|
|
||
| stream._reconnect_event.clear() | ||
| stt.update_options(enable_logging=False) | ||
| assert stream._reconnect_event.is_set() | ||
| assert stream._opts.enable_logging is False | ||
| finally: | ||
| await stream.aclose() | ||
|
|
||
|
|
||
| def test_combined_options(): | ||
| stt = STT( | ||
| api_key="test-key", | ||
| keyterms=["alpha", "beta"], | ||
| no_verbatim=True, | ||
| enable_logging=False, | ||
| ) | ||
| assert stt._opts.keyterms == ["alpha", "beta"] | ||
| assert stt._opts.no_verbatim is True | ||
| assert stt._opts.enable_logging is False | ||
|
|
||
|
|
||
| def _make_session_mock(captured: dict[str, str]) -> MagicMock: | ||
| async def fake_ws_connect(url: str, **kwargs): | ||
| captured["url"] = url | ||
| return MagicMock() | ||
|
|
||
| session = MagicMock() | ||
| session.ws_connect = AsyncMock(side_effect=fake_ws_connect) | ||
| return session | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_realtime_query_string_includes_new_params(): | ||
| """Verify keyterms, no_verbatim, and enable_logging appear in the realtime WS URL.""" | ||
| captured: dict[str, str] = {} | ||
| stt = STT( | ||
| api_key="test-key", | ||
| model_id="scribe_v2_realtime", | ||
| language_code="en", | ||
| keyterms=["hello world", "scribe&v2"], | ||
| no_verbatim=True, | ||
| enable_logging=False, | ||
| http_session=_make_session_mock(captured), | ||
| ) | ||
| stream = stt.stream() | ||
| try: | ||
| await stream._connect_ws() | ||
| finally: | ||
| await stream.aclose() | ||
|
|
||
| url = captured["url"] | ||
| assert "keyterms=hello%20world" in url | ||
| assert "keyterms=scribe%26v2" in url | ||
| assert "no_verbatim=true" in url | ||
| assert "enable_logging=false" in url | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_realtime_query_string_omits_unset_params(): | ||
| """Unset params should not appear in the realtime WS URL.""" | ||
| captured: dict[str, str] = {} | ||
| stt = STT( | ||
| api_key="test-key", | ||
| model_id="scribe_v2_realtime", | ||
| language_code="en", | ||
| http_session=_make_session_mock(captured), | ||
| ) | ||
| stream = stt.stream() | ||
| try: | ||
| await stream._connect_ws() | ||
| finally: | ||
| await stream.aclose() | ||
|
|
||
| url = captured["url"] | ||
| assert "keyterms=" not in url | ||
| assert "no_verbatim=" not in url | ||
| assert "enable_logging=" not in url |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.