mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.Net: Add OpenAI Responses Agent Samples (#83)
* Improved Merge logic * Add modularization for Model Samples and Azure OpenAI * Address PR feedback * Warning fix * Address PR comments * Adding OpenAI Response Samples * Clean up * Revert to provider specific chat options * Fix warnings * Revert slnx changes
This commit is contained in:
@@ -6,6 +6,7 @@ using Azure.Identity;
|
||||
using Microsoft.Extensions.AI;
|
||||
using Microsoft.Shared.Samples;
|
||||
using OpenAI;
|
||||
using OpenAI.Responses;
|
||||
|
||||
namespace GettingStarted;
|
||||
|
||||
@@ -18,17 +19,30 @@ public class AgentSample(ITestOutputHelper output) : BaseSample(output)
|
||||
{
|
||||
OpenAI,
|
||||
AzureOpenAI,
|
||||
OpenAIResponses,
|
||||
OpenAIResponses_InMemoryMessage,
|
||||
OpenAIResponses_ConversationId
|
||||
}
|
||||
|
||||
protected IChatClient GetChatClient(ChatClientProviders provider)
|
||||
{
|
||||
return provider switch
|
||||
=> provider switch
|
||||
{
|
||||
ChatClientProviders.OpenAI => GetOpenAIChatClient(),
|
||||
ChatClientProviders.AzureOpenAI => GetAzureOpenAIChatClient(),
|
||||
ChatClientProviders.OpenAIResponses or
|
||||
ChatClientProviders.OpenAIResponses_InMemoryMessage or
|
||||
ChatClientProviders.OpenAIResponses_ConversationId
|
||||
=> GetOpenAIResponsesClient(),
|
||||
_ => throw new NotSupportedException($"Provider {provider} is not supported.")
|
||||
};
|
||||
}
|
||||
|
||||
protected ChatOptions? GetChatOptions(ChatClientProviders? provider)
|
||||
=> provider switch
|
||||
{
|
||||
ChatClientProviders.OpenAIResponses_InMemoryMessage => new() { RawRepresentationFactory = static (_) => new ResponseCreationOptions() { StoredOutputEnabled = false } },
|
||||
ChatClientProviders.OpenAIResponses_ConversationId => new() { RawRepresentationFactory = static (_) => new ResponseCreationOptions() { StoredOutputEnabled = true } },
|
||||
_ => null
|
||||
};
|
||||
|
||||
private IChatClient GetOpenAIChatClient()
|
||||
=> new OpenAIClient(TestConfiguration.OpenAI.ApiKey)
|
||||
@@ -42,4 +56,9 @@ public class AgentSample(ITestOutputHelper output) : BaseSample(output)
|
||||
: new AzureOpenAIClient(TestConfiguration.AzureOpenAI.Endpoint, new ApiKeyCredential(TestConfiguration.AzureOpenAI.ApiKey)))
|
||||
.GetChatClient(TestConfiguration.AzureOpenAI.DeploymentName)
|
||||
.AsIChatClient();
|
||||
|
||||
private IChatClient GetOpenAIResponsesClient()
|
||||
=> new OpenAIClient(TestConfiguration.OpenAI.ApiKey)
|
||||
.GetOpenAIResponseClient(TestConfiguration.OpenAI.ChatModelId)
|
||||
.AsIChatClient();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user