Skip to content

Commit 22390a1

Browse files
authored
Rename chat client APIs (#44970)
1 parent 6b7e950 commit 22390a1

File tree

39 files changed

+76
-79
lines changed

39 files changed

+76
-79
lines changed

docs/ai/ai-extensions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ IChatClient client =
4545
    new AzureAIInferenceChatClient(...);
4646
```
4747

48-
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:
48+
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:
4949

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

5454
Console.WriteLine(response.Message);

docs/ai/how-to/snippets/content-filtering/AIContentFiltering.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<ItemGroup>
1111
<PackageReference Include="Azure.AI.OpenAI" />
1212
<PackageReference Include="Azure.Identity" />
13-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.0.1-preview.1.24570.5" />
14-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.1-preview.1.24570.5" />
13+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
14+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
1515
</ItemGroup>
1616

1717
</Project>

docs/ai/how-to/snippets/content-filtering/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
try
1111
{
12-
ChatCompletion completion = await client.CompleteAsync("YOUR_PROMPT");
12+
ChatResponse completion = await client.GetResponseAsync("YOUR_PROMPT");
1313

1414
Console.WriteLine(completion.Message);
15-
}
16-
catch (Exception e)
15+
}
16+
catch (Exception e)
1717
{
1818
Console.WriteLine(e.Message);
1919
}

docs/ai/how-to/snippets/hosted-app-auth/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
app.MapGet("/test-prompt", async (IChatClient chatClient) =>
4242
{
43-
return await chatClient.CompleteAsync("Test prompt", new ChatOptions());
43+
return await chatClient.GetResponseAsync("Test prompt", new ChatOptions());
4444
})
4545
.WithName("Test prompt");
4646

docs/ai/how-to/snippets/hosted-app-auth/hosted-app-auth.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
1212
<PackageReference Include="Azure.Identity" Version="1.13.2" />
1313
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.2" />
14-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.1.0-preview.1.25064.3" />
15-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.1.0-preview.1.25064.3" />
16-
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.9.0" />
14+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
15+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
16+
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.10.0" />
1717
</ItemGroup>
1818

1919
</Project>

docs/ai/quickstarts/snippets/build-chat-app/azure-openai/ChatAppAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ItemGroup>
1212
<PackageReference Include="Azure.Identity" Version="1.13.2" />
1313
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
14-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24556.5" />
14+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
1515
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.2" />
1616
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
1717

docs/ai/quickstarts/snippets/build-chat-app/azure-openai/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ the local nature on the hikes when making a recommendation. At the end of your
4141
Console.WriteLine("AI Response:");
4242
var response = "";
4343
await foreach (var item in
44-
chatClient.CompleteStreamingAsync(chatHistory))
44+
chatClient.GetStreamingResponseAsync(chatHistory))
4545
{
4646
Console.Write(item.Text);
4747
response += item.Text;

docs/ai/quickstarts/snippets/build-chat-app/openai/ExtensionsOpenAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24556.5" />
11+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
1212
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.2" />
1313
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
1414
</ItemGroup>

docs/ai/quickstarts/snippets/build-chat-app/openai/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ the local nature on the hikes when making a recommendation. At the end of your
4040
Console.WriteLine("AI Response:");
4141
var response = "";
4242
await foreach (var item in
43-
chatClient.CompleteStreamingAsync(chatHistory))
43+
chatClient.GetStreamingResponseAsync(chatHistory))
4444
{
4545
Console.Write(item.Text);
4646
response += item.Text;

docs/ai/quickstarts/snippets/function-calling/openai/FunctionCallingAI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.0.0-preview.9.24556.5" />
12-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24556.5" />
11+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
12+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
1313
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.2" />
1414
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
1515
</ItemGroup>

docs/ai/quickstarts/snippets/function-calling/openai/Program.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
using Microsoft.Extensions.Configuration;
33
using OpenAI;
44

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

99
IChatClient client =
10-
new ChatClientBuilder()
11-
.UseFunctionInvocation()
12-
.Use(
13-
new OpenAIClient(key)
14-
.AsChatClient(model));
10+
new ChatClientBuilder(new OpenAIClient(key).AsChatClient(model ?? "gpt-4o"))
11+
.UseFunctionInvocation()
12+
.Build();
1513

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

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

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

38-
var response = await client.CompleteAsync(chatHistory, chatOptions);
37+
ChatResponse response = await client.GetResponseAsync(chatHistory, chatOptions);
3938
chatHistory.Add(new ChatMessage(ChatRole.Assistant, response.Message.Contents));
4039
Console.WriteLine($"{chatHistory.Last().Role} >>> {chatHistory.Last()}");

docs/ai/quickstarts/snippets/local-ai/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.Extensions.AI;
22

3-
IChatClient chatClient =
3+
IChatClient chatClient =
44
new OllamaChatClient(new Uri("http://localhost:11434/"), "phi3:mini");
55

66
// Start the conversation with context for the AI model
@@ -17,11 +17,11 @@
1717
Console.WriteLine("AI Response:");
1818
var response = "";
1919
await foreach (var item in
20-
chatClient.CompleteStreamingAsync(chatHistory))
20+
chatClient.GetStreamingResponseAsync(chatHistory))
2121
{
2222
Console.Write(item.Text);
2323
response += item.Text;
2424
}
2525
chatHistory.Add(new ChatMessage(ChatRole.Assistant, response));
2626
Console.WriteLine();
27-
}
27+
}

docs/ai/quickstarts/snippets/local-ai/ollama.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

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

1414
</Project>

docs/ai/quickstarts/snippets/prompt-completion/azure-openai/ExtensionsAzureOpenAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<ItemGroup>
1111
<PackageReference Include="Azure.Identity" Version="1.13.2" />
1212
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
13-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24556.5" />
13+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
1414
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.2" />
1515
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
1616

docs/ai/quickstarts/snippets/prompt-completion/azure-openai/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
Console.WriteLine($"user >>> {prompt}");
2121

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

docs/ai/quickstarts/snippets/prompt-completion/openai/ExtensionsOpenAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24556.5" />
11+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
1212
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.2" />
1313
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.2" />
1414
</ItemGroup>

docs/ai/quickstarts/snippets/prompt-completion/openai/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
using Microsoft.Extensions.Configuration;
33
using OpenAI;
44

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

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

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

0 commit comments

Comments
 (0)