AIHelperLibrary 0.0.1
See the version list below for details.
dotnet add package AIHelperLibrary --version 0.0.1
NuGet\Install-Package AIHelperLibrary -Version 0.0.1
<PackageReference Include="AIHelperLibrary" Version="0.0.1" />
<PackageVersion Include="AIHelperLibrary" Version="0.0.1" />
<PackageReference Include="AIHelperLibrary" />
paket add AIHelperLibrary --version 0.0.1
#r "nuget: AIHelperLibrary, 0.0.1"
#:package AIHelperLibrary@0.0.1
#addin nuget:?package=AIHelperLibrary&version=0.0.1
#tool nuget:?package=AIHelperLibrary&version=0.0.1
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-TurboandGPT-4models. - 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
- .NET 6.0 or later.
- OpenAI API Key (get one from the OpenAI Platform).
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
- GitHub Repository: AI Helper Library GitHub
- Contact: Email
ns.dev.contact@gmail.com
| Product | Versions 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. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.