WK.OpenAiWrapper 2.0.11

There is a newer version of this package available.
See the version list below for details.
dotnet add package WK.OpenAiWrapper --version 2.0.11
NuGet\Install-Package WK.OpenAiWrapper -Version 2.0.11
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WK.OpenAiWrapper" Version="2.0.11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WK.OpenAiWrapper --version 2.0.11
#r "nuget: WK.OpenAiWrapper, 2.0.11"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WK.OpenAiWrapper as a Cake Addin
#addin nuget:?package=WK.OpenAiWrapper&version=2.0.11

// Install WK.OpenAiWrapper as a Cake Tool
#tool nuget:?package=WK.OpenAiWrapper&version=2.0.11

OpenAiWrapper - A .NET Library for OpenAI API Integration

OpenAiWrapper is a user-friendly .NET library designed to simplify the integration and utilization of the OpenAI API in .NET applications. This library acts as a wrapper around the OpenAI-DotNet package by RageAgainstThePixel, streamlining API interactions and enhancing usability, particularly for managing AI workflows and threads.

Features

  • ๐Ÿ›  Easy Configuration: Simplify the setup process with extension methods for IServiceCollection.
  • ๐Ÿค– Enhanced AI Operations: Utilize various OpenAI models efficiently within your .NET applications.
  • ๐Ÿงต Thread Management: Manage threads for continuous conversations or data tracking.
  • ๐Ÿš€ Advanced Pilot Management: Configure and use different pilots with specific capabilities and tools.
  • ๐Ÿ“ Support for Multiple AI Features: Get text, image, and audio responses easily.

Installation

To start using OpenAiWrapper, add the package to your .NET project using NuGet:

dotnet add package OpenAiWrapper

Configuration

Setup in Startup.cs or Program.cs

public void ConfigureServices(IServiceCollection services)
{
    var configuration = new ConfigurationBuilder()
        .AddJsonFile("appsettings.json")
        .Build();

    // Register OpenAI services with API key and optional pilots
    services.RegisterOpenAi("your_openai_api_key_here", new Pilot("default", "Default Pilot Instructions"));
}

Usage Examples

Getting AI Responses

public async Task<string> GetResponseFromOpenAi(string userInput)
{
    var client = serviceProvider.GetService<IOpenAiClient>();
    var response = await client.GetOpenAiResponseWithNewThread(userInput, "default", "user1");

    if (response.IsSuccess)
    {
        return response.Value.Answer;
    }
    else
    {
        throw new Exception("Failed to get response from OpenAI");
    }
}

Working with Images

public async Task<string> GetImageUrlFromOpenAi(string prompt)
{
    var client = serviceProvider.GetService<IOpenAiClient>();
    var response = await client.GetOpenAiImageResponse(prompt);

    if (response.IsSuccess)
    {
        return response.Value.Url;
    }
    else
    {
        throw new Exception("Failed to generate image from OpenAI");
    }
}

Advanced Configuration

Defining Pilots

Pilots can be defined with specific tools and models to tailor the AI responses according to the application's needs.

var advancedPilot = new Pilot("advanced", "Provide detailed analysis", "gpt-4-turbo")
{
    Tools = new List<Tool>
    {
        new Tool("AnalysisTool", "Detailed Analysis")
    }
};

services.RegisterOpenAi("your_openai_api_key_here", advancedPilot);

Contribution

Contributions are welcome! If you would like to improve the OpenAiWrapper, feel free to fork the repository and submit a pull request.

About Us

Werbas continues to innovate and improve upon tools and technologies that enhance your experience with artificial intelligence. Visit us at www.werbas.com to learn more about our contributions to the tech community and how we can help you achieve your business goals.

License

OpenAiWrapper is released under the MIT License. See the LICENSE file for more information.


Enjoy building with OpenAiWrapper, and unleash the power of AI in your .NET applications seamlessly! ๐Ÿš€โœจ

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.15 49 5/31/2024
2.0.14 69 5/29/2024
2.0.13 90 5/15/2024
2.0.12 70 5/15/2024
2.0.11 90 5/8/2024
2.0.10 50 5/2/2024
2.0.9 81 4/27/2024
2.0.8 78 4/27/2024
2.0.7 73 4/26/2024
2.0.6 93 4/24/2024
2.0.5 87 4/21/2024
2.0.4 82 4/21/2024
2.0.3 98 4/21/2024
2.0.2 97 4/20/2024
2.0.1 112 4/20/2024
2.0.0 102 4/20/2024
1.0.0 111 4/12/2024
0.1.0 108 4/12/2024