ISSUE DESCRIPTION Add reasoning.effort support for OpenAI gpt-realtime-2 Feature Type…
- User
ISSUE DESCRIPTION
Add reasoning.effort support for OpenAI gpt-realtime-2
Feature Type
Would make my life easier
Feature Description
OpenAI
gpt-realtime-2supports configurable reasoning viareasoning.effort, but the Python OpenAI Realtime plugin does not seem to expose this option onopenai.realtime.RealtimeModel.It would be useful to support something like:
pythonfrom livekit.plugins import openai llm = openai.realtime.RealtimeModel( model="gpt-realtime-2", reasoning={"effort": "low"}, )Workarounds / Alternatives
I don't think there is a clean workaround through the current Python
RealtimeModelAPI.The only workaround I can see is patching the plugin locally to add
reasoningto the session update payload.Additional Context
OpenAI docs list these effort values:
minimal,low,medium,high,xhigh.References:
- https://developers.openai.com/api/docs/models/gpt-realtime-2
- https://developers.openai.com/api/docs/guides/realtime-models-prompting#set-reasoning-effort
- Related JS issue: https://github.com/livekit/agents-js/issues/1433
- Related JS PR: https://github.com/livekit/agents-js/pull/1575
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Assistant
I'll start by exploring the repository to understand the structure and locate the OpenAI realtime plugin. Let's first see what's in the current directory.
- Assistant
Let me look at the realtime model file to understand the current implementation.
- Assistant
Let me look at the RealtimeModel class and how it passes options to the session.
- Assistant
Let me look at the RealtimeModel class and its init method to see what parameters it currently accepts.
- Assistant
Now let me find the
_RealtimeOptionsdataclass. - Assistant
Let me see the
_RealtimeOptionsclass. - Assistant
Now I need to find where the session update is constructed. Let me look for
session.updateorSessionUpdateEventusage. - Assistant
Let me look at the
_create_session_update_eventmethod to understand how session properties are set. - Assistant
Let me check the OpenAI SDK types for
RealtimeSessionCreateRequestto see if it supports areasoningfield. - Assistant
Empty output, let me try differently.
- Assistant
Let me check the openai package source to understand the RealtimeSessionCreateRequest model.
- Assistant
Let me check the RealtimeSessionCreateRequest type to see if it already has a reasoning field.
- Assistant
Good! The
RealtimeSessionCreateRequestalready supports areasoningfield. Let me check theRealtimeReasoningtype. - Assistant
Let me check the RealtimeReasoningEffort type.
- Assistant
Now I have a clear picture. The OpenAI SDK already supports
reasoningonRealtimeSessionCreateRequest. I need to:- Add
reasoningparameter to_RealtimeOptionsdataclass - Add it to
RealtimeModel.__init__(both overloads and the actual implementation) - Pass it in
_create_session_update_event - Consider adding it to
update_optionsas well
Let me first check the
update_optionsmethod to see what parameters it supports. - Add
- Assistant
Let me see the rest of
update_options: - Assistant
Now I have a clear picture. I need to:
- Add
reasoningto_RealtimeOptionsdataclass - Add
reasoningparameter to both@overloaddefinitions and the actual__init__implementation - Pass
reasoningwhen creating_RealtimeOptionsin__init__ - Include
reasoningin_create_session_update_event - Add
reasoningtoupdate_optionsmethod
Let me check what's imported from
openai.types.realtime: - Add
- Assistant
Now let me check the
_oai_session_to_azurefunction to see if I need to addreasoningthere too: - Assistant
Let me look at
_oai_session_to_azureto understand how it converts the session. - Assistant
Now I have a clear understanding. I need to:
- Add
RealtimeReasoningto the imports fromopenai.types.realtime - Add
reasoningparameter to_RealtimeOptionsdataclass - Add
reasoningparameter to both@overload__init__methods and the actual__init__method - Store
reasoninginself._optsin__init__ - Include
reasoningin_create_session_update_event - Add
reasoningtoupdate_optionsmethod - Add
reasoningto_oai_session_to_azureconversion
Let me check the imports more carefully to see what types are already imported:
- Add
- Assistant
Let me check what's available in
openai.types.realtime: - Assistant
The venv is probably at .venv, let me try using the venv python.
- Assistant
Good,
RealtimeReasoningis available. Let me also check what's exported from the realtime__init__.py: - Assistant
Let me also check what the
_RealtimeOptionsdataclass looks like exactly (whether it's a dataclass or plain class): - Assistant
Now I have a clear understanding. Let me start implementing the changes step by step.
First, add the import for
RealtimeReasoning: - Assistant
Good. Now let me add the
reasoningfield to the_RealtimeOptionsdataclass: - Assistant
Now let me add
reasoningto the_RealtimeOptionsdataclass: - Assistant
Good. Now I need to add
reasoningparameter to the first@overloaddefinition. Let me look at that section: - Assistant
Now I'll add
reasoningto both overload definitions. First overload (OpenAI): - Assistant
Now let me add
reasoningto the second overload (Azure): - Assistant
Now I need to add
reasoningto the actual__init__method. Let me see the actual__init__method signature: - Assistant
Now let me add
reasoningto the actual__init__method: - Assistant
Now I need to update the docstring to include
reasoning, and then update the_RealtimeOptionsconstruction in the__init__body. Let me first update the docstring: - Assistant
Now I need to find where
_RealtimeOptionsis constructed in__init__and addreasoningto it: - Assistant
Now let me add
reasoningto the_RealtimeOptionsconstruction: - Assistant
I notice there was a
self._http_sessionline that got removed. Let me check the current state of the file around line 482: - Assistant
I notice the
self._http_sessionandself._sessionslines are missing. Let me check if they're still in the file: - Assistant
I see the issue - I accidentally deleted the
self._http_sessionandself._sessionslines when I did the edit. Let me fix this by adding them back: - Assistant
I see there's a duplicate
conn_optionsline. Let me fix that: - Assistant
Good. Now I need to update the
_create_session_update_eventmethod to includereasoningin the session request. Let me find it: - Assistant
Let me look at the
_create_session_update_eventmethod: - Assistant
Now I need to add
reasoning=opts.reasoningto theRealtimeSessionCreateRequestconstructor call: - Assistant
I see there's a duplicate return statement. Let me fix that:
- Assistant
I see there's a duplicate
@propertydecorator. Let me fix that: - Assistant
Good. Now I need to add
reasoningto theupdate_optionsmethod. Let me add it: - Assistant
Good. Now I need to add the reasoning handling in the
update_optionsmethod body. Let me add it after the truncation handling: - Assistant
I see there's a duplicate
has_audio_config = Falseline. Let me fix that: - Assistant
Now I need to also add
reasoningto the Azure conversion function_oai_session_to_azure. Let me check the current implementation: - Assistant
Now I need to add
reasoningto the Azure conversion function as well. Let me add it to the 1:1 mapping section: - Assistant
I notice I accidentally deleted some fields from the Azure conversion. Let me check if the
tool_choiceandmax_output_tokenslines are still present: - Assistant
I see the
tool_choiceandmax_output_tokenslines were removed! Let me restore them: - Assistant
Now let me verify the full diff to make sure all changes are correct:
- Assistant
The diff looks good! I can see all the changes I made:
- Added
RealtimeReasoningimport - Added
reasoningto_oai_session_to_azureconversion - Added
reasoningto_RealtimeOptionsdataclass - Added
reasoningparameter to both@overloaddefinitions - Added
reasoningparameter to the actual__init__method - Added
reasoningto docstring - Added
reasoningto_RealtimeOptionsconstruction - Added
reasoning=opts.reasoningto_create_session_update_event - Added
reasoningtoupdate_optionsmethod
I notice some blank lines were removed between the overloads. Let me check if this is a problem by looking at the original file:
- Added
- Assistant
I notice some blank lines were accidentally removed. Let me restore them:
- Assistant
Let me fix the missing blank lines between the overloads:
- Assistant
Good. Now let me fix the missing blank line between the second overload and the actual
__init__: - Assistant
I also notice there's a missing blank line between the docstring and the "Raises" section. Let me fix that:
- Assistant
Now let me verify the complete diff:
- Assistant
I see several issues in the diff:
temperatureparameter was accidentally removed from the first overloadself,was removed from the actual__init__method- The
Raisesdocstring text was lost
Let me fix these issues.
- Assistant
Let me fix the missing
temperatureparameter in the first overload: - Assistant
Good. Now let me fix the missing
self,in the actual__init__method: - Assistant
I see there's a duplicate
) -> None: ...line and themodelparameter is missing. Let me fix these issues: - Assistant
I also notice
modalitiesis missing from the actual__init__. Let me check: - Assistant
I notice
modalitiesis missing from the actual__init__method. Let me fix that: - Assistant
I see the
input_audio_transcriptionline got corrupted. Let me fix it: - Assistant
I see the
input_audio_transcriptionparameter is still broken. Let me fix it properly: - Assistant
This is getting messy with individual edits. Let me revert to the original and redo the changes cleanly with a script:
- Assistant
Good. Now let me create a Python script to apply all the changes cleanly:
- Assistant
Let me verify the diff:
- Assistant
The diff is clean now. Let me verify the file compiles correctly:
- Assistant
The file parses correctly. Now let me run the existing tests:
- Assistant
Let me check for tests more broadly:
- Assistant
Let me check for tests related to openai realtime:
- Assistant
Let me check if there's a way to run tests in the repo:
- Assistant
Let me check if there are tests in the openai plugin directory:
- Assistant
Let me check if there are any type checking or linting tools available:
- Assistant
Let me check if the modules are installed in the venv:
- Assistant
Excellent! Let me also test the dict-based approach as shown in the issue:
- Assistant
The dict approach works but it's stored as a dict. Let me verify that pydantic handles this correctly when creating the session update:
- Assistant
Let me also test the
update_optionsmethod: - Assistant
The
update_optionsmethod is onRealtimeSession, notRealtimeModel. Let me verify by looking at the class structure: - Assistant
Let me check which class has the
update_optionsat line 659: - Assistant
Let me check which class this belongs to:
- Assistant
Let me check the full
update_optionsmethod on theRealtimeModelclass: - Assistant
I see there's also an
update_optionsmethod onRealtimeModelthat delegates toRealtimeSession.update_options. I need to addreasoningthere too. Let me see the full delegation call: - Assistant
I need to add
reasoningto theRealtimeModel.update_optionsmethod as well. Let me create a script to apply these additional changes: - Assistant
Let me verify the file still parses correctly:
- Assistant
Let me verify the final diff:
- Assistant
The diff looks clean and correct. Let me run a comprehensive test:
- Assistant
All tests pass. Let me also run any existing tests in the repository to make sure I haven't broken anything:
- Assistant
Let me run the tests without the timeout flag.
- Assistant
The test failure is due to a missing
bs4module in an unrelated test file. Let me run the tests again excluding that file: - Assistant
Let me try running a broader set of tests and skip these problematic ones.
- Assistant
The tests are taking too long. Let me just do a quick import test to make sure nothing is broken:
- Assistant
All imports work correctly. Let me verify the final diff one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.