Skip to content

Commit 61d6af2

Browse files
authored
Update to official MS AI package (#331)
1 parent bc2dbc3 commit 61d6af2

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

common/microsoft-extensions-ai-integration/AIPromptIntegration/AIPromptIntegration/AIPromptIntegration.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<ItemGroup>
1212
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
1313
<PackageReference Include="Azure.Core" Version="1.45.0" />
14-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.1.0-preview.1.25064.3" />
15-
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.1.0-preview.1.25064.3" />
16-
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.1.0-preview.1.25064.3" />
17-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.1.0-preview.1.25064.3" />
18-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0-preview.2.25163.2" />
14+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.*" />
15+
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.5.0-preview.1.25265.7" />
16+
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.5.0-preview.1.25265.7" />
17+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.5.0-preview.1.25265.7" />
18+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.*" />
1919
<PackageReference Include="Telerik.UI.for.Blazor" Version="*" />
2020
</ItemGroup>
2121
</Project>

common/microsoft-extensions-ai-integration/AIPromptIntegration/AIPromptIntegration/Program.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,35 @@
2828
var endpoint = builder.Configuration["Endpoint"] ?? throw new InvalidOperationException("Missing configuration: Endpoint. See the README for details.");
2929
// 🔑 The API Key for your provider
3030
var apikey = builder.Configuration["ApiKey"] ?? throw new InvalidOperationException("Missing configuration: ApiKey. See the README for details.");
31-
// 🧠 The model name or azure deployment name
31+
// 🧠 The model name or Azure deployment name
3232
var model = "YOUR_MODEL_NAME";
3333

34-
// Replace the innerClient below with your preferred model provider
35-
var innerClient = new OpenAIClient(
34+
// Use your preferred AI client below
35+
36+
// If using OpenAIClient
37+
builder.Services.AddSingleton(new OpenAIClient(
3638
new ApiKeyCredential(apikey),
3739
new OpenAIClientOptions()
3840
{
3941
Endpoint = new Uri(endpoint)
4042
}
41-
).AsChatClient(model);
43+
));
4244

43-
builder.Services.AddChatClient(innerClient) // 🤖 Add the configured chat client
45+
builder.Services.AddChatClient(services => services.GetRequiredService<OpenAIClient>().GetChatClient(model).AsIChatClient()) // 🤖 Add the configured chat client
4446
.UseFunctionInvocation() // 🛠️ Include tool calling
4547
.UseLogging(); //🐞 Include Logging
4648

49+
// OR
50+
51+
// If using AzureOpenAIClient
52+
53+
// builder.Services.AddSingleton(new AzureOpenAIClient(
54+
// new Uri(endpoint),
55+
// new AzureKeyCredential(apikey)
56+
// ));
57+
58+
// builder.Services.AddChatClient(services => services.GetRequiredService<AzureOpenAIClient>().GetChatClient(model).AsIChatClient());
59+
4760
var app = builder.Build();
4861

4962
// Configure the HTTP request pipeline.

common/microsoft-extensions-ai-integration/AIPromptIntegration/readme.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ To run the project successfully, you need to provide your endpoint and credentia
3535
var innerClient = new Azure.AI.Inference.ChatCompletionsClient(
3636
new Uri(endpoint),
3737
new AzureKeyCredential(apikey)
38-
).AsChatClient(model);
38+
);
3939
```
4040

4141
**Azure OpenAI Client registration**
@@ -45,15 +45,20 @@ var innerClient = new Azure.AI.Inference.ChatCompletionsClient(
4545
var innerClient = new AzureOpenAIClient(
4646
new Uri(endpoint),
4747
new AzureKeyCredential(apikey)
48-
).AsChatClient(model);
48+
);
4949
```
5050

5151
**OpenAI Client registration**
5252

5353
>Program.cs
5454
```csharp
55-
var innerClient = new OpenAIClient(apikey)
56-
.AsChatClient(model);
55+
var innerClient = new OpenAIClient(
56+
new ApiKeyCredential(apikey),
57+
new OpenAIClientOptions()
58+
{
59+
Endpoint = new Uri(endpoint)
60+
}
61+
);
5762
```
5863

5964
**GitHub Models Client registration**
@@ -66,7 +71,7 @@ var innerClient = new OpenAIClient(
6671
{
6772
Endpoint = new Uri(endpoint)
6873
}
69-
).AsChatClient(model);
74+
);
7075
```
7176

7277
**Ollama Client registration**

0 commit comments

Comments
 (0)