1

The Azure OpenAI SDK appears to follow a one-client-per-session model, but I want to be sure. Since it is still in beta, it is not clear if a single instance of the client returned by AzureOpenAIClient.GetRealtimeConversationClient is able to create multiple session objects or there should be an instance of RealtimeConversationClient per every RealtimeConversationSession?

1 Answer 1

0

The single instance of the client returned by AzureOpenAIClient.GetRealtimeConversationClient should able to create multiple session objects.

Here is some source code of using RealtimeConversationClient to create RealtimeConversationSession.

internal partial class AzureRealtimeConversationClient : RealtimeConversationClient
{
    /// <summary>
    /// <para>[Protocol Method]</para>
    /// Creates a new realtime conversation operation instance, establishing a connection with the /realtime endpoint.
    /// </summary>
    /// <param name="options"></param>
    /// <returns></returns>
    [EditorBrowsable(EditorBrowsableState.Never)]
    public override async Task<RealtimeConversationSession> StartConversationSessionAsync(RequestOptions options)
    {
        RealtimeConversationSession provisionalOperation = _tokenCredential is not null
            ? new AzureRealtimeConversationSession(this, _endpoint, _tokenCredential, _tokenAuthorizationScopes, _userAgent)
            : new AzureRealtimeConversationSession(this, _endpoint, _credential, _userAgent);
        try
        {
            await provisionalOperation.ConnectAsync(options).ConfigureAwait(false);
            RealtimeConversationSession result = provisionalOperation;
            provisionalOperation = null;
            return result;
        }
        finally
        {
            provisionalOperation?.Dispose();
        }
    }
}

https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/openai/Azure.AI.OpenAI/src/Custom/RealtimeConversation/AzureRealtimeConversationClient.Protocol.cs#L24

If you want to test it out to be 100% sure, there are a few test case in the repo too like below

    public async Task TextOnlyWorks(AzureOpenAIClientOptions.ServiceVersion? version)
    {
        RealtimeConversationClient client = GetTestClient(GetTestClientOptions(version));

        using RealtimeConversationSession session = await client.StartConversationSessionAsync(CancellationToken);
        // duplicate above statement to create multiple sessions and see if these multiple sessions work as normal.

        await session.AddItemAsync(
            ConversationItem.CreateUserMessage(["Hello, world!"]),
            cancellationToken: CancellationToken);
        await session.StartResponseAsync(CancellationToken);

        StringBuilder responseBuilder = new();
        bool gotResponseDone = false;
        bool gotRateLimits = false;
        ..............
 
     }

https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/openai/Azure.AI.OpenAI/tests/ConversationTests.cs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.