Skip to content

Update to official MS AI package #331

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -11,11 +11,11 @@
<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Azure.Core" Version="1.45.0" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.1.0-preview.1.25064.3" />
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.1.0-preview.1.25064.3" />
<PackageReference Include="Microsoft.Extensions.AI.Ollama" 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.DependencyInjection" Version="10.0.0-preview.2.25163.2" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.*" />
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.5.0-preview.1.25265.7" />
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.5.0-preview.1.25265.7" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.5.0-preview.1.25265.7" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.*" />
<PackageReference Include="Telerik.UI.for.Blazor" Version="*" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,35 @@
var endpoint = builder.Configuration["Endpoint"] ?? throw new InvalidOperationException("Missing configuration: Endpoint. See the README for details.");
// 🔑 The API Key for your provider
var apikey = builder.Configuration["ApiKey"] ?? throw new InvalidOperationException("Missing configuration: ApiKey. See the README for details.");
// 🧠 The model name or azure deployment name
// 🧠 The model name or Azure deployment name
var model = "YOUR_MODEL_NAME";

// Replace the innerClient below with your preferred model provider
var innerClient = new OpenAIClient(
// Use your preferred AI client below

// If using OpenAIClient
builder.Services.AddSingleton(new OpenAIClient(
new ApiKeyCredential(apikey),
new OpenAIClientOptions()
{
Endpoint = new Uri(endpoint)
}
).AsChatClient(model);
));

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

// OR

// If using AzureOpenAIClient

// builder.Services.AddSingleton(new AzureOpenAIClient(
// new Uri(endpoint),
// new AzureKeyCredential(apikey)
// ));

// builder.Services.AddChatClient(services => services.GetRequiredService<AzureOpenAIClient>().GetChatClient(model).AsIChatClient());

var app = builder.Build();

// Configure the HTTP request pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To run the project successfully, you need to provide your endpoint and credentia
var innerClient = new Azure.AI.Inference.ChatCompletionsClient(
new Uri(endpoint),
new AzureKeyCredential(apikey)
).AsChatClient(model);
);
```

**Azure OpenAI Client registration**
Expand All @@ -45,15 +45,20 @@ var innerClient = new Azure.AI.Inference.ChatCompletionsClient(
var innerClient = new AzureOpenAIClient(
new Uri(endpoint),
new AzureKeyCredential(apikey)
).AsChatClient(model);
);
```

**OpenAI Client registration**

>Program.cs
```csharp
var innerClient = new OpenAIClient(apikey)
.AsChatClient(model);
var innerClient = new OpenAIClient(
new ApiKeyCredential(apikey),
new OpenAIClientOptions()
{
Endpoint = new Uri(endpoint)
}
);
```

**GitHub Models Client registration**
Expand All @@ -66,7 +71,7 @@ var innerClient = new OpenAIClient(
{
Endpoint = new Uri(endpoint)
}
).AsChatClient(model);
);
```

**Ollama Client registration**
Expand Down