mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.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:
committed by
GitHub
Unverified
parent
e6bfc51367
commit
14f3811648
@@ -22,11 +22,13 @@ public sealed class Step01_Running(ITestOutputHelper output) : AgentSample(outpu
|
||||
/// Demonstrate the usage of <see cref="ChatClientAgent"/> where each invocation is
|
||||
/// a unique interaction with no conversation history between them.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task RunWithoutThread()
|
||||
[Theory]
|
||||
[InlineData(ChatClientProviders.OpenAI)]
|
||||
[InlineData(ChatClientProviders.AzureOpenAI)]
|
||||
public async Task RunWithoutThread(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
|
||||
ChatClientAgent agent =
|
||||
@@ -37,12 +39,12 @@ public sealed class Step01_Running(ITestOutputHelper output) : AgentSample(outpu
|
||||
});
|
||||
|
||||
// Respond to user input
|
||||
await InvokeAgentAsync("Fortune favors the bold.");
|
||||
await InvokeAgentAsync("I came, I saw, I conquered.");
|
||||
await InvokeAgentAsync("Practice makes perfect.");
|
||||
await RunAgentAsync("Fortune favors the bold.");
|
||||
await RunAgentAsync("I came, I saw, I conquered.");
|
||||
await RunAgentAsync("Practice makes perfect.");
|
||||
|
||||
// Local function to invoke agent and display the conversation messages.
|
||||
async Task InvokeAgentAsync(string input)
|
||||
async Task RunAgentAsync(string input)
|
||||
{
|
||||
this.WriteUserMessage(input);
|
||||
|
||||
@@ -54,11 +56,13 @@ public sealed class Step01_Running(ITestOutputHelper output) : AgentSample(outpu
|
||||
/// <summary>
|
||||
/// Demonstrate the usage of <see cref="ChatClientAgent"/> where a conversation history is maintained.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task RunWithConversationThread()
|
||||
[Theory]
|
||||
[InlineData(ChatClientProviders.OpenAI)]
|
||||
[InlineData(ChatClientProviders.AzureOpenAI)]
|
||||
public async Task RunWithConversationThread(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
|
||||
ChatClientAgent agent =
|
||||
@@ -72,11 +76,11 @@ public sealed class Step01_Running(ITestOutputHelper output) : AgentSample(outpu
|
||||
AgentThread thread = agent.GetNewThread();
|
||||
|
||||
// Respond to user input
|
||||
await InvokeAgentAsync("Tell me a joke about a pirate.");
|
||||
await InvokeAgentAsync("Now add some emojis to the joke.");
|
||||
await RunAgentAsync("Tell me a joke about a pirate.");
|
||||
await RunAgentAsync("Now add some emojis to the joke.");
|
||||
|
||||
// Local function to invoke agent and display the conversation messages for the thread.
|
||||
async Task InvokeAgentAsync(string input)
|
||||
async Task RunAgentAsync(string input)
|
||||
{
|
||||
this.WriteUserMessage(input);
|
||||
|
||||
@@ -90,11 +94,13 @@ public sealed class Step01_Running(ITestOutputHelper output) : AgentSample(outpu
|
||||
/// Demonstrate the usage of <see cref="ChatClientAgent"/> in streaming mode,
|
||||
/// where a conversation is maintained by the <see cref="AgentThread"/>.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task StreamingRunWithConversationThread()
|
||||
[Theory]
|
||||
[InlineData(ChatClientProviders.OpenAI)]
|
||||
[InlineData(ChatClientProviders.AzureOpenAI)]
|
||||
public async Task StreamingRunWithConversationThread(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
|
||||
ChatClientAgent agent =
|
||||
@@ -108,11 +114,11 @@ public sealed class Step01_Running(ITestOutputHelper output) : AgentSample(outpu
|
||||
AgentThread thread = agent.GetNewThread();
|
||||
|
||||
// Respond to user input
|
||||
await InvokeAgentAsync("Tell me a joke about a pirate.");
|
||||
await InvokeAgentAsync("Now add some emojis to the joke.");
|
||||
await RunAgentAsync("Tell me a joke about a pirate.");
|
||||
await RunAgentAsync("Now add some emojis to the joke.");
|
||||
|
||||
// Local function to invoke agent and display the conversation messages.
|
||||
async Task InvokeAgentAsync(string input)
|
||||
async Task RunAgentAsync(string input)
|
||||
{
|
||||
this.WriteUserMessage(input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user