Skip to content

Conversation

iceljc
Copy link
Collaborator

@iceljc iceljc commented Sep 26, 2025

PR Type

Enhancement


Description

  • Add realtime options support for audio format configuration

  • Extend interfaces and implementations to pass options through the chain

  • Create new RealtimeOptions model for input/output audio formats

  • Update OpenAI provider to use options with fallback to settings


Diagram Walkthrough

flowchart LR
  A["ChatStreamRequest"] -- "contains" --> B["RealtimeOptions"]
  B -- "passed to" --> C["IRealtimeHub.ConnectToModel"]
  C -- "forwards to" --> D["IRealTimeCompletion.SetOptions"]
  D -- "used by" --> E["OpenAI Provider"]
  E -- "configures" --> F["Audio Formats"]
Loading

File Walkthrough

Relevant files
Enhancement
IRealTimeCompletion.cs
Add SetOptions method to IRealTimeCompletion interface     

src/Infrastructure/BotSharp.Abstraction/MLTasks/IRealTimeCompletion.cs

  • Add SetOptions method to interface for realtime configuration
+1/-0     
IRealtimeHub.cs
Extend ConnectToModel with options parameter                         

src/Infrastructure/BotSharp.Abstraction/Realtime/IRealtimeHub.cs

  • Add optional RealtimeOptions parameter to ConnectToModel method
+2/-1     
RealtimeOptions.cs
Create RealtimeOptions model for audio configuration         

src/Infrastructure/BotSharp.Abstraction/Realtime/Models/RealtimeOptions.cs

  • Create new model class with input/output audio format properties
  • Use JSON property names and ignore null values
+12/-0   
RealtimeHub.cs
Implement options support in RealtimeHub service                 

src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs

  • Add options parameter to ConnectToModel method
  • Pass options to completer via SetOptions call
+6/-1     
ChatStreamMiddleware.cs
Update middleware to handle realtime options                         

src/Plugins/BotSharp.Plugin.ChatHub/ChatStreamMiddleware.cs

  • Update method signature to accept ChatStreamRequest instead of states
  • Pass options from request to hub connection
  • Remove unused import
+3/-4     
ChatStreamRequest.cs
Add realtime options to ChatStreamRequest model                   

src/Plugins/BotSharp.Plugin.ChatHub/Models/Stream/ChatStreamRequest.cs

  • Add optional Options property of type RealtimeOptions
  • Configure JSON serialization with property name and null ignore
+4/-0     
RealTimeCompletionProvider.cs
Add SetOptions stub to Google AI provider                               

src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Realtime/RealTimeCompletionProvider.cs

  • Move SetModelName method to end of class
  • Add empty SetOptions implementation
+10/-5   
RealTimeCompletionProvider.cs
Implement realtime options in OpenAI provider                       

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs

  • Add _realtimeOptions field to store options
  • Implement SetOptions method to store options
  • Use options for audio formats with fallback to settings
+8/-2     

Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Null Handling

Ensure _completer is non-null and SetOptions safely handles null or unsupported options across providers; add guards or logs if provider not found or options ignored.

_completer = _services.GetServices<IRealTimeCompletion>().First(x => x.Provider == settings.Provider);
_completer.SetOptions(options);
Unused Options

SetOptions is empty; confirm whether Google provider should respect RealtimeOptions or explicitly log/ignore to avoid confusion.

public void SetOptions(RealtimeOptions? options)
{

}
Options Scope

Verify _realtimeOptions are applied consistently for all session updates and initial connect paths; ensure no race conditions if options change mid-session.

}).ToArray();

