### Quick Start Text Generation with C# Source: https://github.com/iyulab/lm-supply/blob/main/src/LMSupply.Generator/README.md Demonstrates how to initialize and use the TextGeneratorBuilder to generate text asynchronously. This example shows the basic setup for text generation using default models. ```csharp using LMSupply.Generator; // Using the builder pattern var generator = await TextGeneratorBuilder.Create() .WithDefaultModel() .BuildAsync(); // Generate text string response = await generator.GenerateCompleteAsync("What is AI?"); Console.WriteLine(response); await generator.DisposeAsync(); ``` -------------------------------- ### Basic Tokenization Example (C#) Source: https://github.com/iyulab/lm-supply/blob/main/src/LMSupply.Text.Core/README.md Illustrates basic text tokenization using the LMSupply.Text library. It shows how to create a tokenizer, encode a single sequence, and decode the resulting tokens. ```csharp using LMSupply.Text; // Create tokenizer var tokenizer = await TokenizerFactory.CreateAutoAsync(modelPath); // Encode text var encoded = tokenizer.EncodeSequence("Hello, world!"); Console.WriteLine($"Tokens: {encoded.InputIds.Length}"); // Decode tokens var decoded = tokenizer.Decode(encoded.InputIds, skipSpecialTokens: true); ``` -------------------------------- ### Loading and Using Multiple Models in C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/MODEL_LIFECYCLE.md Shows how to load multiple independent model instances simultaneously and how to manage memory by loading them sequentially if VRAM is limited. ```csharp await using var embedder = await LocalEmbedder.LoadAsync("default"); await using var reranker = await LocalReranker.LoadAsync("default"); // Both models active simultaneously var embeddings = await embedder.EmbedAsync(texts); var ranked = await reranker.RerankAsync(query, documents); ``` ```csharp // Sequential approach for limited VRAM await using (var embedder = await LocalEmbedder.LoadAsync("default")) { embeddings = await embedder.EmbedAsync(texts); } // Embedder released, VRAM freed await using (var reranker = await LocalReranker.LoadAsync("quality")) { ranked = await reranker.RerankAsync(query, documents); } ``` -------------------------------- ### Get Hardware-Optimized LlamaOptions (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/llama.md Demonstrates the use of `LlamaOptions.GetOptimalForHardware()` to automatically configure the server settings based on the detected system hardware. This method simplifies setup by selecting appropriate values for GPU layers, batch size, KV cache quantization, and Flash Attention. ```csharp var options = new GeneratorOptions { LlamaOptions = LlamaOptions.GetOptimalForHardware() }; ``` -------------------------------- ### Start LM Supply Host Server Source: https://github.com/iyulab/lm-supply/blob/main/docs/plans/2026-03-06-api-key-impl-plan.md Starts the .NET host server for the LM Supply application. This command is used to run the application locally for testing purposes. ```bash dotnet run --project console/host/LMSupply.Console.Host.csproj ``` -------------------------------- ### C# XML Documentation Example Source: https://github.com/iyulab/lm-supply/blob/main/docs/API_DESIGN_GUIDELINES.md Demonstrates the standard format for XML documentation comments in C# for public APIs. It includes tags for summary, parameters, return values, exceptions, and code examples, ensuring comprehensive API documentation. ```csharp /// /// Brief description (one line). /// /// Description with examples. /// Cancellation token. /// Description of return value. /// When input is null. /// /// /// var result = await model.ProcessAsync("input"); /// /// ``` -------------------------------- ### Install LMSupply.Segmenter Package Source: https://github.com/iyulab/lm-supply/blob/main/docs/segmenter.md Installs the core LMSupply.Segmenter NuGet package for .NET projects. This is the first step to using the library. ```bash dotnet add package LMSupply.Segmenter ``` -------------------------------- ### Warmup Model for Fast Inference (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/TROUBLESHOOTING.md Prepares the model for inference by performing initial computations like JIT compilation and kernel initialization. This ensures subsequent inference calls are fast. ```csharp await using var model = await LocalEmbedder.LoadAsync("default"); // Warmup before production use await model.WarmupAsync(); // Now inference is fast var result = await model.EmbedAsync("text"); ``` -------------------------------- ### Quick Start Image Captioning in C# Source: https://github.com/iyulab/lm-supply/blob/main/src/LMSupply.Captioner/README.md Demonstrates the basic usage of LMSupply.Captioner to load a default captioning model and generate a caption for an image. Requires the LMSupply.Captioner NuGet package. ```csharp using LMSupply.Captioner; // Load the default captioning model var captioner = await LocalCaptioner.LoadAsync("default"); // Generate a caption var result = await captioner.CaptionAsync("photo.jpg"); Console.WriteLine(result.Caption); // Output: "A cat sitting on a windowsill looking outside" ``` -------------------------------- ### Pair Encoding for Rerankers Example (C#) Source: https://github.com/iyulab/lm-supply/blob/main/src/LMSupply.Text.Core/README.md Demonstrates how to perform pair encoding for reranker models. It covers creating a pair tokenizer and encoding a single query-document pair or a batch of pairs. ```csharp using LMSupply.Text; // Create pair tokenizer (auto-detects WordPiece/Unigram/BPE) var pairTokenizer = await TokenizerFactory.CreateAutoPairAsync(modelPath, maxLength: 512); // Encode query-document pair var encoded = pairTokenizer.EncodePair( "What is machine learning?", "Machine learning is a branch of AI..." ); // Batch encode for multiple documents var batch = pairTokenizer.EncodePairBatch( "What is machine learning?", new[] { "Doc 1...", "Doc 2...", "Doc 3..." } ); ``` -------------------------------- ### Using HuggingFace Models with C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/generator.md Explains how to use ONNX models directly from HuggingFace. This allows access to a wide range of community-provided models. The examples show how to specify models like Phi-3.5-mini-instruct-onnx and Llama-3.2-1B-Instruct-GENAI-ONNX. ```csharp // Use any ONNX model from HuggingFace .WithHuggingFaceModel("microsoft/Phi-3.5-mini-instruct-onnx") .WithHuggingFaceModel("onnx-community/Llama-3.2-1B-Instruct-GENAI-ONNX") ``` -------------------------------- ### Install LMSupply.Ocr Package Source: https://github.com/iyulab/lm-supply/blob/main/docs/ocr.md Installs the core LMSupply.Ocr NuGet package. Additional packages are required for GPU acceleration on different platforms. ```bash dotnet add package LMSupply.Ocr ``` -------------------------------- ### Install LMSupply.Captioner Package Source: https://github.com/iyulab/lm-supply/blob/main/docs/captioner.md Installs the core LMSupply.Captioner NuGet package. For GPU acceleration, additional packages like Microsoft.ML.OnnxRuntime.Gpu, Microsoft.ML.OnnxRuntime.DirectML, or Microsoft.ML.OnnxRuntime.CoreML are required depending on the operating system and hardware. ```bash dotnet add package LMSupply.Captioner # For GPU acceleration: # NVIDIA CUDA dotnet add package Microsoft.ML.OnnxRuntime.Gpu # Windows DirectML dotnet add package Microsoft.ML.OnnxRuntime.DirectML # macOS CoreML dotnet add package Microsoft.ML.OnnxRuntime.CoreML ``` -------------------------------- ### Install LMSupply.Translator Package Source: https://github.com/iyulab/lm-supply/blob/main/docs/translator.md Installs the core LMSupply.Translator NuGet package for .NET projects. This is the first step to using the library for machine translation. ```bash dotnet add package LMSupply.Translator ``` -------------------------------- ### Quick Start: Synthesize Speech with LMSupply.Synthesizer (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/synthesizer.md Demonstrates the basic usage of LMSupply.Synthesizer to load a default model, synthesize speech from text, and save the output to a WAV file. This requires the LMSupply.Synthesizer NuGet package. ```csharp using LMSupply.Synthesizer; // Load the default model (English US Lessac) var synthesizer = await LocalSynthesizer.LoadAsync("default"); // Synthesize speech from text var result = await synthesizer.SynthesizeAsync("Hello, welcome to LMSupply!"); Console.WriteLine($"Duration: {result.DurationSeconds:F2}s"); Console.WriteLine($"Real-time factor: {result.RealTimeFactor:F1}x"); // Save as WAV file await synthesizer.SynthesizeToFileAsync("Hello world!", "output.wav"); ``` -------------------------------- ### Batch Processing Example (C#) Source: https://github.com/iyulab/lm-supply/blob/main/src/LMSupply.Text.Core/README.md Shows how to efficiently process multiple text sequences in a batch using the LMSupply.Text tokenizer. It demonstrates encoding a batch of texts and accessing the resulting InputIds and AttentionMask tensors. ```csharp var tokenizer = await TokenizerFactory.CreateAutoAsync(modelPath); var texts = new[] { "First text", "Second text", "Third text" }; var batch = tokenizer.EncodeBatch(texts, maxLength: 256); // Access batch tensors long[,] inputIds = batch.InputIds; long[,] attentionMask = batch.AttentionMask; ``` -------------------------------- ### Monitor Model Download Progress (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/TROUBLESHOOTING.md Shows how to monitor the progress of model downloads using a progress callback. This is useful for long downloads or to provide user feedback. ```csharp // 1. Use progress callback to monitor var progress = new Progress(p => Console.WriteLine($"{p.ProgressPercentage:P0}")); await LocalEmbedder.LoadAsync("default", progress: progress); ``` -------------------------------- ### Installation: Add LMSupply.Synthesizer Package (Bash) Source: https://github.com/iyulab/lm-supply/blob/main/docs/synthesizer.md Shows the command to add the LMSupply.Synthesizer NuGet package to a .NET project using the dotnet CLI. This is the first step to using the library. ```bash dotnet add package LMSupply.Synthesizer ``` -------------------------------- ### Install GPU Acceleration Packages for .NET Source: https://github.com/iyulab/lm-supply/blob/main/src/LMSupply.Captioner/README.md Provides commands to add the necessary NuGet packages for enabling GPU acceleration with LMSupply.Captioner. Choose the package appropriate for your hardware (NVIDIA or Windows DirectML). ```bash # NVIDIA GPU dotnet add package Microsoft.ML.OnnxRuntime.Gpu # Windows (AMD/Intel/NVIDIA) dotnet add package Microsoft.ML.OnnxRuntime.DirectML ``` -------------------------------- ### Save Synthesis to File (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/synthesizer.md Provides a concise example of synthesizing speech directly to a WAV file using the `SynthesizeToFileAsync` method. This is a convenient way to generate audio output without manual file handling. ```csharp // Save directly to WAV file await synthesizer.SynthesizeToFileAsync("Hello, world!", "output.wav"); ``` -------------------------------- ### Check NVIDIA Driver Status on Linux (Bash) Source: https://github.com/iyulab/lm-supply/blob/main/docs/TROUBLESHOOTING.md Verifies the status and details of the NVIDIA driver installation on a Linux system using the `nvidia-smi` command. Essential for diagnosing CUDA-related issues. ```bash # Check NVIDIA driver nvidia-smi ``` -------------------------------- ### Run Transcriber Sample with Different Configurations Source: https://github.com/iyulab/lm-supply/blob/main/samples/README.md Demonstrates how to run the TranscriberSample with default settings, specifying an audio file, and selecting a model and provider (e.g., CUDA). This sample showcases model loading, basic transcription, segment timestamps, language specification, and real-time factor calculation. ```bash # Run with default settings dotnet run --project TranscriberSample # Transcribe an audio file dotnet run --project TranscriberSample -- path/to/audio.wav # Specify model and provider dotnet run --project TranscriberSample -- path/to/audio.wav large cuda ``` -------------------------------- ### Get Hardware Profile Information in C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/GPU_PROVIDERS.md Retrieves and displays detailed hardware information, including GPU name, memory, system memory, and the recommended execution provider tier. ```csharp var profile = HardwareProfile.Current; Console.WriteLine($"GPU: {profile.GpuInfo.DeviceName}"); Console.WriteLine($"GPU Memory: {profile.GpuMemoryGB:F1} GB"); Console.WriteLine($"System Memory: {profile.SystemMemoryGB:F1} GB"); Console.WriteLine($"Recommended Provider: {profile.RecommendedProvider}"); Console.WriteLine($"Performance Tier: {profile.Tier}"); ``` -------------------------------- ### Check CUDA Provider Availability in C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/GPU_PROVIDERS.md Checks if the system has an NVIDIA GPU and prints its details, including device name and VRAM. This is useful for troubleshooting or confirming CUDA setup. ```csharp var profile = HardwareProfile.Current; if (profile.GpuInfo.Vendor == GpuVendor.Nvidia) { Console.WriteLine($"NVIDIA GPU: {profile.GpuInfo.DeviceName}"); Console.WriteLine($"VRAM: {profile.GpuMemoryGB:F1} GB"); } ``` -------------------------------- ### Warmup and Use Model for Faster Inference in C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/MODEL_LIFECYCLE.md Shows how to use the `WarmupAsync()` method to pre-compile model operators and GPU kernels before production inference, reducing the latency of the first actual inference call. ```csharp await using var model = await LocalEmbedder.LoadAsync("default"); // Warm up the model (runs a dummy inference) await model.WarmupAsync(); // Subsequent calls will be faster var embedding = await model.EmbedAsync("Hello world"); ``` -------------------------------- ### Get Hardware Profile Information (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/TROUBLESHOOTING.md Retrieves and displays detailed information about the current hardware, including GPU name, vendor, VRAM, and recommended execution provider. Useful for diagnosing GPU-related issues. ```csharp var profile = HardwareProfile.Current; Console.WriteLine($"GPU: {profile.GpuInfo.DeviceName}"); Console.WriteLine($"Vendor: {profile.GpuInfo.Vendor}"); Console.WriteLine($"VRAM: {profile.GpuMemoryGB:F1} GB"); Console.WriteLine($"Provider: {profile.RecommendedProvider}"); ``` -------------------------------- ### Query Model Information and Diagnostics in C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/MODEL_LIFECYCLE.md Demonstrates how to retrieve model metadata such as ID, path, and dimensions using `GetModelInfo()`, and how to check runtime diagnostics like GPU activation status and active execution providers. ```csharp await using var model = await LocalEmbedder.LoadAsync("default"); var info = model.GetModelInfo(); Console.WriteLine($"Model: {info.ModelId}"); Console.WriteLine($"Path: {info.ModelPath}"); Console.WriteLine($"Dimensions: {info.Dimensions}"); ``` ```csharp // For Transcriber (currently) Console.WriteLine($"GPU Active: {model.IsGpuActive}"); Console.WriteLine($"Providers: {string.Join(", ", model.ActiveProviders)}"); ``` -------------------------------- ### Loading Generator Models (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/MEMORY_REQUIREMENTS.md Provides examples for loading memory-intensive generator models. It shows how to use GGUF quantized models for automatic hardware fitting and smaller ONNX models like Phi-4-mini-instruct. ```csharp // Use GGUF quantized model (auto-selects best fit for your hardware) var generator = await LocalGenerator.LoadAsync("model-q4_k_m.gguf"); // Or use a small ONNX model var generator = await LocalGenerator.LoadAsync("microsoft/Phi-4-mini-instruct-onnx"); ``` -------------------------------- ### Quick Start Object Detection in C# Source: https://github.com/iyulab/lm-supply/blob/main/src/LMSupply.Detector/README.md Demonstrates how to load a default object detection model and perform detection on an image using LMSupply.Detector. It iterates through the detection results, printing labels, confidence scores, and bounding box coordinates. ```csharp using LMSupply.Detector; // Load the default model await using var detector = await LocalDetector.LoadAsync("default"); // Detect objects var results = await detector.DetectAsync("photo.jpg"); foreach (var detection in results) { Console.WriteLine($"{detection.Label}: {detection.Confidence:P1}"); Console.WriteLine($" Box: [{detection.Box.X1:F0}, {detection.Box.Y1:F0}]"); } ``` -------------------------------- ### Work with Bounding Boxes in C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/detector.md Demonstrates how to access and manipulate bounding box information for detected objects. Includes examples of getting box dimensions, center coordinates, area, scaling, clamping to image boundaries, and calculating Intersection over Union (IoU). ```csharp var results = await detector.DetectAsync("photo.jpg"); foreach (var det in results) { var box = det.Box; // Get box properties Console.WriteLine($"Width: {box.Width}, Height: {box.Height}"); Console.WriteLine($"Center: ({box.CenterX}, {box.CenterY})"); Console.WriteLine($"Area: {box.Area} pixels"); // Scale to different dimensions var scaledBox = box.Scale(0.5f, 0.5f); // Clamp to image boundaries var clampedBox = box.Clamp(imageWidth, imageHeight); // Calculate IoU with another box float iou = box.IoU(otherBox); } ``` -------------------------------- ### Get Hardware Performance Tier and Details (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/MEMORY_REQUIREMENTS.md Retrieves the current hardware performance tier and associated details such as GPU name, VRAM, and recommended provider. This information is crucial for selecting appropriate models based on available hardware. ```csharp var profile = HardwareProfile.Current; Console.WriteLine($"Tier: {profile.Tier}"); Console.WriteLine($"GPU: {profile.GpuInfo?.Name ?? "None"}"); Console.WriteLine($"VRAM: {profile.GpuInfo?.VramBytes / (1024*1024*1024)}GB"); Console.WriteLine($"Recommended Provider: {profile.RecommendedProvider}"); ``` -------------------------------- ### Basic Synthesis: Get Audio Samples and Convert (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/synthesizer.md Illustrates how to synthesize speech and access the raw audio samples as a float array. It also shows how to convert these samples into WAV or 16-bit PCM byte arrays for further processing or saving. ```csharp // Synthesize and get result var result = await synthesizer.SynthesizeAsync("Hello, world!"); // Access audio samples (float32, range -1.0 to 1.0) float[] samples = result.AudioSamples; int sampleRate = result.SampleRate; // Get as byte arrays byte[] wavBytes = result.ToWavBytes(); // WAV file format byte[] pcmBytes = result.ToPcm16Bytes(); // Raw 16-bit PCM ``` -------------------------------- ### Build Project and UI Source: https://github.com/iyulab/lm-supply/blob/main/docs/plans/2026-03-06-api-key-impl-plan.md Builds the .NET project and the UI using npm. This is the initial step before running any tests or deployments. ```bash dotnet build cd console/ui && npm run build ``` -------------------------------- ### Configure Execution Provider for Memory Issues (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/MEMORY_REQUIREMENTS.md Provides code examples for switching the execution provider to DirectML (on Windows) or CPU to mitigate CUDA Out of Memory errors. This allows the system to utilize different hardware resources for model execution. ```csharp // Switch to DirectML (Windows) var options = new EmbedderOptions { Provider = ExecutionProvider.DirectML }; // Or use CPU var options = new EmbedderOptions { Provider = ExecutionProvider.Cpu }; ``` -------------------------------- ### Enable DirectML for Transcriber Sample Source: https://github.com/iyulab/lm-supply/blob/main/samples/README.md Demonstrates how to enable the DirectML package for the TranscriberSample to leverage DirectML on Windows for GPU acceleration. This command specifies the DirectML provider and an audio file for transcription. ```bash # Enable DirectML package dotnet run --project TranscriberSample -p:EnableDirectML=true -- audio.wav default directml ``` -------------------------------- ### Run Embedder Sample with Different Configurations Source: https://github.com/iyulab/lm-supply/blob/main/samples/README.md Demonstrates how to run the EmbedderSample with default settings or by specifying a model and provider (e.g., CUDA). This sample covers single and batch embedding, cosine similarity calculation, and GPU/CPU provider selection. ```bash # Run with default settings dotnet run --project EmbedderSample # Specify model and provider dotnet run --project EmbedderSample -- default cuda ``` -------------------------------- ### Install LMSupply.Generator Package Source: https://github.com/iyulab/lm-supply/blob/main/docs/generator.md Installs the LMSupply.Generator NuGet package using the .NET CLI. This is the first step to using the library in your C# project. ```bash dotnet add package LMSupply.Generator ``` -------------------------------- ### Model Configuration: Specify Execution Provider and Cache (C#) Source: https://github.com/iyulab/lm-supply/blob/main/docs/synthesizer.md Demonstrates how to customize the `LocalSynthesizer` loading process using `SynthesizerOptions`. This includes specifying the `ExecutionProvider` (e.g., GPU acceleration) and setting a custom cache directory for models. ```csharp var options = new SynthesizerOptions { Provider = ExecutionProvider.Cuda, // Use GPU CacheDirectory = "/custom/cache", // Custom cache location ThreadCount = 4 // CPU threads }; var synthesizer = await LocalSynthesizer.LoadAsync("quality", options); ``` -------------------------------- ### Install LMSupply.Detector Package Source: https://github.com/iyulab/lm-supply/blob/main/docs/detector.md Installs the core LMSupply.Detector package using the .NET CLI. This is the first step to using the library in your project. ```bash dotnet add package LMSupply.Detector ``` -------------------------------- ### Selecting Preset Models with C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/generator.md Demonstrates how to select different preset models for text generation. The code shows options for default, fast, quality, and small model presets, allowing users to choose based on their needs for speed or quality. ```csharp // Default: Phi-3.5 Mini (balanced, MIT license) .WithDefaultModel() // Or use presets .WithModel(GeneratorModelPreset.Default) // Phi-3.5 Mini .WithModel(GeneratorModelPreset.Fast) // Llama 3.2 1B .WithModel(GeneratorModelPreset.Quality) // Phi-4 .WithModel(GeneratorModelPreset.Small) // Llama 3.2 1B ``` -------------------------------- ### Install LMSupply.Reranker Package Source: https://github.com/iyulab/lm-supply/blob/main/docs/reranker.md Installs the core LMSupply.Reranker library using the .NET CLI. For GPU acceleration, additional packages for ONNX Runtime (CUDA, DirectML, CoreML) may be required. ```bash dotnet add package LMSupply.Reranker # NVIDIA CUDA dotnet add package Microsoft.ML.OnnxRuntime.Gpu # Windows DirectML dotnet add package Microsoft.ML.OnnxRuntime.DirectML # macOS CoreML dotnet add package Microsoft.ML.OnnxRuntime.CoreML ``` -------------------------------- ### Commit Changes for EF Core SQLite Setup Source: https://github.com/iyulab/lm-supply/blob/main/docs/plans/2026-03-06-api-key-impl-plan.md This command stages and commits the changes made to Directory.Packages.props and LMSupply.Console.Host.csproj. It includes a descriptive commit message indicating the addition of EF Core SQLite packages for API key storage. ```bash git add Directory.Packages.props console/host/LMSupply.Console.Host.csproj git commit -m "feat(console): add EF Core SQLite packages for API key storage" ``` -------------------------------- ### Install GPU Acceleration Packages Source: https://github.com/iyulab/lm-supply/blob/main/docs/detector.md Installs optional packages for GPU acceleration. Choose the package corresponding to your hardware and operating system (NVIDIA CUDA, Windows DirectML, or macOS CoreML). ```bash # NVIDIA CUDA dotnet add package Microsoft.ML.OnnxRuntime.Gpu # Windows DirectML dotnet add package Microsoft.ML.OnnxRuntime.DirectML # macOS CoreML dotnet add package Microsoft.ML.OnnxRuntime.CoreML ``` -------------------------------- ### Perform Text Clustering Source: https://github.com/iyulab/lm-supply/blob/main/docs/embedder.md Shows an example of clustering texts by calculating the cosine similarity between their embeddings and identifying pairs with similarity above a threshold. ```csharp using LMSupply.Embedder; await using var model = await LocalEmbedder.LoadAsync("default"); var texts = new[] { // Technology "Artificial intelligence is changing industries.", "Machine learning models improve with more data.", "Cloud computing enables scalable applications.", // Nature "The forest is home to many species of birds.", "Rivers flow from mountains to the sea.", // Food "Italian pasta is often served with tomato sauce.", "Sushi is a traditional Japanese dish." }; var embeddings = await model.EmbedAsync(texts); // Find texts with similarity > 0.5 for (int i = 0; i < texts.Length; i++) { for (int j = i + 1; j < texts.Length; j++) { var sim = LocalEmbedder.CosineSimilarity(embeddings[i], embeddings[j]); if (sim > 0.5) { Console.WriteLine($"Similar: \"{texts[i]}\" <-> \"{texts[j]}\" ({sim:F3})"); } } } ``` -------------------------------- ### Install LMSupply.Embedder Package Source: https://github.com/iyulab/lm-supply/blob/main/docs/embedder.md This command adds the LMSupply.Embedder NuGet package to your .NET project. This package contains all the necessary components for text embedding. ```bash dotnet add package LMSupply.Embedder ``` -------------------------------- ### Traditional AI Model Setup vs. LMSupply (C#) Source: https://github.com/iyulab/lm-supply/blob/main/README.md Compares the traditional, verbose approach to setting up and running AI model inference with the streamlined, two-line solution provided by LMSupply. This highlights LMSupply's zero boilerplate principle. ```csharp // ❌ Without LMSupply: 50+ lines of setup var tokenizer = LoadTokenizer(modelPath); var session = new InferenceSession(modelPath, sessionOptions); var inputIds = tokenizer.Encode(text); var attentionMask = CreateAttentionMask(inputIds); var inputs = new List { ... }; var outputs = session.Run(inputs); var embeddings = PostProcess(outputs); // ... error handling, pooling, normalization, cleanup ... ``` ```csharp // ✅ With LMSupply: 2 lines await using var model = await LocalEmbedder.LoadAsync("default"); float[] embedding = await model.EmbedAsync("Hello, world!"); ``` -------------------------------- ### Retrieve Model Information Source: https://github.com/iyulab/lm-supply/blob/main/docs/embedder.md Shows how to get information about the loaded embedding model, including its repository ID, dimensions, and maximum sequence length. ```csharp var info = model.GetModelInfo(); if (info != null) { Console.WriteLine($"Model: {info.RepoId}"); Console.WriteLine($"Dimensions: {info.Dimensions}"); Console.WriteLine($"Max Tokens: {info.MaxSequenceLength}"); } ``` -------------------------------- ### Get Specific API Key Statistics Source: https://github.com/iyulab/lm-supply/blob/main/docs/plans/2026-03-06-api-key-impl-plan.md Retrieves request statistics for a specific API key over a specified number of past days. ```APIDOC ## GET /api/keys/{id}/stats ### Description Fetches request statistics for a particular API key for a given period. ### Method GET ### Endpoint /api/keys/{id}/stats ### Parameters #### Path Parameters - **id** (guid) - Required - The unique identifier of the API key. #### Query Parameters - **days** (integer) - Optional - The number of past days to include in the statistics. Defaults to 7. #### Request Body None ### Response #### Success Response (200 OK) - **stats** (object) - An object containing statistics for the specific key. - **totalRequests** (integer) - The total number of requests made by this key. - **startDate** (datetime) - The start date of the statistics period. - **endDate** (datetime) - The end date of the statistics period. #### Response Example ```json { "totalRequests": 120, "startDate": "2023-10-20T00:00:00Z", "endDate": "2023-10-27T00:00:00Z" } ``` #### Error Response (404 Not Found) Indicates that the specified API key ID was not found. ``` -------------------------------- ### Image Preprocessing with LMSupply.Vision.Core (C#) Source: https://github.com/iyulab/lm-supply/blob/main/src/LMSupply.Vision.Core/README.md Demonstrates how to load and preprocess an image for a specific model using the ImagePreprocessor class from LMSupply.Vision.Core. This involves creating an instance of ImagePreprocessor and calling the Preprocess method with an image path and a predefined profile. ```csharp using LMSupply.Vision; // Load and preprocess an image for a specific model var preprocessor = new ImagePreprocessor(); var tensor = preprocessor.Preprocess("image.jpg", PreprocessProfiles.ImageNet); ``` -------------------------------- ### Setting Generation Options with C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/generator.md Illustrates how to customize generation parameters such as maximum tokens, temperature, top-p, top-k, and repetition penalty. It also shows how to use predefined options for creative or precise generation. ```csharp var options = new GeneratorOptions { MaxTokens = 512, // Maximum tokens to generate Temperature = 0.7f, // Randomness (0.0 = deterministic) TopP = 0.9f, // Nucleus sampling TopK = 50, // Top-K sampling RepetitionPenalty = 1.1f, // Discourage repetition DoSample = true // Enable sampling (vs greedy) }; string response = await generator.GenerateCompleteAsync(prompt, options); // Or use presets string creative = await generator.GenerateCompleteAsync(prompt, GeneratorOptions.Creative); string precise = await generator.GenerateCompleteAsync(prompt, GeneratorOptions.Precise); ``` -------------------------------- ### Get Global API Key Statistics Source: https://github.com/iyulab/lm-supply/blob/main/docs/plans/2026-03-06-api-key-impl-plan.md Retrieves aggregated request statistics for all API keys over a specified number of past days. ```APIDOC ## GET /api/keys/stats ### Description Fetches aggregated request statistics across all API keys for a given period. ### Method GET ### Endpoint /api/keys/stats ### Parameters #### Query Parameters - **days** (integer) - Optional - The number of past days to include in the statistics. Defaults to 7. #### Request Body None ### Response #### Success Response (200 OK) - **stats** (object) - An object containing aggregated statistics. - **totalRequests** (integer) - The total number of requests made by all keys. - **uniqueKeys** (integer) - The number of unique API keys that had activity. - **averageRequestsPerKey** (number) - The average number of requests per active key. - **startDate** (datetime) - The start date of the statistics period. - **endDate** (datetime) - The end date of the statistics period. #### Response Example ```json { "totalRequests": 1500, "uniqueKeys": 50, "averageRequestsPerKey": 30.0, "startDate": "2023-10-20T00:00:00Z", "endDate": "2023-10-27T00:00:00Z" } ``` ``` -------------------------------- ### Hardware Detection and Recommendations with C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/generator.md Shows how to use the HardwareDetector to get recommendations for AI models based on the system's hardware. It provides a summary of detected hardware, system memory, recommended providers, quantization, context length, and suitable models. ```csharp using LMSupply.Generator; // Get hardware recommendations var recommendation = HardwareDetector.GetRecommendation(); Console.WriteLine(recommendation.GetSummary()); // Output: // Hardware: NVIDIA RTX 4090 (24.0GB) // System Memory: 64.0GB // Provider: Cuda // Quantization: FP16 // Max Context: 16384 // Recommended Models: microsoft/Phi-3.5-mini-instruct-onnx, microsoft/phi-4-onnx // Auto-select best provider var provider = HardwareDetector.GetBestProvider(); ``` -------------------------------- ### Batch Image Captioning in C# Source: https://github.com/iyulab/lm-supply/blob/main/docs/captioner.md Demonstrates how to process multiple images in a batch using the captioner. This is useful for scenarios where captions need to be generated for a collection of images efficiently. ```csharp var images = new[] { "image1.jpg", "image2.jpg", "image3.jpg" }; foreach (var image in images) { var result = await captioner.CaptionAsync(image); Console.WriteLine($"{image}: {result.Caption}"); } ```