mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
1dde57981e
* WIP * WIP * Simple call working * Update Thinking sample * Non-Streaming Function calling working * Update Anthropic Impl * Public Preps * UT + IT working * Update documentation + samples * Update variable * Revert nuget.config * Add IT for BetaService implementation * Remove polyfill + enable IT to run for netstandard 2.0 * Skipping Anthropic IT's for manual execution and avoid pipeline execution * Fix compilation error * Address error in UT * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix warning * Net 10 update * Update for NET 10, remove Anthropic.Foundry due to vulnerability * Final missing adjustments for NET 10 * Address PR comments * Remove unused code * Address feedback --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
19 lines
729 B
C#
19 lines
729 B
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// This sample shows how to create and use a simple AI agent with OpenAI Chat Completion as the backend.
|
|
|
|
using Microsoft.Agents.AI;
|
|
using Microsoft.Extensions.AI;
|
|
using OpenAI;
|
|
|
|
var apiKey = Environment.GetEnvironmentVariable("OPENAI_APIKEY") ?? throw new InvalidOperationException("OPENAI_APIKEY is not set.");
|
|
var model = Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o-mini";
|
|
|
|
AIAgent agent = new OpenAIClient(
|
|
apiKey)
|
|
.GetChatClient(model)
|
|
.CreateAIAgent(instructions: "You are good at telling jokes.", name: "Joker");
|
|
|
|
// Invoke the agent and output the text result.
|
|
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));
|