Skip to content

Merge main into live #44997

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 8 commits into from
Feb 22, 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
4 changes: 2 additions & 2 deletions docs/ai/ai-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ IChatClient client =
    new AzureAIInferenceChatClient(...);
```

Then, regardless of the provider you're using, you can send requests by calling <xref:Microsoft.Extensions.AI.IChatClient.CompleteAsync(System.Collections.Generic.IList{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatOptions,System.Threading.CancellationToken)>, as follows:
Then, regardless of the provider you're using, you can send requests by calling <xref:Microsoft.Extensions.AI.IChatClient.GetResponseAsync(System.Collections.Generic.IList{Microsoft.Extensions.AI.ChatMessage},Microsoft.Extensions.AI.ChatOptions,System.Threading.CancellationToken)>, as follows:

```csharp
var response = await chatClient.CompleteAsync(
var response = await chatClient.GetResponseAsync(
      "Translate the following text into Pig Latin: I love .NET and AI");

Console.WriteLine(response.Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.0.1-preview.1.24570.5" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.1-preview.1.24570.5" />
<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" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions docs/ai/how-to/snippets/content-filtering/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

try
{
ChatCompletion completion = await client.CompleteAsync("YOUR_PROMPT");
ChatResponse completion = await client.GetResponseAsync("YOUR_PROMPT");

Console.WriteLine(completion.Message);
}
catch (Exception e)
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
2 changes: 1 addition & 1 deletion docs/ai/how-to/snippets/hosted-app-auth/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

app.MapGet("/test-prompt", async (IChatClient chatClient) =>
{
return await chatClient.CompleteAsync("Test prompt", new ChatOptions());
return await chatClient.GetResponseAsync("Test prompt", new ChatOptions());
})
.WithName("Test prompt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Azure.Identity" Version="1.13.2" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.1.0-preview.1.25064.3" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.1.0-preview.1.25064.3" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.9.0" />
<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.Azure" Version="1.10.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<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.0-preview.9.24556.5" />
<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" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ the local nature on the hikes when making a recommendation. At the end of your
Console.WriteLine("AI Response:");
var response = "";
await foreach (var item in
chatClient.CompleteStreamingAsync(chatHistory))
chatClient.GetStreamingResponseAsync(chatHistory))
{
Console.Write(item.Text);
response += item.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24556.5" />
<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" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ the local nature on the hikes when making a recommendation. At the end of your
Console.WriteLine("AI Response:");
var response = "";
await foreach (var item in
chatClient.CompleteStreamingAsync(chatHistory))
chatClient.GetStreamingResponseAsync(chatHistory))
{
Console.Write(item.Text);
response += item.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI" Version="9.0.0-preview.9.24556.5" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24556.5" />
<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" />
</ItemGroup>
Expand Down
23 changes: 11 additions & 12 deletions docs/ai/quickstarts/snippets/function-calling/openai/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
using Microsoft.Extensions.Configuration;
using OpenAI;

var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
string model = config["ModelName"];
string key = config["OpenAIKey"];
IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
string? model = config["ModelName"];
string? key = config["OpenAIKey"];

IChatClient client =
new ChatClientBuilder()
.UseFunctionInvocation()
.Use(
new OpenAIClient(key)
.AsChatClient(model));
new ChatClientBuilder(new OpenAIClient(key).AsChatClient(model ?? "gpt-4o"))
.UseFunctionInvocation()
.Build();

// Add a new plugin with a local .NET function that should be available to the AI model
// Add a new plugin with a local .NET function
// that should be available to the AI model.
var chatOptions = new ChatOptions
{
Tools = [AIFunctionFactory.Create((string location, string unit) =>
Expand All @@ -25,16 +24,16 @@
"Get the current weather in a given location")]
};

// System prompt to provide context
// System prompt to provide context.
List<ChatMessage> chatHistory = [new(ChatRole.System, """
You are a hiking enthusiast who helps people discover fun hikes in their area. You are upbeat and friendly.
""")];

// Weather conversation relevant to the registered function
// 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? "));
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last()}");

var response = await client.CompleteAsync(chatHistory, chatOptions);
ChatResponse response = await client.GetResponseAsync(chatHistory, chatOptions);
chatHistory.Add(new ChatMessage(ChatRole.Assistant, response.Message.Contents));
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last()}");
6 changes: 3 additions & 3 deletions docs/ai/quickstarts/snippets/local-ai/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.AI;

IChatClient chatClient =
IChatClient chatClient =
new OllamaChatClient(new Uri("http://localhost:11434/"), "phi3:mini");

// Start the conversation with context for the AI model
Expand All @@ -17,11 +17,11 @@
Console.WriteLine("AI Response:");
var response = "";
await foreach (var item in
chatClient.CompleteStreamingAsync(chatHistory))
chatClient.GetStreamingResponseAsync(chatHistory))
{
Console.Write(item.Text);
response += item.Text;
}
chatHistory.Add(new ChatMessage(ChatRole.Assistant, response));
Console.WriteLine();
}
}
2 changes: 1 addition & 1 deletion docs/ai/quickstarts/snippets/local-ai/ollama.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.0.1-preview.1.24570.5" />
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.3.0-preview.1.25114.11" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<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.0-preview.9.24556.5" />
<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" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
Console.WriteLine($"user >>> {prompt}");

// Submit the prompt and print out the response
ChatCompletion response = await client.CompleteAsync(prompt, new ChatOptions { MaxOutputTokens = 400 });
ChatResponse response = await client.GetResponseAsync(prompt, new ChatOptions { MaxOutputTokens = 400 });
Console.WriteLine($"assistant >>> {response}");
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24556.5" />
<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" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Microsoft.Extensions.Configuration;
using OpenAI;

var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
string model = config["ModelName"];
string key = config["OpenAIKey"];
IConfigurationRoot config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
string? model = config["ModelName"];
string? key = config["OpenAIKey"];

// Create the IChatClient
IChatClient client =
Expand All @@ -19,5 +19,5 @@
Console.WriteLine($"user >>> {prompt}");

// Submit the prompt and print out the response
ChatCompletion response = await client.CompleteAsync(prompt, new ChatOptions { MaxOutputTokens = 400 });
ChatResponse response = await client.GetResponseAsync(prompt, new ChatOptions { MaxOutputTokens = 400 });
Console.WriteLine($"assistant >>> {response}");
Loading
Loading