.NET: Update M.A.AI.OpenAI implementations (#1018)

* Update M.A.AI.OpenAI implementations

- There was only a ChatClient-based agent. Add a Responses one, too.
- Fix the public extension methods to create OpenAI types even when not backed by the right OpenAI client.
- Add reusable AgentRunResponse{Update} to ChatResponse{Update} conversion routines that are then used by the OpenAI agents and elsewhere

* Address feedback
This commit is contained in:
Stephen Toub
2025-09-30 15:06:10 -04:00
committed by GitHub
Unverified
parent 8dad045c9d
commit 2d20e644df
11 changed files with 275 additions and 184 deletions
@@ -3,7 +3,7 @@
using System.ClientModel;
using OpenAI.Chat;
namespace Microsoft.Agents.AI.OpenAI.ChatClient;
namespace Microsoft.Agents.AI.OpenAI;
internal sealed class AsyncStreamingUpdateCollectionResult : AsyncCollectionResult<StreamingChatCompletionUpdate>
{
@@ -19,13 +19,10 @@ internal sealed class AsyncStreamingUpdateCollectionResult : AsyncCollectionResu
public override IAsyncEnumerable<ClientResult> GetRawPagesAsync() =>
AsyncEnumerable.Repeat(ClientResult.FromValue(this._updates, new StreamingUpdatePipelineResponse(this._updates)), 1);
protected override async IAsyncEnumerable<StreamingChatCompletionUpdate> GetValuesFromPageAsync(ClientResult page)
protected override IAsyncEnumerable<StreamingChatCompletionUpdate> GetValuesFromPageAsync(ClientResult page)
{
var updates = ((ClientResult<IAsyncEnumerable<AgentRunResponseUpdate>>)page).Value;
await foreach (var update in updates.ConfigureAwait(false))
{
yield return update.AsStreamingChatCompletionUpdate();
}
return updates.AsChatResponseUpdatesAsync().AsOpenAIStreamingChatCompletionUpdatesAsync();
}
}
@@ -2,7 +2,7 @@
using System.ClientModel.Primitives;
namespace Microsoft.Agents.AI.OpenAI.ChatClient;
namespace Microsoft.Agents.AI.OpenAI;
internal sealed class StreamingUpdatePipelineResponse : PipelineResponse
{