CodedByKay.SmartDialogue 1.0.5-alpha

This is a prerelease version of CodedByKay.SmartDialogue.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package CodedByKay.SmartDialogue --version 1.0.5-alpha
NuGet\Install-Package CodedByKay.SmartDialogue -Version 1.0.5-alpha
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="CodedByKay.SmartDialogue" Version="1.0.5-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CodedByKay.SmartDialogue --version 1.0.5-alpha
#r "nuget: CodedByKay.SmartDialogue, 1.0.5-alpha"
#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 CodedByKay.SmartDialogue as a Cake Addin
#addin nuget:?package=CodedByKay.SmartDialogue&version=1.0.5-alpha&prerelease

// Install CodedByKay.SmartDialogue as a Cake Tool
#tool nuget:?package=CodedByKay.SmartDialogue&version=1.0.5-alpha&prerelease

CodedByKay.SmartDialogue Setup Guide

Overview

CodedByKay.SmartDialogue is a .NET class library designed to facilitate easy communication with the OpenAI Assistant API, integrating seamlessly into .NET web applications. It supports sending messages, receiving responses, and maintaining a chat history.

Features

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, add it to your project via NuGet Package Manager or using the .NET CLI:

dotnet add package CodedByKay.SmartDialogue

Configuration in Startup.cs

Incorporate CodedByKay.SmartDialogue into your project's Startup.cs file to begin using its functionalities.

Register SmartDialogue Services Then, add CodedByKay.SmartDialogue to your service collection:

public void ConfigureServices(IServiceCollection services)
{
    services.AddSmartDialogue(options =>
    {
        // All values are default for the AddSmartDialogue library
        options.OpenAiApiKey = "your_openai_api_key_here";
        options.Model = "gpt-3.5-turbo";
        options.OpenAIApiUrl = "https://api.openai.com";
        options.MaxTokens = 2000;
        options.Temperature = 1;
        options.TopP = 1;
        options.AverageTokeLenght = 2.85;
    });
}

Usage

Inject ISmartDialogueService into your controllers or services to utilize the library:

using Microsoft.AspNetCore.Mvc;

public class ChatController : ControllerBase
{
    private readonly ISmartDialogueService _smartDialogueService;

    public ChatController(ISmartDialogueServiceFactory smartDialogueServiceFactory)
    {
        _smartDialogueService = 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 _smartDialogueService.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.");
        }
    }
}

public class ChatRequest
{
    public string SessionId { get; set; }
    public string Message { get; set; }
}

Conclusion

With CodedByKay.SmartDialogue, 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 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
1.0.14-alpha 62 2/10/2024
1.0.13-alpha 45 2/10/2024
1.0.12-alpha 45 2/10/2024
1.0.11-alpha 47 2/10/2024
1.0.10-alpha 48 2/9/2024
1.0.9-alpha 47 2/9/2024
1.0.8-alpha 48 2/9/2024
1.0.7-alpha 46 2/9/2024
1.0.6-alpha 44 2/9/2024
1.0.5-alpha 43 2/9/2024
1.0.4-alpha 48 2/8/2024
1.0.3-alpha 44 2/8/2024
1.0.2-alpha 45 2/8/2024