AIHelperLibrary 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package AIHelperLibrary --version 0.0.1
                    
NuGet\Install-Package AIHelperLibrary -Version 0.0.1
                    
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="AIHelperLibrary" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AIHelperLibrary" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="AIHelperLibrary" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AIHelperLibrary --version 0.0.1
                    
#r "nuget: AIHelperLibrary, 0.0.1"
                    
#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.
#:package AIHelperLibrary@0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AIHelperLibrary&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=AIHelperLibrary&version=0.0.1
                    
Install as a Cake Tool

AI Helper Library

Overview

The AI Helper Library is a modular and reusable C# library designed for seamless interaction with OpenAI's API. With features like prompt management, multi-turn chatbot functionality, and persistent session support, this library simplifies the integration of AI-driven solutions into .NET applications.


Features

  • AI Model Support: Compatible with OpenAI's GPT-3.5-Turbo and GPT-4 models.
  • Predefined Prompts: Built-in templates for tasks like summarization and Q&A.
  • Dynamic Prompts: Create, store, and reuse custom prompts programmatically.
  • Persistent Conversations: Context-aware chatbot sessions with configurable history limits.
  • Highly Configurable: Adjust token limits, temperature, and logging via simple configuration.
  • Error Handling: Validates inputs and gracefully manages API errors.

Installation

Install the package via NuGet:

.NET CLI

dotnet add package AIHelperLibrary

Package Manager

Install-Package AIHelperLibrary

Quick Start

1. Configuration

Set up the library with your OpenAI API key and configuration options:

using AIHelperLibrary.Configurations;
using AIHelperLibrary.Services;

var config = new AIExtensionHelperConfiguration
{
    DefaultModel = AIModel.GPT_3_5_Turbo,
    MaxTokens = 200,
    Temperature = 0.7,
    TopP = 1.0,
    RequestTimeoutMs = 10000,
    EnableLogging = true,
    MaxChatHistorySize = 10
};

var client = new OpenAIClient("your-api-key", config);

2. Generate AI Responses

Freeform Prompt

Send a custom prompt to OpenAI:

var response = await client.GenerateTextAsync("Explain quantum computing in simple terms.");
Console.WriteLine(response);
Predefined Prompt

Use built-in templates like summarization:

var result = await client.GenerateTextWithPredefinedPromptAsync("Summarize the following text:", "Artificial intelligence is revolutionizing industries...");
Console.WriteLine(result);
Dynamic Prompts

Create and reuse custom prompts:

var promptManager = new DynamicPromptManager();
promptManager.AddPrompt("WelcomeMessage", "Greet the user warmly.");

var response = await client.GenerateTextWithDynamicPromptAsync(promptManager, "WelcomeMessage", "Hello!");
Console.WriteLine(response);
Persistent Chatbot Conversations

Maintain context across multiple messages:

var chatResponse = await client.GenerateChatResponseAsync(
    "SupportBot",
    "What are your working hours?",
    "You are a polite customer service assistant."
);
Console.WriteLine(chatResponse);

Configuration Options

The AIExtensionHelperConfiguration class allows for extensive customization:

Property Description Default Value
DefaultModel AI model to use (GPT-3.5-Turbo, GPT-4). GPT-3.5-Turbo
MaxTokens Maximum tokens for each response. 150
Temperature Controls randomness (0.0 = deterministic). 0.7
TopP Sampling parameter for diversity. 1.0
RequestTimeoutMs API request timeout in milliseconds. 10000 (10 seconds)
EnableLogging Enable or disable logging. false
MaxChatHistorySize Limit on retained chat messages. 10

Requirements


Future Enhancements

  • Retry logic for API calls with backoff.
  • Enhanced error messages for better debugging.
  • Support for additional AI models (e.g., Azure OpenAI).
  • Community-driven feature suggestions.

Support

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
1.1.0 239 4/27/2025
1.0.1 161 2/2/2025
1.0.0 135 1/19/2025
0.0.1 131 1/17/2025