Table of Contents

💬 Create Chatbot with Persistent Session in .NET Applications


🎯 Purpose of the Sample

The Multi-Turn Chat with Persistent Session Demo illustrates the use of the LM-Kit.NET SDK to develop a chat application that maintains context across multiple interactions. This application saves chat sessions to a file, enabling users to resume conversations seamlessly after reopening the application.


👥 Industry Target Audience

This sample is particularly beneficial for developers and organizations in the following sectors:

  • 📞 Customer Support: Businesses requiring persistent chat sessions to track ongoing customer interactions.
  • 🤖 Virtual Assistants: Developers building virtual assistants that need to retain context between sessions.
  • 📚 E-Learning Platforms: Educational services that provide tutoring and need to save student interactions for continuity.
  • 🏥 Healthcare: Applications that require maintaining patient conversations for better follow-up and care continuity.

🚀 Problem Solved

Traditional chat applications often lose context when closed or interrupted. This demo resolves that issue by saving chat sessions to a file, allowing the conversation to resume from the last interaction. This ensures continuity and enhances the user experience. Furthermore, by saving sessions to disk rather than keeping them in memory, the application can handle a large number of simultaneous conversations on the same server without exhausting memory resources. This eliminates the need for an underlying key-value cache in memory, making the system more scalable and efficient.


💻 Sample Application Description

The Multi-Turn Chat with Persistent Session Demo is a console application that facilitates multi-turn conversations with context retention across sessions. It leverages a pre-trained language model for handling interactions and saves chat history to a file for persistence. Both loading and saving operations are optimized for speed, ensuring a seamless user experience.

✨ Key Features

  • 📈 Model Selection: Allows users to choose from multiple pre-trained models.
  • 💾 Persistent Sessions: Saves and resumes chat sessions from a file.
  • 🔄 Multi-Turn Conversations: Maintains context across multiple user interactions.
  • 📝 Special Commands: Provides commands to reset the session or regenerate the last response.
  • 📜 Complete Chat History: Displays the entire chat history when a previously saved session is reopened.
  • ⚡ Fast Operations: Ensures rapid loading and saving of sessions, minimizing delay.

🧠 Supported Models

The sample supports the following pre-trained models for chat interactions:

  • Mistral Nemo 2407 12.2B
  • Meta Llama 3.1 8B
  • Google Gemma2 9B Medium
  • Microsoft Phi-3 3.82B Mini
  • Alibaba Qwen-2 7.6B

🛠️ Getting Started

📋 Prerequisites

  • .NET Framework 4.6.2 or .NET 6.0

📥 Download the Project

▶️ Running the Application

  1. 📂 Clone the repository:

    git clone https://github.com/LM-Kit/lm-kit-net-samples.git
    
  2. 📁 Navigate to the project directory:

    cd lm-kit-net-samples/console_framework_4.62/multi_turn_chat_with_persistent_session
    

    or

    cd lm-kit-net-samples/console_net6/multi_turn_chat_with_persistent_session
    
  3. 🔨 Build and run the application:

    dotnet build
    dotnet run
    

💡 Example Usage

  1. Set the License Key (if available):

    LMKit.Licensing.LicenseManager.SetLicenseKey(""); // Set an optional license key here if available.
    
  2. Select the Model: The application prompts you to select one of the pre-defined models or enter a custom model URI.

  3. Start the Chat Session: If a previous session exists, it will resume from the last interaction, displaying the complete chat history on the screen. Otherwise, it starts a new session.

  4. Use Special Commands:

    • /reset: Start a new session from scratch.
    • /regenerate: Generate a new response for the last input.
    • Empty Prompt: Save the chat session and exit.

By following these steps, developers can explore the functionalities of LM-Kit.NET and integrate advanced persistent session management into their chatbot applications, enhancing user interactions through continuous and context-aware dialogue.