Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ if __name__ == "__main__":
// dotnet add package Azure.AI.OpenAI
// dotnet add package Azure.Identity
// Use `az login` to authenticate with Azure CLI
using System;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI;
using System.ClientModel.Primitives;

var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!;
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME")!;

var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
var agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetOpenAIResponseClient(deploymentName)
.CreateAIAgent(name: "HaikuBot", instructions: "You are an upbeat assistant that writes beautifully.");

Expand Down
1 change: 0 additions & 1 deletion dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<PackageVersion Include="Aspire.Microsoft.Azure.Cosmos" Version="$(AspireAppHostSdkVersion)" />
<PackageVersion Include="Aspire.Hosting.Testing" Version="$(AspireAppHostSdkVersion)" />
<PackageVersion Include="Azure.AI.Agents.Persistent" Version="1.2.0-beta.5" />
<PackageVersion Include="Azure.AI.OpenAI" Version="2.3.0-beta.2" />
<PackageVersion Include="Azure.Identity" Version="1.16.0" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.4.0" />
<PackageVersion Include="CommunityToolkit.Aspire.OllamaSharp" Version="9.8.0" />
Expand Down
9 changes: 5 additions & 4 deletions dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
### Basic Agent - .NET

```c#
using System;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI;
using System.ClientModel.Primitives;

var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!;
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME")!;

var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
var agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetOpenAIResponseClient(deploymentName)
.CreateAIAgent(name: "HaikuBot", instructions: "You are an upbeat assistant that writes beautifully.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
Expand Down
7 changes: 5 additions & 2 deletions dotnet/samples/GettingStarted/AgentOpenTelemetry/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright (c) Microsoft. All rights reserved.

using System.ClientModel.Primitives;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.Metrics;
using Azure.AI.OpenAI;
using Azure.Identity;
using Azure.Monitor.OpenTelemetry.Exporter;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OpenAI;
using OpenTelemetry;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
Expand Down Expand Up @@ -110,7 +111,9 @@ static async Task<string> GetWeatherAsync([Description("The location to get the
return $"The weather in {location} is cloudy with a high of 15°C.";
}

using var instrumentedChatClient = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
using var instrumentedChatClient = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetChatClient(deploymentName)
.AsIChatClient() // Converts a native OpenAI SDK ChatClient into a Microsoft.Extensions.AI.IChatClient
.AsBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// This sample shows how to create and use a simple AI agent with Azure OpenAI Chat Completion as the backend.

using Azure.AI.OpenAI;
using System.ClientModel.Primitives;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI;
Expand All @@ -13,9 +13,9 @@
const string JokerName = "Joker";
const string JokerInstructions = "You are good at telling jokes.";

AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
AIAgent agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetChatClient(deploymentName)
.CreateAIAgent(JokerInstructions, JokerName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// This sample shows how to create and use a simple AI agent with Azure OpenAI Responses as the backend.

using Azure.AI.OpenAI;
using System.ClientModel.Primitives;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI;
Expand All @@ -13,9 +13,9 @@
const string JokerName = "Joker";
const string JokerInstructions = "You are good at telling jokes.";

AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
AIAgent agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetOpenAIResponseClient(deploymentName)
.CreateAIAgent(JokerInstructions, JokerName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// This sample shows how to create and use a simple AI agent with Azure OpenAI as the backend.

using Azure.AI.OpenAI;
using System.ClientModel.Primitives;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI;
Expand All @@ -13,9 +13,9 @@
const string JokerName = "Joker";
const string JokerInstructions = "You are good at telling jokes.";

AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
AIAgent agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetChatClient(deploymentName)
.CreateAIAgent(JokerInstructions, JokerName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// This sample shows how to create and use a simple AI agent with a multi-turn conversation.

using Azure.AI.OpenAI;
using System.ClientModel.Primitives;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI;
Expand All @@ -13,9 +13,9 @@
const string JokerName = "Joker";
const string JokerInstructions = "You are good at telling jokes.";

AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
AIAgent agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetChatClient(deploymentName)
.CreateAIAgent(JokerInstructions, JokerName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// This sample demonstrates how to use a ChatClientAgent with function tools.
// It shows both non-streaming and streaming agent interactions using menu-related tools.

using System.ClientModel.Primitives;
using System.ComponentModel;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
Expand All @@ -18,9 +18,9 @@ static string GetWeather([Description("The location to get the weather for.")] s
=> $"The weather in {location} is cloudy with a high of 15°C.";

// Create the chat client and agent, and provide the function tool to the agent.
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
AIAgent agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetChatClient(deploymentName)
.CreateAIAgent(instructions: "You are a helpful assistant", tools: [AIFunctionFactory.Create(GetWeather)]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// If the agent is hosted in a service, with a remote user, combine this sample with the Persisted Conversations sample to persist the chat history
// while the agent is waiting for user input.

using System.ClientModel.Primitives;
using System.ComponentModel;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
Expand All @@ -22,9 +22,9 @@ static string GetWeather([Description("The location to get the weather for.")] s

// Create the chat client and agent.
// Note that we are wrapping the function tool with ApprovalRequiredAIFunction to require user approval before invoking it.
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
AIAgent agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetChatClient(deploymentName)
.CreateAIAgent(instructions: "You are a helpful assistant", tools: [new ApprovalRequiredAIFunction(AIFunctionFactory.Create(GetWeather))]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

// This sample shows how to create and use a simple AI agent with Azure OpenAI as the backend, to produce structured output using JSON schema from a class.

using System.ClientModel.Primitives;
using System.ComponentModel;
using System.Text.Json;
using System.Text.Json.Serialization;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
Expand All @@ -25,9 +25,9 @@
};

// Create the agent using Azure OpenAI.
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
AIAgent agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetChatClient(deploymentName)
.CreateAIAgent(agentOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// This sample shows how to create and use a simple AI agent with a conversation that can be persisted to disk.

using System.ClientModel.Primitives;
using System.Text.Json;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI;
Expand All @@ -15,9 +15,9 @@
const string JokerInstructions = "You are good at telling jokes.";

// Create the agent
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
AIAgent agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetChatClient(deploymentName)
.CreateAIAgent(JokerInstructions, JokerName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

// This sample shows how to create and use a simple AI agent with a conversation that can be persisted to disk.

using System.ClientModel.Primitives;
using System.Text.Json;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
Expand All @@ -25,9 +25,9 @@
VectorStore vectorStore = new InMemoryVectorStore();

// Create the agent
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
AIAgent agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetChatClient(deploymentName)
.CreateAIAgent(new ChatClientAgentOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
<PackageReference Include="OpenTelemetry" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// This sample shows how to create and use a simple AI agent with Azure OpenAI as the backend that logs telemetry using OpenTelemetry.

using Azure.AI.OpenAI;
using System.ClientModel.Primitives;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI;
Expand All @@ -24,7 +24,9 @@
.Build();

// Create the agent, and enable OpenTelemetry instrumentation.
AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
AIAgent agent = new OpenAIClient(
new BearerTokenPolicy(new AzureCliCredential(), "https://cognitiveservices.azure.com/.default"),
new OpenAIClientOptions() { Endpoint = new Uri($"{endpoint}/openai/v1") })
.GetChatClient(deploymentName)
.CreateAIAgent(JokerInstructions, JokerName)
.AsBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
Expand Down
Loading
Loading