mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Add some OpenAI and Foundry extension methods (#225)
* Add some OpenAI specific extensions * Update samples and extension methods * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add extension methods for creating agents using the Assistant API * Add orchestration sample * Add orchestration sample * Sample for the Foundry alignment document * Address code review feedback * Rename provider samples * Sample showing how to get an AI agent for Foundry SDK * Add OpenAI chat completion based implementation of AIAgent * Split OpenAI client extension methods by client type * Remove OpenAIClient extension methods * Rename AsRunnableAgent * Fix XML comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Shared.Samples;
|
||||
using OpenAI;
|
||||
using OpenAI.Chat;
|
||||
|
||||
namespace Custom;
|
||||
|
||||
/// <summary>
|
||||
/// End-to-end sample showing how to use a custom <see cref="OpenAIChatClientAgent"/>.
|
||||
/// </summary>
|
||||
public sealed class Custom_OpenAIChatClientAgent(ITestOutputHelper output) : AgentSample(output)
|
||||
{
|
||||
/// <summary>
|
||||
/// This will create an instance of <see cref="MyOpenAIChatClientAgent"/> and run it.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task RunCustomChatClientAgent()
|
||||
{
|
||||
var chatClient = new OpenAIClient(TestConfiguration.OpenAI.ApiKey).GetChatClient(TestConfiguration.OpenAI.ChatModelId);
|
||||
|
||||
var agent = new MyOpenAIChatClientAgent(chatClient);
|
||||
|
||||
var chatMessage = new UserChatMessage("Tell me a joke about a pirate.");
|
||||
var chatCompletion = await agent.RunAsync(chatMessage);
|
||||
|
||||
Console.WriteLine(chatCompletion.Content.Last().Text);
|
||||
}
|
||||
}
|
||||
|
||||
public class MyOpenAIChatClientAgent : OpenAIChatClientAgent
|
||||
{
|
||||
private const string JokerName = "Joker";
|
||||
private const string JokerInstructions = "You are good at telling jokes.";
|
||||
|
||||
public MyOpenAIChatClientAgent(ChatClient client, ILoggerFactory? loggerFactory = null) :
|
||||
base(client, instructions: JokerInstructions, name: JokerName, loggerFactory: loggerFactory)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user