fix(asr): update session handling and improve schema for GA integration - #2290
Conversation
|
Thanks for tackling this — the beta Realtime transcription API being retired is a real problem, and the approach of keeping the flat Below is what I found reading 1. The migration is incomplete — schemas still import from the beta namespace
from openai.types.beta.realtime.transcription_session_update_param import (
SessionTurnDetection,
SessionInputAudioTranscription,
SessionInputAudioNoiseReduction,
)The docstring now points at the GA guide and the Two options, either is fine:
Given the repo guidance on pinning dependencies, I would lean toward an upper bound regardless of which you pick. 2.
Anyone relying on it gets no error, just a config that quietly stops taking effect. Either wire it into the GA payload or remove the field from the schema so misconfiguration surfaces as a validation error. 3. [verify] Nested This is the one I would most want confirmed on a live connection. The old path serialized the whole model with if isinstance(value, dict):
return value # returned as-is, nulls included
if hasattr(value, "model_dump"):
return value.model_dump(exclude_none=True)
A config like if isinstance(value, dict):
return {k: v for k, v in value.items() if v is not None}4. Three different idioms for the same "omit if absent" check Within one function: if transcription: # truthiness — drops empty dict
if params.turn_detection is not None: # checks the model field
if noise_reduction is not None: # checks the converted valueThese are not equivalent: an empty 5. Hardcoded "pcm16": {"type": "audio/pcm", "rate": 24000},This is correct and well-commented for the PCM path — The 6. Test coverage — the new logic is never executed
This is a pure function with no I/O — about as cheap to test as code gets. A handful of cases would lock in the wire format:
Two smaller things in the existing fixtures while you are in there:
7. Minor: In 8. Housekeeping
Summary The core translation approach is sound and the backward-compatible config shape is the right tradeoff. The two things I would want resolved before merge are the lingering Happy to be wrong on item 3 — that one really needs a live connection to settle. |
e7df9af to
562defb
Compare
|
Review: Thanks for this — moving A few things worth addressing before merge. 1. The core change has no test coverage
This matters more than usual here because the payload shape is the only thing this PR changes, and it cannot be validated without talking to OpenAI. A handful of assertions would cover it: def test_pcm16_maps_to_audio_pcm_24k():
payload = build_ga_session_update(TranscriptionParam(
input_audio_format="pcm16",
input_audio_transcription={"model": "whisper-1", "language": "en"},
))
assert payload["type"] == "session.update"
assert payload["session"]["type"] == "transcription"
assert payload["session"]["audio"]["input"]["format"] == {
"type": "audio/pcm", "rate": 24000,
}
def test_optional_fields_omitted_when_unset():
payload = build_ga_session_update(TranscriptionParam(
input_audio_format="pcm16",
input_audio_transcription={"model": "whisper-1"},
))
audio_input = payload["session"]["audio"]["input"]
assert "turn_detection" not in audio_input
assert "noise_reduction" not in audio_input
assert "include" not in payload["session"]Plus the two 2. The docstring now drops the "this is a beta api" warning and points at the GA docs, but the type imports directly below it are unchanged: from openai.types.beta.realtime.transcription_session_update_param import (
SessionTurnDetection,
SessionInputAudioTranscription,
SessionInputAudioNoiseReduction,
)So the module claims GA while its types come from the SDK path most likely to be removed. Combined with
Note 3. The diff shows "No newline at end of file" on Medium Shared mutable dict leaks into the payload. audio_input: dict[str, Any] = {
"format": _AUDIO_FORMAT_TO_GA[params.input_audio_format],
}Nothing mutates it today, so there is no live bug — but any caller that later tweaks
Three different idioms for the same optional-field check. Within one function: if transcription: (truthiness)
if params.turn_detection is not None: (None check on the model field)
if noise_reduction is not None: (None check on the converted value)Beyond readability, these are not equivalent: a Related, No way to explicitly disable turn detection. When Docs still describe the beta API. All five Minor
Things I could not verify I reviewed this statically and did not run the extension against the live API, so I cannot confirm the two facts the fix hinges on: that the GA endpoint still accepts Version bumps in |
Review:
|
…ove session handling
a5863cf to
5939916
Compare
openai_asr已经不支持beta api
需要更新