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?
Add a comment
|
1 Answer
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();
}
}
}
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;
..............
}