All work

LMStudio for .NET

A small .NET library for chatting with a local language model through LM Studio. My first NuGet package: 1,000+ downloads.

soloMay – Jun 2024.NET 8, no dependencies, MITStopped: no longer maintained

The LMStudio package page on nuget.org, with the download count.

The problem

In 2024 I wanted to call a local language model from C#, without pulling in a large SDK.

What I built

A chat class that keeps the conversation history and talks to LM Studio’s local server, using only HttpClient and System.Text.Json. Because it follows the OpenAI chat format, it works with any server that speaks it. Four releases in three weeks, MIT-licensed, with no dependencies.

Program.cs
var connection = new ModelConnection(
    "http://localhost:1234/v1/", "llama-3-8b-instruct");
var chat = new Chat(connection, "You're a helpful assistant.");
string answer = await chat.CreateChatCompletion(
    "What is dependency injection?");
Using the library, version 1.0.

What I’d do differently

  • Version 1.2 made the main call synchronous. That’s a breaking change in a minor version, and .Result can deadlock in UI and ASP.NET code.
  • The apiKey parameter is accepted but never sent.
  • A library shouldn’t write to the console; it should log through ILogger, or not at all.
  • The code of the later releases was never pushed, so the repository is behind the package.
  • No streaming, no cancellation, and a new HttpClient per connection instead of a factory.

Status

No longer maintained. It has 1,000+ downloads on NuGet; that count includes mirrors and CI restores, so it isn’t a user count. The code is on GitHub.