-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(voice): send language and prompt in streamed STT #4533
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
sylvesterkaczmarek
wants to merge
8
commits into
openai:main
Choose a base branch
from
sylvesterkaczmarek:fix/stt-stream-language-prompt
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.
+107
−1
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4a0f68a
fix(voice): send language and prompt in streamed STT
sylvesterkaczmarek 5121a8b
test(voice): cover streamed STT language and prompt
sylvesterkaczmarek 1f66f70
test(voice): cover gpt-live-transcribe languages
sylvesterkaczmarek 99c7abe
fix(voice): use plural languages for live transcription
sylvesterkaczmarek a24c1c3
chore: apply STT review follow-up
sylvesterkaczmarek 319f909
chore: remove temporary follow-up workflow
sylvesterkaczmarek f561b5a
fix(voice): map current transcription languages
sylvesterkaczmarek 2f485f1
test(voice): cover gpt-transcribe languages
sylvesterkaczmarek 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
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,97 @@ | ||
| import json | ||
| from unittest.mock import AsyncMock | ||
|
|
||
| import pytest | ||
|
|
||
| from agents.voice import StreamedAudioInput, STTModelSettings | ||
| from agents.voice.models.openai_stt import OpenAISTTTranscriptionSession | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_streaming_stt_sends_language_and_prompt() -> None: | ||
| session = OpenAISTTTranscriptionSession( | ||
| input=StreamedAudioInput(), | ||
| client=AsyncMock(api_key="FAKE_KEY"), | ||
| model="gpt-4o-transcribe", | ||
| settings=STTModelSettings(language="fr", prompt="domain vocabulary"), | ||
| trace_include_sensitive_data=False, | ||
| trace_include_sensitive_audio_data=False, | ||
| ) | ||
| websocket = AsyncMock() | ||
| session._websocket = websocket | ||
|
|
||
| await session._configure_session() | ||
|
|
||
| payload = json.loads(websocket.send.await_args.args[0]) | ||
| assert payload["session"]["audio"]["input"]["transcription"] == { | ||
| "model": "gpt-4o-transcribe", | ||
| "language": "fr", | ||
| "prompt": "domain vocabulary", | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_streaming_stt_sends_plural_languages_for_gpt_transcribe() -> None: | ||
| session = OpenAISTTTranscriptionSession( | ||
| input=StreamedAudioInput(), | ||
| client=AsyncMock(api_key="FAKE_KEY"), | ||
| model="gpt-transcribe", | ||
| settings=STTModelSettings(language="fr", prompt="domain vocabulary"), | ||
| trace_include_sensitive_data=False, | ||
| trace_include_sensitive_audio_data=False, | ||
| ) | ||
| websocket = AsyncMock() | ||
| session._websocket = websocket | ||
|
|
||
| await session._configure_session() | ||
|
|
||
| payload = json.loads(websocket.send.await_args.args[0]) | ||
| assert payload["session"]["audio"]["input"]["transcription"] == { | ||
| "model": "gpt-transcribe", | ||
| "languages": ["fr"], | ||
| "prompt": "domain vocabulary", | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_streaming_stt_sends_plural_languages_for_gpt_live_transcribe() -> None: | ||
| session = OpenAISTTTranscriptionSession( | ||
| input=StreamedAudioInput(), | ||
| client=AsyncMock(api_key="FAKE_KEY"), | ||
| model="gpt-live-transcribe", | ||
| settings=STTModelSettings(language="fr", prompt="domain vocabulary"), | ||
| trace_include_sensitive_data=False, | ||
| trace_include_sensitive_audio_data=False, | ||
| ) | ||
| websocket = AsyncMock() | ||
| session._websocket = websocket | ||
|
|
||
| await session._configure_session() | ||
|
|
||
| payload = json.loads(websocket.send.await_args.args[0]) | ||
| assert payload["session"]["audio"]["input"]["transcription"] == { | ||
| "model": "gpt-live-transcribe", | ||
| "languages": ["fr"], | ||
| "prompt": "domain vocabulary", | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_streaming_stt_omits_unset_language_and_prompt() -> None: | ||
| session = OpenAISTTTranscriptionSession( | ||
| input=StreamedAudioInput(), | ||
| client=AsyncMock(api_key="FAKE_KEY"), | ||
| model="gpt-4o-transcribe", | ||
| settings=STTModelSettings(), | ||
| trace_include_sensitive_data=False, | ||
| trace_include_sensitive_audio_data=False, | ||
| ) | ||
| websocket = AsyncMock() | ||
| session._websocket = websocket | ||
|
|
||
| await session._configure_session() | ||
|
|
||
| payload = json.loads(websocket.send.await_args.args[0]) | ||
| assert payload["session"]["audio"]["input"]["transcription"] == { | ||
| "model": "gpt-4o-transcribe" | ||
| } |
Oops, something went wrong.
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.
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.
When callers select
gpt-transcribeand setSTTModelSettings.language, this condition now serializes the value aslanguages, butdocs/realtime/guide.md:115reserves plurallanguagesforgpt-live-transcribe, while line 140 identifiesgpt-transcribe's plural field as completion output rather than expected-language input. The session update therefore does not send the requested singular input language and may be rejected; keepgpt-transcribeonlanguageand reserve this list conversion forgpt-live-transcribe. Fresh evidence since the prior thread is the follow-up widening of this condition to includegpt-transcribe.AGENTS.md reference: AGENTS.md:L167-L167
Useful? React with 👍 / 👎.