Table of Contents

🚀 Getting Started with LM-Kit.NET

This guide provides instructions to quickly get started with LM-Kit.NET, enabling the integration of generative AI capabilities into .NET applications.


📋 Prerequisites

LM-Kit.NET can be used in any application targeting the .NET framework from version 4.6.2 to 9.0, with just four clicks. Ensure the following prerequisites are met before starting:

  • .NET Framework: .NET 4.6.2 or later.
  • Development Environment: Visual Studio 2019 or later, or Visual Studio Code.
    • Operating Systems: Windows or macOS.
  • NuGet Package Manager: Ensure the NuGet Package Manager is installed for easy installation of the LM-Kit.NET package.

📥 Installation

To use LM-Kit.NET, install the SDK via NuGet Package Manager as follows:

Using NuGet Package Manager Console

  1. Open the project in Visual Studio (or preferred .NET IDE).
  2. Open the NuGet Package Manager Console from the Tools menu.
  3. Execute the following command:
    Install-Package LM-Kit.NET
    

Using NuGet Package Manager UI

  1. Right-click on the project in the Solution Explorer.
  2. Select Manage NuGet Packages...
  3. Search for LM-Kit.NET in the Browse tab.
  4. Click Install to add the package to the project.

Note: It is recommended to install the optional CUDA Backend to benefit from Nvidia GPU acceleration:

Install-Package LM-Kit.NET.Backend.Cuda12.Windows
Install-Package LM-Kit.NET.Backend.Cuda12.Linux

🛠 Basic Usage

Initialize LM-Kit.NET

After installing the SDK, initialize LM-Kit.NET in the application. Below is an example demonstrating basic initialization with logging and CUDA acceleration:

using LMKit;

namespace YourNamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            // Set log level to Debug
            LMKit.Runtime.LogLevel = LMKit.Runtime.LMKitLogLevel.Debug;
            
            // Enable CUDA acceleration
            LMKit.Runtime.EnableCuda = true;

            // Initialize LM-Kit.NET runtime
            LMKit.Runtime.Initialize();

            // Optionally set a license key if available
            LMKit.Licensing.LicenseManager.SetLicenseKey("");

            // Code to use LM-Kit.NET goes here
        }
    }
}

💬 Example: Text Generation

The following example demonstrates generating text using LM-Kit.NET:

using LMKit;
using LMKit.TextGeneration;

namespace YourNamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            // Load the model
            var model = new LMKit.Model.LLM("my-model.gguf");

            // Create a multi-turn conversation instance
            var chat = new LMKit.TextGeneration.MultiTurnConversation(model);

            // Submit a prompt and get the response. The Submit method returns an object of type [LMKit.TextGeneration.TextGenerationResult](https://docs.lm-kit.com/lm-kit-net/api/LMKit.TextGeneration.TextGenerationResult.html)
            var response = chat.Submit("Why are cats so cute?");

            // Output the generated text
            Console.WriteLine("Response: " + response.Completion);
        }
    }
}

🌐 Example: Language Detection

The following example demonstrates detecting the language of a given text using LM-Kit.NET:

using LMKit;
using LMKit.LanguageDetection;

namespace YourNamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            // Load the model
            var model = new LMKit.Model.LLM("my-model.gguf");

            // Create a [TextTranslation](https://docs.lm-kit.com/lm-kit-net/api/LMKit.Translation.html) instance
            var textTranslation = new LMKit.Translation.TextTranslation(model);
            string text = "Allons boire une bière après le travail !";
            Language detectedLanguage = textTranslation.DetectLanguage(text);

            // Output the detected language
            Console.WriteLine("Detected Language: " + detectedLanguage.ToString());
        }
    }
}

⚙️ Advanced Configuration

LM-Kit.NET provides advanced configuration options for fine-tuning performance and behavior. Below is an example of customizing the internal inference engine:

using LMKit;
using LMKit.Configuration;

namespace YourNamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            // Enable KV (key-value) cache recycling 
            LMKit.GlobalConfiguration.EnableKVCacheRecycling = true;
            
            // Disable model caching 
            LMKit.GlobalConfiguration.EnableModelCache = false;
            
            // Enable token healing 
            LMKit.GlobalConfiguration.EnableTokenHealing = true;
            
            // Discover more parameters in the LMKit.GlobalConfiguration static class.

            // Code to use LM-Kit.NET goes here
        }
    }
}

🔍 Exploring More Features

LM-Kit.NET includes various features, such as:

  • Text Correction: Automatically correct grammar and spelling errors.
  • Sentiment Analysis: Detect and interpret the emotional tone of text.
  • Model Fine-Tuning: Customize pre-trained models for specific tasks.
  • Text Embeddings: Transform text into numerical representations for semantic analysis.

Refer to the API Documentation for detailed information on all available methods and classes.


📞 Support

For assistance with LM-Kit.NET:

  • Visit the Documentation for comprehensive guides and references.
  • Contact Support for professional assistance.