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:
from 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 callsubmit) usinggit statusorgit diffcommands. 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
Let me start by exploring the repository structure to understand the codebase and find the relevant files for implementing the
reasoning.effortsupport for OpenAI gpt-realtime-2.Assistant
Let me look for the openai plugin in the repository, excluding the .venv directory.
Assistant
I found the relevant files. Let me look at the realtime model implementation to understand the current structure.
Assistant
I need to use a different approach to open the file. Let me read it with cat first.
Assistant
The file is quite long. Let me scroll through it to see the full structure, especially the
RealtimeModelclass definition and the_RealtimeOptionsdataclass to understand how options are configured.Assistant
Now let me look at the
_RealtimeOptionsdataclass and how the session is created to understand where I need to add thereasoningoption:Assistant
Now let me look at the
_create_session_update_eventmethod and how it builds theRealtimeSessionCreateRequest:Assistant
Now let me check what the OpenAI SDK provides for the
reasoningfield in theRealtimeSessionCreateRequest:Assistant
Let me examine the
RealtimeReasoningclass:Assistant
Now I have a clear picture of what I need to do:
- Add a
reasoningfield to the_RealtimeOptionsdataclass - Add a
reasoningparameter to theRealtimeModel.__init__method (all three overloads) - Pass the
reasoningoption when creatingRealtimeSessionCreateRequestin_create_session_update_event - Also handle it in the Azure conversion function
_oai_session_to_azure
Let me also check the
__init__.pyto see what's exported:- Add a
Assistant
Now let me also look at the JS PR for reference to understand the expected API design:
Assistant
Now let me look at the
update_optionsmethod and also check if there's ageneratemethod that might need reasoning:Assistant
Let me also check the
with_azureclassmethod and howRealtimeReasoningis imported from the OpenAI package:Assistant
Now I have a complete picture. Let me also check the imports section more carefully and the
_oai_session_to_azurefunction to understand how to handle reasoning for Azure:Assistant
Now let me look at the
_oai_session_to_azurefunction to see if reasoning needs to be handled there:Assistant
Now I have all the information I need. Let me check if the Azure API supports reasoning by looking at the Azure session type:
Assistant
Good, Azure beta doesn't support reasoning yet, so I don't need to add it to the Azure conversion. Let me now implement the changes:
Assistant
Now let me implement the changes. I need to:
- Add
RealtimeReasoningto the imports fromopenai.types.realtime - Add
reasoningfield to_RealtimeOptions - Add
reasoningparameter to all three overloads of__init__ - Store
reasoningin_opts - Pass
reasoningwhen creatingRealtimeSessionCreateRequestin_create_session_update_event - Add
reasoningto thewith_azuremethod signature (for consistency, even if not used)
Let me start by adding the import:
- Add
Assistant
Now I'll make all the necessary edits. Let me start:
Step 1: Add
RealtimeReasoningto importsAssistant
Step 2: Add
reasoningfield to_RealtimeOptionsdataclassAssistant
Step 3: Add
reasoningparameter to the first overload of__init__Assistant
The line numbers have shifted by 1 because I added the RealtimeReasoning import. Let me add the
reasoningparameter to the first overload. I'll add it aftertruncationand beforeapi_key.Assistant
That sed command with newlines is tricky. Let me verify and use a different approach:
Assistant
The multiline sed didn't work. Let me use Python to make the edits more reliably:
Assistant
Let me verify the changes were applied correctly:
Assistant
The overloads are updated. Now I need to continue checking the implementation to see if the
reasoningparameter is also added to the actual__init__method body, and then verify the rest of the changes.Assistant
Good, the
reasoningparameter is now in all three__init__overloads. Now I need to:- Update the docstring to include
reasoning - Update
_optsinitialization to includereasoning - Update
_create_session_update_eventto passreasoningto the session request - Update
with_azuremethod to acceptreasoningparameter
Let me do these changes:
- Update the docstring to include
Assistant
Now let me update the
_optsinitialization to includereasoning:Assistant
Now update
_create_session_update_eventto pass reasoning:Assistant
Now let me update the
with_azuremethod to accept thereasoningparameter:Assistant
Now I need to update the return statement in
with_azureto pass thereasoningparameter:Assistant
The
with_azuremethod returns aRealtimeModelinstance. I need to addreasoning=reasoningto the kwargs passed to it. Let me update that.Assistant
Now I also notice there's another
update_optionsmethod in theRealtimeModelclass that seems to be a different version (in the old Azure code). Let me check and verify the structure is correct:Assistant
I see there are two
update_optionsmethods. One at line 660 (inRealtimeModelclass) and one at line 1217 (inRealtimeSessionclass). Let me check the full first one to understand what needs updating:Assistant
I see. The first
update_optionsis a simpler version inRealtimeModelthat delegates toRealtimeSession.update_options. I should also addreasoningto this method for completeness. Let me update it:Assistant
Now let me also update the
RealtimeSession.update_optionsmethod:Assistant
The
RealtimeSession.update_optionsmethod also needs to be updated to include thereasoningparameter. Let me update it.Assistant
Now let me verify all the changes are correct by checking the syntax of the file:
Assistant
Good, the syntax is valid. Now let me verify the key parts of the file are correct:
Assistant
All the reasoning-related changes are in place. Let me also verify the import is correct:
Assistant
Let me verify the import section to make sure RealtimeReasoning is properly imported.
Assistant
Good, the import is in place. Let me create a simple test script to verify the API works as expected:
Assistant
I have a dataclass error. The
reasoningfield was added afterspeedwhich has a default value, butreasoningdoesn't have a default. I need to givereasoninga default value ofNone.Assistant
The error is still happening because I need to verify the change was applied correctly. Let me check the dataclass.
Assistant
The dataclass now has
reasoning: RealtimeReasoning | None = Nonewhich should be correct sincespeed: float = 1.0has a default value andreasoningalso has a default value. Let me run the test again.Assistant
Good, the basic tests pass. Now let me look for existing tests related to the realtime module and run them:
Assistant
Let me check the existing realtime tests to see if there are any tests I should run to validate my changes don't break anything.
Assistant
The existing tests require API credentials to run (they call the actual OpenAI API). Let me verify my changes are syntactically correct and check if there are any type-checking tools available:
Assistant
All the changes have been made and verified. Let me now run a final check to make sure there are no issues with the code and verify the complete diff of my changes.
Assistant
I need to execute a git diff command to see the changes I made.
Assistant
The diff looks correct and complete. Let me clean up my test file and submit the changes.
Assistant
Let me verify once more that the code compiles and the module imports correctly:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.