Boundless.OmniAdapter
1.0.4-alpha
dotnet add package Boundless.OmniAdapter --version 1.0.4-alpha
NuGet\Install-Package Boundless.OmniAdapter -Version 1.0.4-alpha
<PackageReference Include="Boundless.OmniAdapter" Version="1.0.4-alpha" />
paket add Boundless.OmniAdapter --version 1.0.4-alpha
#r "nuget: Boundless.OmniAdapter, 1.0.4-alpha"
// Install Boundless.OmniAdapter as a Cake Addin #addin nuget:?package=Boundless.OmniAdapter&version=1.0.4-alpha&prerelease // Install Boundless.OmniAdapter as a Cake Tool #tool nuget:?package=Boundless.OmniAdapter&version=1.0.4-alpha&prerelease
OmniAdapter
Overview
OmniAdapter is a versatile set of interfaces that supports seamless integration with various AI providers across multiple modalities, including text, audio, and images to normalize their differences.
Table of Contents
- Overview
- Features
- Installation
- Configuration
- Usage
- Dependencies
- Resilience
- FAQ
- License
- Contributing
- ToDo
Features
The main features of this package are the clients for the various providers and normalization to a common set of interfaces.
Interfaces
- IChatCompletion
- IChatStream
- IAudioCompletion
- IImageCompletion
Clients
- AmazonQ
- Anthropic
- AzureAI
- Gemini
- Groq
- OpenAI
- Perplexity
- ElevenLabs
- Leonardo
⚠️ AmazonQ, ElevenLabs, Leonardo are still in active devlopement.
Installation
To install OmniAdapter, you need to add the package to your .NET project. You can do this using the .NET CLI or by adding it directly to your project file.
dotnet add package Boundless.OmniAdapter
Configuration
OmniAdapter supports configuration for various AI provider clients. You can configure these settings in your application's configuration files (e.g., appsettings.json
) or through environment variables.
Example Configuration in appsettings.json
{
"AnthropicSettings": {
"AnthropicApiKey": "your-anthropic-api-key"
},
"AzureAiSettings": {
"AzureAiApiKey": "your-azure-ai-api-key",
"AzureAiEndpoint": "your-azure-ai-endpoint",
"AzureAiDeployment": "your-azure-ai-deployment"
},
"GeminiSettings": {
"GeminiApiKey": "your-gemini-api-key"
},
"GroqSettings": {
"GroqApiKey": "your-groq-api-key"
},
"OpenAiSettings": {
"OpenAiApiKey": "your-openai-api-key",
"OpenAiOrganization": "your-openai-organization",
"OpenAiProject": "your-openai-project"
},
"PerplexitySettings": {
"PerplexityApiKey": "your-perplexity-api-key"
}
}
Usage
Setup
To use OmniAdapter in your .NET project, follow these steps to set up and configure the various clients and interfaces.
- Create a new .NET project or open an existing one.
- Install the OmniAdapter package as described in the Installation section.
- Configure the services in your
Program.cs
public class Program
{
static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
var configuration = hostContext.Configuration;
services.Configure<OpenAiSettings>(configuration.GetSection("OpenAiSettings"));
services.AddOpenAiClient();
});
}
These extention methods will Validate the correct settings are aviable on startup, add a keyed singleton for the client and its implemented interfaces, and a keyed http client.
❗ Each key is unique to the provider's name.
Functions
There is a build in method within the function class to create a Function object from a .Net Delegate using refelection.
🚨 The Delegate meet the following condtions:
- The name is lifted from the method name but must match the regex
^[a-zA-Z0-9_-]{1,64}$
.- The the functions description comes from the [Description] Attribute on the method.
- must single paramter. That paramter is automaticly converted into a schema for the .Net type useing the JsonSchema.Net.
Function.CreateFrom<T>(T action) where T : Delegate
Function.CreateFrom<T>(string name, string description, T action) where T : Delegate
🆕 The OmniKernel is desinged to handle function binding, upon other considerations.
Dependencies
A list of dependencies and prerequisites for running OmniAdapter.
JsonSchema.Net Tools for parsing, generating, and validating JSON Schemas within .NET applications.
System.Net.Http.Json Extension methods for HttpClient and HttpContent that enable automatic serialization and deserialization using System.Text.Json.
Microsoft.Extensions.Http Features for working with HTTP services in a structured way. Integrates with the Dependency Injection (DI) framework in ASP.NET Core for easier configuration and usage of HttpClient instances.
Microsoft.Extensions.Options.DataAnnotations Validates options using data annotations within the options pattern in ASP.NET Core. Supports attributes like [Required], [Range], [StringLength], etc., for validating configuration properties.
Resilience
Resilience mechanisms for HttpClient built on the Polly framework via the Microsoft.Extensions.Http.Resilience
package.
When configuring an HttpClient through the HTTP client factory, the following extensions can add pre-configured hedging or resilience behaviors. These pipelines combine multiple resilience strategies with default settings.
- Total Request Timeout Pipeline: Ensures the request, including hedging attempts, does not exceed the configured time limit.
- Retry Pipeline: Retries the request if the dependency is slow or returns a transient error.
- Rate Limiter Pipeline: Limits the maximum number of requests sent to the dependency.
- Circuit Breaker: Blocks execution if too many direct failures or timeouts are detected.
- Attempt Timeout Pipeline: Limits each request attempt duration and throws an exception if it exceeds the limit.
.ConfigureServices((hostContext, services) =>
{
services.AddOpenAiClient().AddStandardResilienceHandler();
});
FAQ
What is the purpose of the IChatCompletion, IChatStream, IAudioCompletion, and IImageCompletion interfaces? These interfaces provide a standardized way to interact with different AI providers across various modalities (text, audio, images). They ensure that you can switch between providers without changing the core logic of your application.
How does OmniAdapter handle API rate limits and errors from different AI providers? OmniAdapter expose the http client for you to add any resilience strategies such as retry mechanisms, rate limiting, circuit breakers, and total request timeouts to handle API rate limits and errors. These strategies ensure that your application remains stable and responsive even when facing issues with the AI providers.
Can I use OmniAdapter in a non-.NET project? OmniAdapter is designed specifically for .NET projects. If you are using a different technology stack, you would need to look for or develop a similar adapter that integrates with the AI providers you need.
How do I add a new AI provider client to OmniAdapter? To add a new AI provider client, you would need to create a new client class that implements the relevant interfaces (e.g., IChatCompletion, IAudioCompletion). You would also need to update the configuration and registration process to include this new client.
What kind of logging and monitoring does OmniAdapter support? OmniAdapter can integrate with standard .NET logging and monitoring frameworks. You can configure logging and monitoring in your application to track the performance and usage of the AI clients.
Is there a way to mock or simulate AI provider responses for testing purposes? Yes, you can create mock implementations of the interfaces provided by OmniAdapter (e.g., IChatCompletion, IAudioCompletion) to simulate AI provider responses. This allows you to test your application's logic without making actual API calls.
How do I handle authentication for different AI providers in OmniAdapter? Authentication for different AI providers is handled through configuration settings. Each provider requires specific API keys or credentials, which you can set in your configuration files or environment variables.
Can I use OmniAdapter for real-time applications? Yes, OmniAdapter supports real-time applications, especially with the IChatStream interface for streaming text responses. Ensure that you configure the resilience strategies properly to handle the demands of real-time processing.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Follow the Contributing for guidelines for contributing to the project, including code style and submission process.
Looking for a place to start? Check the list below or any issues labled with good first issue
ToDo
- Merge the Azure ContentFilter into the FinishReason.ContentFilter
- Logging
- Add Client for AmazonQ
- Add Client for Elevenlabs
- Add Client for Leonardo
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- JsonSchema.Net (>= 7.0.2)
- JsonSchema.Net.Generation (>= 4.3.0.2)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 8.0.0)
- System.Net.Http.Json (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.4-alpha | 72 | 5/21/2024 |