Realtime Session Update Configuration
维护者通常 1 天内回复
评估
调研方向
从 openai.resources.beta.realtime.AsyncRealtimeConnection.send 开始,检查 SessionUpdateEvent 如何使用 exclude_defaults=True 进行序列化。将 Session 模型的 turn_detection 默认值与 SessionCreatedEvent 和 SessionUpdatedEvent 示例中显示的服务器端 VAD 值进行比较。当带有 turn_detection=None 的 SessionUpdateEvent 能够按预期更改 realtime 会话配置时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
The intended behavior is to disable server-side VAD for the OpenAI Realtime model. We are using LiveKit to facilitate the websocket connection, but the bug is in the OpenAI library.
In particular, the openai.resources.beta.realtime.AsyncRealtimeConnection.send method uses event.to_json(use_api_names=True, exclude_defaults=True, exclude_unset=True) to serialize the SessionUpdateEvent. The issue is with the exclude_defaults=True parameter which doesn't include any values that are equal to their default values.
We have confirmed the two serial SessionUpdateEvents get composed, so a change from the first event is reflected in the resulting configuration of the second event. This makes the exclude_defaults=True argument particularly problematic because there is now no way to ever change a default and then change it back.
There are a couple of problems here. For VAD in particular, despite the default value of turn_detection=None in Session(BaseModel), it is in fact not None and instead some default server-side VAD values. When you try to pass None in the SessionUpdateEvent you can't change the turn_detection value because (1) exclude_defaults=True prevents you and (2) the default value is inconsistent with what actually exists by default.
There are two solutions:
- Remove
exclude_defaults=True - Update the default
turn_detectioninSession
To Reproduce
Please follow the steps below.
Code snippets
When running python minimal_worker.py console using LiveKit agents on branch dev-1.0 with the following model configuration:
agent = VoiceAgent(
instructions="You are a helpful assistant that can answer questions and help with tasks.",
llm=openai.realtime.RealtimeModel(
model="gpt-4o-realtime-preview-2024-12-17",
voice="alloy"
)
)
Then, within the _main_task of RealtimeSession, we hardcode the turn_detection=None parameter as follows:
self._msg_ch.send_nowait(
SessionUpdateEvent(
type="session.update",
session=session_update_event.Session(
model=self._realtime_model._opts.model, # type: ignore
voice=self._realtime_model._opts.voice, # type: ignore
input_audio_transcription=input_audio_transcription,
turn_detection=None
),
event_id=utils.shortuuid("session_update_"),
)
)
The issue here is that turn_detection never gets updated properly according to the SessionUpdatedEvent. This is related to the problem that this PR was attempting to solve.
For example, we get:
- The
SessionCreatedEventwith the defaultturn_detector. By the way, even after passing the query param to the websocket uriturn_detector=for a null value, it still returns with server-side VAD.
SessionCreatedEvent(..., turn_detection=TurnDetection(create_response=True, interrupt_response=True, prefix_padding_ms=300, silence_duration_ms=200, threshold=0.5, type='server_vad'), ...) type='session.created')
- After passing the
turn_detector=Noneargument to theSessionUpdateEventas mentioned above, we still eventually observe theSessionUpdatedEvent.
SessionUpdatedEvent(..., turn_detection=TurnDetection(create_response=True, interrupt_response=True, prefix_padding_ms=300, silence_duration_ms=200, threshold=0.5, type='server_vad'), ...), type='session.updated')
OS
macOS
Python version
Python v3.13
Library version
openai v1.66.3
- 主要语言
- Python
- 星标
- 31.8k
- 派生
- 7.3k
- 平均合并
- 1 天 3 小时
- 30 天内合并 PR
- 131
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openai/openai-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
openai/openai-python#4022 · 8 条评论 ·
维护者通常 1 天内回复
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providers可能已有人在做 @mohmedmm 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
openai/openai-python#4017 · 3 条评论 ·
维护者通常 1 天内回复
-
Querystring drops explicit empty-string scalar values可能已有人在做 @sylvesterkaczmarek 于 29 天前认领。 未关闭sdk-breaking-change v4
难度 2/5 1-3 小时 新手友好度 86/100
openai/openai-python#3837 ·
维护者通常 1 天内回复
-
Define + export `ServiceTiers` string literal可能已有人在做 @SparshGarg999 于 56 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-python#3556 · 3 条评论 ·
维护者通常 1 天内回复
-
Empty OPENAI_BASE_URL prevents fallback to default API endpoint可能已有人在做 @Sehastrajit-S 于 22 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-python#2927 · 6 条评论 ·
维护者通常 1 天内回复
查看 openai/openai-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
[BUG] Multi-day events show "Ended" while still in progress可能已有人在做 @tarunagnihotri534 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 85/100
data-umbrella/du-event-board#231 · 2 条评论 ·
-
avl_automation: the generated control surface block isn't valid XML (typo in avl_out_parse.py)可能已有人在做 @brksol 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 92/100
PX4/PX4-gazebo-models#164 ·