Skip to content

Merge main into live #45372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
<PackageReference Include="Azure.Identity" Version="1.13.2" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion docs/ai/how-to/snippets/content-filtering/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{
ChatResponse completion = await client.GetResponseAsync("YOUR_PROMPT");

Console.WriteLine(completion.Message);
Console.WriteLine(completion.Messages.Single());
}
catch (Exception e)
{
Expand Down
4 changes: 2 additions & 2 deletions docs/ai/quickstarts/evaluate-ai-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Complete the following steps to create an MSTest project that connects to your l

- Sets up the <xref:Microsoft.Extensions.AI.Evaluation.ChatConfiguration>.
- Sets the <xref:Microsoft.Extensions.AI.ChatOptions>, including the <xref:Microsoft.Extensions.AI.ChatOptions.Temperature> and the <xref:Microsoft.Extensions.AI.ChatOptions.ResponseFormat>.
- Fetches the response to be evaluated by calling <xref:Microsoft.Extensions.AI.IChatClient.GetResponseAsync(System.Collections.Generic.IList{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatOptions,System.Threading.CancellationToken)>, and stores it in a static variable.
- Fetches the response to be evaluated by calling <xref:Microsoft.Extensions.AI.IChatClient.GetResponseAsync(System.Collections.Generic.IEnumerable{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatOptions,System.Threading.CancellationToken)>, and stores it in a static variable.

1. Add the `GetOllamaChatConfiguration` method, which creates the <xref:Microsoft.Extensions.AI.IChatClient> that the evaluator uses to communicate with the model.

Expand All @@ -102,7 +102,7 @@ Complete the following steps to create an MSTest project that connects to your l

This method does the following:

- Invokes the <xref:Microsoft.Extensions.AI.Evaluation.Quality.CoherenceEvaluator> to evaluate the *coherence* of the response. The <xref:Microsoft.Extensions.AI.Evaluation.IEvaluator.EvaluateAsync(System.Collections.Generic.IEnumerable{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatMessage,Microsoft.Extensions.AI.Evaluation.ChatConfiguration,System.Collections.Generic.IEnumerable{Microsoft.Extensions.AI.Evaluation.EvaluationContext},System.Threading.CancellationToken)> method returns an <xref:Microsoft.Extensions.AI.Evaluation.EvaluationResult> that contains a <xref:Microsoft.Extensions.AI.Evaluation.NumericMetric>. A `NumericMetric` contains a numeric value that's typically used to represent numeric scores that fall within a well-defined range.
- Invokes the <xref:Microsoft.Extensions.AI.Evaluation.Quality.CoherenceEvaluator> to evaluate the *coherence* of the response. The <xref:Microsoft.Extensions.AI.Evaluation.IEvaluator.EvaluateAsync(System.Collections.Generic.IEnumerable{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatResponse,Microsoft.Extensions.AI.Evaluation.ChatConfiguration,System.Collections.Generic.IEnumerable{Microsoft.Extensions.AI.Evaluation.EvaluationContext},System.Threading.CancellationToken)> method returns an <xref:Microsoft.Extensions.AI.Evaluation.EvaluationResult> that contains a <xref:Microsoft.Extensions.AI.Evaluation.NumericMetric>. A `NumericMetric` contains a numeric value that's typically used to represent numeric scores that fall within a well-defined range.
- Retrieves the coherence score from the <xref:Microsoft.Extensions.AI.Evaluation.EvaluationResult>.
- Validates the *default interpretation* for the returned coherence metric. Evaluators can include a default interpretation for the metrics they return. You can also change the default interpretation to suit your specific requirements, if needed.
- Validates that no diagnostics are present on the returned coherence metric. Evaluators can include diagnostics on the metrics they return to indicate errors, warnings, or other exceptional conditions encountered during evaluation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Microsoft.Extensions.VectorData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VectorDataAI
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.VectorData;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.VectorData;
using Microsoft.SemanticKernel.Connectors.InMemory;
using VectorDataAI;

Expand Down Expand Up @@ -60,26 +60,26 @@

// Create and populate the vector store
var vectorStore = new InMemoryVectorStore();
var cloudServicesStore = vectorStore.GetCollection<int, CloudService>("cloudServices");
Microsoft.Extensions.VectorData.IVectorStoreRecordCollection<int, CloudService> cloudServicesStore = vectorStore.GetCollection<int, CloudService>("cloudServices");
await cloudServicesStore.CreateCollectionIfNotExistsAsync();

foreach (var service in cloudServices)
foreach (CloudService service in cloudServices)
{
service.Vector = await generator.GenerateEmbeddingVectorAsync(service.Description);
await cloudServicesStore.UpsertAsync(service);
}

// Convert a search query to a vector and search the vector store
var query = "Which Azure service should I use to store my Word documents?";
var queryEmbedding = await generator.GenerateEmbeddingVectorAsync(query);
string query = "Which Azure service should I use to store my Word documents?";
ReadOnlyMemory<float> queryEmbedding = await generator.GenerateEmbeddingVectorAsync(query);

var results = await cloudServicesStore.VectorizedSearchAsync(queryEmbedding, new VectorSearchOptions()
VectorSearchResults<CloudService> results =
await cloudServicesStore.VectorizedSearchAsync(queryEmbedding, new VectorSearchOptions<CloudService>()
{
Top = 1,
VectorPropertyName = "Vector"
Top = 1
});

await foreach (var result in results.Results)
await foreach (VectorSearchResult<CloudService> result in results.Results)
{
Console.WriteLine($"Name: {result.Record.Name}");
Console.WriteLine($"Description: {result.Record.Description}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.13.2" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.1-preview.1.24570.5" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25078.1" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.31.0-preview" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25161.1" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.41.0-preview" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.1.25080.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.1.25080.5" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Microsoft.Extensions.VectorData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VectorDataAI
{
Expand Down
52 changes: 23 additions & 29 deletions docs/ai/quickstarts/snippets/chat-with-data/openai/Program.cs
Original file line number Diff line number Diff line change
@@ -1,83 +1,77 @@
using Microsoft.Extensions.AI;
using OpenAI;
using System.ClientModel;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.VectorData;
using Microsoft.SemanticKernel.Connectors.InMemory;
using OpenAI;
using VectorDataAI;
using System.ClientModel;
using Microsoft.Extensions.Configuration;

var cloudServices = new List<CloudService>()
{
new CloudService
{
new() {
Key=0,
Name="Azure App Service",
Description="Host .NET, Java, Node.js, and Python web applications and APIs in a fully managed Azure service. You only need to deploy your code to Azure. Azure takes care of all the infrastructure management like high availability, load balancing, and autoscaling."
},
new CloudService
{
new() {
Key=1,
Name="Azure Service Bus",
Description="A fully managed enterprise message broker supporting both point to point and publish-subscribe integrations. It's ideal for building decoupled applications, queue-based load leveling, or facilitating communication between microservices."
},
new CloudService
{
new() {
Key=2,
Name="Azure Blob Storage",
Description="Azure Blob Storage allows your applications to store and retrieve files in the cloud. Azure Storage is highly scalable to store massive amounts of data and data is stored redundantly to ensure high availability."
},
new CloudService
{
new() {
Key=3,
Name="Microsoft Entra ID",
Description="Manage user identities and control access to your apps, data, and resources.."
},
new CloudService
{
new() {
Key=4,
Name="Azure Key Vault",
Description="Store and access application secrets like connection strings and API keys in an encrypted vault with restricted access to make sure your secrets and your application aren't compromised."
},
new CloudService
{
new() {
Key=5,
Name="Azure AI Search",
Description="Information retrieval at scale for traditional and conversational search applications, with security and options for AI enrichment and vectorization."
}
};

// Load the configuration values
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
// Load the configuration values.
IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
string model = config["ModelName"];
string key = config["OpenAIKey"];

// Create the embedding generator
// Create the embedding generator.
IEmbeddingGenerator<string, Embedding<float>> generator =
new OpenAIClient(new ApiKeyCredential(key))
.AsEmbeddingGenerator(modelId: model);

// Create and populate the vector store
// Create and populate the vector store.
var vectorStore = new InMemoryVectorStore();
var cloudServicesStore = vectorStore.GetCollection<int, CloudService>("cloudServices");
IVectorStoreRecordCollection<int, CloudService> cloudServicesStore = vectorStore.GetCollection<int, CloudService>("cloudServices");
await cloudServicesStore.CreateCollectionIfNotExistsAsync();

foreach (var service in cloudServices)
foreach (CloudService service in cloudServices)
{
service.Vector = await generator.GenerateEmbeddingVectorAsync(service.Description);
await cloudServicesStore.UpsertAsync(service);
}

// Convert a search query to a vector and search the vector store
var query = "Which Azure service should I use to store my Word documents?";
var queryEmbedding = await generator.GenerateEmbeddingVectorAsync(query);
// Convert a search query to a vector and search the vector store.
string query = "Which Azure service should I use to store my Word documents?";
ReadOnlyMemory<float> queryEmbedding = await generator.GenerateEmbeddingVectorAsync(query);

var results = await cloudServicesStore.VectorizedSearchAsync(queryEmbedding, new VectorSearchOptions()
VectorSearchResults<CloudService> results =
await cloudServicesStore.VectorizedSearchAsync(queryEmbedding, new VectorSearchOptions<CloudService>()
{
Top = 1,
VectorPropertyName = "Vector"
Top = 1
});

await foreach (var result in results.Results)
await foreach (VectorSearchResult<CloudService> result in results.Results)
{
Console.WriteLine($"Name: {result.Record.Name}");
Console.WriteLine($"Description: {result.Record.Description}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.1-preview.1.24570.5" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25078.1" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.31.0-preview" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.0.0-preview.1.25161.1" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.41.0-preview" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.1.25080.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.1.25080.5" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25161.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.1.25080.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0-preview.1.25080.5" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
{
Tools = [AIFunctionFactory.Create((string location, string unit) =>
{
// Here you would call a weather API to get the weather for the location
// Here you would call a weather API
// to get the weather for the location.
return "Periods of rain or drizzle, 15 C";
},
"get_current_weather",
Expand All @@ -31,9 +32,8 @@ You are a hiking enthusiast who helps people discover fun hikes in their area. Y

// Weather conversation relevant to the registered function.
chatHistory.Add(new ChatMessage(ChatRole.User,
"I live in Montreal and I'm looking for a moderate intensity hike. What's the current weather like? "));
"I live in Montreal and I'm looking for a moderate intensity hike. What's the current weather like?"));
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last()}");

ChatResponse response = await client.GetResponseAsync(chatHistory, chatOptions);
chatHistory.Add(new ChatMessage(ChatRole.Assistant, response.Message.Contents));
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last()}");
Console.WriteLine($"Assistant >>> {response.Text}");
2 changes: 1 addition & 1 deletion docs/ai/quickstarts/use-function-calling.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Micr
dotnet run
```

The app prints a the completion response from the AI model that includes data provided by the .NET function. The AI model understood the registered function was available and called it automatically to generate a proper response.
The app prints the completion response from the AI model that includes data provided by the .NET function. The AI model understood the registered function was available and called it automatically to generate a proper response.

:::zone target="docs" pivot="azure-openai"

Expand Down
Loading
Loading