.Net: Add Azure OpenAI Agent Model Samples (#80)

* Improved Merge logic

* Add modularization for Model Samples and Azure OpenAI

* Address PR feedback

* Warning fix

* Address PR comments
This commit is contained in:
Roger Barreto
2025-06-18 13:00:38 +01:00
committed by GitHub
Unverified
parent e6bfc51367
commit 14f3811648
10 changed files with 235 additions and 100 deletions
@@ -8,11 +8,13 @@ namespace Steps;
public sealed class Step02_UsingTools(ITestOutputHelper output) : AgentSample(output)
{
[Fact]
public async Task RunningWithTools()
[Theory]
[InlineData(ChatClientProviders.OpenAI)]
[InlineData(ChatClientProviders.AzureOpenAI)]
public async Task RunningWithTools(ChatClientProviders provider)
{
// Get the chat client to use for the agent.
using var chatClient = base.GetOpenAIChatClient();
using var chatClient = base.GetChatClient(provider);
// Define the agent
var menuTools = new MenuTools();
@@ -35,12 +37,12 @@ public sealed class Step02_UsingTools(ITestOutputHelper output) : AgentSample(ou
var thread = agent.GetNewThread();
// Respond to user input, invoking functions where appropriate.
await InvokeAgentAsync("Hello");
await InvokeAgentAsync("What is the special soup and its price?");
await InvokeAgentAsync("What is the special drink and its price?");
await InvokeAgentAsync("Thank you");
await RunAgentAsync("Hello");
await RunAgentAsync("What is the special soup and its price?");
await RunAgentAsync("What is the special drink and its price?");
await RunAgentAsync("Thank you");
async Task InvokeAgentAsync(string input)
async Task RunAgentAsync(string input)
{
this.WriteUserMessage(input);
var response = await agent.RunAsync(input, thread);
@@ -48,11 +50,13 @@ public sealed class Step02_UsingTools(ITestOutputHelper output) : AgentSample(ou
}
}
[Fact]
public async Task StreamingRunWithTools()
[Theory]
[InlineData(ChatClientProviders.OpenAI)]
[InlineData(ChatClientProviders.AzureOpenAI)]
public async Task StreamingRunWithTools(ChatClientProviders provider)
{
// Get the chat client to use for the agent.
using var chatClient = base.GetOpenAIChatClient();
using var chatClient = base.GetChatClient(provider);
// Define the agent
var menuTools = new MenuTools();
@@ -75,12 +79,12 @@ public sealed class Step02_UsingTools(ITestOutputHelper output) : AgentSample(ou
var thread = agent.GetNewThread();
// Respond to user input, invoking functions where appropriate.
await InvokeAgentAsync("Hello");
await InvokeAgentAsync("What is the special soup and its price?");
await InvokeAgentAsync("What is the special drink and its price?");
await InvokeAgentAsync("Thank you");
await RunAgentAsync("Hello");
await RunAgentAsync("What is the special soup and its price?");
await RunAgentAsync("What is the special drink and its price?");
await RunAgentAsync("Thank you");
async Task InvokeAgentAsync(string input)
async Task RunAgentAsync(string input)
{
this.WriteUserMessage(input);
await foreach (var update in agent.RunStreamingAsync(input, thread))