![]() |
VOOZH | about |
dotnet add package SemanticKernelPooling --version 1.5.3
NuGet\Install-Package SemanticKernelPooling -Version 1.5.3
<PackageReference Include="SemanticKernelPooling" Version="1.5.3" />
<PackageVersion Include="SemanticKernelPooling" Version="1.5.3" />Directory.Packages.props
<PackageReference Include="SemanticKernelPooling" />Project file
paket add SemanticKernelPooling --version 1.5.3
#r "nuget: SemanticKernelPooling, 1.5.3"
#:package SemanticKernelPooling@1.5.3
#addin nuget:?package=SemanticKernelPooling&version=1.5.3Install as a Cake Addin
#tool nuget:?package=SemanticKernelPooling&version=1.5.3Install as a Cake Tool
SemanticKernelPooling is a .NET library designed to facilitate seamless integration with multiple AI service providers, such as OpenAI, Azure OpenAI, HuggingFace, Google, Mistral AI, and others. It utilizes a kernel pooling approach to manage resources efficiently and provide robust AI capabilities in your .NET applications.
Microsoft.Extensions.Logging for detailed logging and diagnostics.Microsoft.Extensions.DependencyInjectionMicrosoft.Extensions.LoggingMicrosoft.SemanticKernelPolly for advanced retry logicTo install SemanticKernelPooling, you can use the NuGet package manager:
dotnet add package SemanticKernelPooling
Configure Services
Start by configuring the services in your Program.cs or Startup.cs file:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SemanticKernelPooling;
using SemanticKernelPooling.Connectors.OpenAI;
var services = new ServiceCollection();
services.AddLogging(configure => configure.AddConsole());
services.UseSemanticKernelPooling(); // Core service pooling registration
services.UseOpenAIKernelPool(); // Register OpenAI kernel pool
services.UseAzureOpenAIKernelPool(); // Register Azure OpenAI kernel pool
var serviceProvider = services.BuildServiceProvider();
Configure Providers
You need to set up configuration settings for each AI service provider you intend to use. These settings can be defined in a appsettings.json or any configuration source supported by .NET:
{
"AIServiceProviderConfigurations": [
{
"UniqueName": "OpenAI",
"ServiceType": "OpenAI",
"ApiKey": "YOUR_OPENAI_API_KEY",
"ModelId": "YOUR_MODEL_ID"
},
{
"UniqueName": "AzureOpenAI",
"ServiceType": "AzureOpenAI",
"DeploymentName": "YOUR_DEPLOYMENT_NAME",
"ApiKey": "YOUR_AZURE_API_KEY",
"Endpoint": "YOUR_ENDPOINT",
"ModelId": "YOUR_MODEL_ID",
"ServiceId": "YOUR_SERVICE_ID"
}
// Add more providers as needed
]
}
Retrieve a Kernel and Execute Commands
Once the service providers are configured and registered, you can retrieve a kernel from the pool and execute commands:
var kernelPoolManager = serviceProvider.GetRequiredService<IKernelPoolManager>();
// Example: Getting a kernel for OpenAI
using var kernelWrapper = await kernelPoolManager.GetKernelAsync(AIServiceProviderType.OpenAI);
// Use the kernel to perform AI operations
var response = await kernelWrapper.Kernel.ExecuteAsync("What is Semantic Kernel?");
Console.WriteLine(response);
// Return the kernel to the pool after use
Using Retry Policies
To handle API rate limits and transient errors, use Polly to define retry policies:
AsyncPolicy httpTimeoutAndRetryPolicy = Policy
.Handle<Exception>(ex => ex.IsTransientError())
.WaitAndRetryAsync(
retryCount: 6,
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)) + TimeSpan.FromMilliseconds(new Random().Next(0, 3000)),
onRetry: (exception, timespan, retryCount, context) =>
{
logger.LogError($"Retry {retryCount} after {timespan.TotalSeconds} seconds due to: {exception.Message}");
});
Adding New AI Providers
To add support for a new AI provider, follow these steps:
Create a Configuration Class: Define a new configuration class inheriting from AIServiceProviderConfiguration.
Implement a Kernel Pool Class: Create a new kernel pool class inheriting from AIServicePool<T>.
Register the New Provider: Add the registration method in the ServiceExtension class to register your new provider with the DI container.
For example, to add a new "CustomAI" provider:
public record CustomAIConfiguration : AIServiceProviderConfiguration
{
public required string ModelId { get; init; }
public required string ApiKey { get; init; }
// Additional settings...
}
class CustomAIKernelPool(
CustomAIConfiguration config,
ILoggerFactory loggerFactory)
: AIServicePool<CustomAIConfiguration>(config)
{
protected override void RegisterChatCompletionService(IKernelBuilder kernelBuilder, CustomAIConfiguration config, HttpClient? httpClient)
{
// Register service logic...
}
protected override ILogger Logger { get; } = loggerFactory.CreateLogger<CustomAIKernelPool>();
}
public static class ServiceExtension
{
public static void UseCustomAIKernelPool(this IServiceProvider serviceProvider)
{
var registrar = serviceProvider.GetRequiredService<IKernelPoolFactoryRegistrar>();
registrar.RegisterKernelPoolFactory(
AIServiceProviderType.CustomAI,
(aiServiceProviderConfiguration, loggerFactory) =>
new CustomAIKernelPool((CustomAIConfiguration)aiServiceProviderConfiguration, loggerFactory));
}
}
OpenAIConfiguration and OpenAIKernelPool to interact with OpenAI services.AzureOpenAIConfiguration and AzureOpenAIKernelPool for Azure OpenAI.HuggingFaceConfiguration and HuggingFaceKernelPool to integrate with HuggingFace models.GoogleConfiguration and GoogleKernelPool for Google AI services.MistralAIConfiguration and MistralAIKernelPool to leverage Mistral AI services.Contributions are welcome! Please fork the repository, make your changes, and submit a pull request. Ensure your code adheres to the project's coding standards and includes appropriate tests.
This project is licensed under the MIT License. See the file for more details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 4 NuGet packages that depend on SemanticKernelPooling:
| Package | Downloads |
|---|---|
|
SemanticKernelPooling.Connectors.OpenAI
Enable SemanticKernelPooling to pool OpenAI and Azure OpenAI kenels |
|
|
SemanticKernelPooling.Connectors.Google
Enable SemanticKernelPooling to pool google AI kenels |
|
|
SemanticKernelPooling.Connectors.HuggingFace
Enable SemanticKernelPooling to pool Hugging Face AI kenels |
|
|
SemanticKernelPooling.Connectors.MistralAI
Enable SemanticKernelPooling to pool Mistarl AI kenels |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.5.3 | 16,103 | 11/12/2025 | |
| 1.5.3-rc5 | 22,941 | 5/10/2025 | |
| 1.5.3-rc4 | 56,082 | 2/2/2025 | |
| 1.5.3-rc3 | 189 | 2/2/2025 | |
| 1.5.3-rc2 | 186 | 2/2/2025 | |
| 1.5.3-rc1 | 201 | 2/2/2025 | |
| 1.5.2 | 24,130 | 10/8/2024 | |
| 1.5.1 | 419 | 10/8/2024 | |
| 1.5.0 | 7,774 | 9/3/2024 | |
| 1.3.0 | 225 | 9/3/2024 | 1.3.0 is deprecated. |
| 1.0.4 | 288 | 9/3/2024 | |
| 1.0.2 | 192 | 9/3/2024 | |
| 1.0.1 | 283 | 9/3/2024 | |
| 1.0.0 | 310 | 9/3/2024 |