CodedByKay.SmartDialogue.Assistants
1.0.0-alpha
See the version list below for details.
dotnet add package CodedByKay.SmartDialogue.Assistants --version 1.0.0-alpha
NuGet\Install-Package CodedByKay.SmartDialogue.Assistants -Version 1.0.0-alpha
<PackageReference Include="CodedByKay.SmartDialogue.Assistants" Version="1.0.0-alpha" />
paket add CodedByKay.SmartDialogue.Assistants --version 1.0.0-alpha
#r "nuget: CodedByKay.SmartDialogue.Assistants, 1.0.0-alpha"
// Install CodedByKay.SmartDialogue.Assistants as a Cake Addin #addin nuget:?package=CodedByKay.SmartDialogue.Assistants&version=1.0.0-alpha&prerelease // Install CodedByKay.SmartDialogue.Assistants as a Cake Tool #tool nuget:?package=CodedByKay.SmartDialogue.Assistants&version=1.0.0-alpha&prerelease
CodedByKay.SmartDialogue.Assistant Setup Guide
Overview
This project offers a comprehensive solution for integrating smart dialogue assistants and chat history management into .NET applications. Designed with modularity and extensibility in mind, it lays the groundwork for developers to create rich, interactive chat applications that can engage users with AI-powered conversations while maintaining an accessible history of these interactions.
At the heart of the project are four key components:
- ChatHistoryService: Manages the storage and retrieval of chat conversations, providing a seamless experience for users to access their chat histories.
- SmartDialogueAssistantsService: Powers the integration of AI-driven dialogue assistants, enhancing user interactions with smart, context-aware responses.
- CodedByKaySmartDialogueAssistantsExtensions: Offers extension methods to simplify the integration and management of dialogue assistants within the application, emphasizing ease of use and developer productivity.
- SmartDialogueServiceFactory: Implements the factory pattern to efficiently manage the creation and lifecycle of smart dialogue service instances, ensuring scalability and maintainability.
Core Features
- Middleware Integration: Easily integrates into the middleware pipeline of a .NET web application.
- Asynchronous Communication: Communicates asynchronously with the OpenAI Assistant API.
- Secure API Key Management: Offers a secure way to manage and use your OpenAI API key.
- Chat History Management: Utilizes a
ConcurrentDictionary
for efficient and thread-safe chat history management.
OpenAI API Communication
- Send Messages: Allows sending messages to the OpenAI Assistant API.
- Receive and Forward Responses: Receives responses from OpenAI and forwards them to the library user.
- Maintain Chat History: Keeps a record of the chat history that can be utilized in subsequent API requests for context.
Setup and Configuration
Prerequisites
- .NET Core 3.1 SDK or later.
- An OpenAI API key.
Installation
To install CodedByKay.SmartDialogue.Assistants
, add it to your project via NuGet Package Manager or using the .NET CLI:
dotnet add package CodedByKay.SmartDialogue.Assistants
Configuration in Startup.cs
Incorporate CodedByKay.SmartDialogue.Assistants into your project's Startup.cs file to begin using its functionalities.
Register SmartDialogue Services
Then, add CodedByKay.SmartDialogue.Assistants
to your service collection:
public void ConfigureServices(IServiceCollection services)
{
services.AddSmartDialogueAssistants(options =>
{
// All values are default for the CodedByKay.SmartDialogue.Assistants library
options.OpenAiApiKey = "your_openai_api_key_here";
options.OpenAIAssistantId = "assistant_id";
options.OpenAIApiUrl = "https://api.openai.com/v1/";
options.MaxTokens = 2000;
options.AverageTokeLenght = 2.85;
});
}
Usage
Inject ISmartDialogueAssistantsService into your controllers or services to utilize the library:
using Microsoft.AspNetCore.Mvc;
public class ChatController : ControllerBase
{
private readonly ISmartDialogueAssistantsService _smartDialogueAssistantsService;
public ChatController(ISmartDialogueServiceFactory smartDialogueServiceFactory)
{
_smartDialogueAssistantsService = smartDialogueServiceFactory.Create();
}
[HttpPost("send")]
public async Task<IActionResult> SendMessage([FromBody] ChatRequest request)
{
if (request == null || string.IsNullOrWhiteSpace(request.Message))
{
return BadRequest("Message is required.");
}
try
{
var response = await _smartDialogueAssistantsService.SendMessageAsync(request.SessionId, request.Message);
return Ok(new { Response = response });
}
catch (Exception ex)
{
// Log the exception details
return StatusCode(500, "An error occurred while processing your request.");
}
}
}
Conclusion
With CodedByKay.SmartDialogue.Assistants, you can enhance your .NET web applications by integrating sophisticated chat functionalities powered by the OpenAI Assistant API. Follow this guide to set up and start leveraging this powerful library in your projects.
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. |
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.1)
- 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.
Version | Downloads | Last updated |
---|---|---|
1.0.4-alpha | 73 | 2/12/2024 |
1.0.3-alpha | 72 | 2/11/2024 |
1.0.2-alpha | 56 | 2/10/2024 |
1.0.1-alpha | 54 | 2/10/2024 |
1.0.0-alpha | 62 | 2/9/2024 |