var realtimeModelSettings = _services.GetRequiredService<RealtimeModelSettings>();
var sessionUpdate = new
{
    type = "session.update",
    session = new RealtimeSessionUpdateRequest
    {
        InputAudioFormat = _realtimeOptions?.InputAudioFormat ?? realtimeModelSettings.InputAudioFormat,
        OutputAudioFormat = _realtimeOptions?.OutputAudioFormat ?? realtimeModelSettings.OutputAudioFormat,
        Voice = realtimeModelSettings.Voice,

Copy link

qodo-merge-pro bot commented Sep 26, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Pass options via method parameters

Refactor the design to avoid making the IRealTimeCompletion provider stateful.
Instead of using a SetOptions method, pass the RealtimeOptions object directly
as a parameter to the relevant methods like Connect.

Examples:

src/Infrastructure/BotSharp.Abstraction/MLTasks/IRealTimeCompletion.cs [10]
    void SetOptions(RealtimeOptions? options);
src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs [50-52]
        _completer.SetOptions(options);

        await _completer.Connect(

Solution Walkthrough:

Before:

// IRealTimeCompletion.cs
public interface IRealTimeCompletion
{
    void SetOptions(RealtimeOptions? options);
    Task Connect(...);
}

// RealtimeHub.cs
public async Task ConnectToModel(..., RealtimeOptions? options)
{
    _completer.SetOptions(options);
    await _completer.Connect(...);
}

// RealTimeCompletionProvider.cs
public class RealTimeCompletionProvider : IRealTimeCompletion
{
    private RealtimeOptions? _realtimeOptions;
    public void SetOptions(RealtimeOptions? options) { _realtimeOptions = options; }
    // ... uses _realtimeOptions in other methods
}

After:

// IRealTimeCompletion.cs
public interface IRealTimeCompletion
{
    // SetOptions is removed.
    Task Connect(..., RealtimeOptions? options);
}

// RealtimeHub.cs
public async Task ConnectToModel(..., RealtimeOptions? options)
{
    // Options are passed directly.
    await _completer.Connect(..., options);
}

// RealTimeCompletionProvider.cs
public class RealTimeCompletionProvider : IRealTimeCompletion
{
    // SetOptions is removed.
    public Task Connect(..., RealtimeOptions? options)
    {
        // Options are received and can be stored for the connection's lifetime.
        var _realtimeOptions = options;
        // ...
    }
}
Suggestion importance[1-10]: 9

__

Why: This is a critical architectural suggestion that correctly identifies the introduction of a stateful pattern via SetOptions, which can lead to temporal coupling and bugs; refactoring to a stateless approach by passing options through method parameters would significantly improve the design's robustness and maintainability.

High
Possible issue
Respect explicitly provided null options

Change the logic to respect explicitly null audio format options provided by the
client, instead of falling back to default settings.

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs [342-343]

-InputAudioFormat = _realtimeOptions?.InputAudioFormat ?? realtimeModelSettings.InputAudioFormat,
-OutputAudioFormat = _realtimeOptions?.OutputAudioFormat ?? realtimeModelSettings.OutputAudioFormat,
+InputAudioFormat = _realtimeOptions != null ? _realtimeOptions.InputAudioFormat : realtimeModelSettings.InputAudioFormat,
+OutputAudioFormat = _realtimeOptions != null ? _realtimeOptions.OutputAudioFormat : realtimeModelSettings.OutputAudioFormat,
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a logic issue where an explicitly provided null option is overridden by a default value, and proposes a fix that better reflects the user's intent.

Medium
Learned
best practice
Safely handle nullable options

Validate the nullable options parameter and store or ignore safely to avoid
future null reference issues. If not used yet, explicitly no-op with a guard.

src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Realtime/RealTimeCompletionProvider.cs [423-426]

+private RealtimeOptions? _realtimeOptions;
+
 public void SetOptions(RealtimeOptions? options)
 {
-
+    _realtimeOptions = options ?? new RealtimeOptions();
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why:
Relevant best practice - Ensure null-safety on optional inputs and object properties by guarding and providing safe defaults.

Low
  • Update

@iceljc iceljc merged commit cd604bf into SciSharp:master Oct 1, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant