A tiny .NET 9 console app that let's you chat with a local LLM (gpt-oss-20b
by default) via LM Studio using the OpenAI-compatible API and Microsoft.Extensions.AI
adapters. It streams responses and separates internal thoughts from the final answer.
- Windows, MacOS or Linux
- .NET 9 SDK
- LM Studio (or any OpenAI-compatible server) running locally
- Default endpoint used in this app:
http://localhost:1234/v1
- Dummy API key is accepted by LM Studio: "lm-studio"
- Default endpoint used in this app:
- For the oss-gpt-20b model at least 16 GB GPU VRAM or 16 GB Unified Memory on Apple Silicon (with less memory you can also use smaller models)
This project uses the following NuGet packages (resolved via the csproj):
- Microsoft.Extensions.AI
- Microsoft.Extensions.AI.OpenAI
- OpenAI (Azure SDK client for OpenAI-compatible APIs)
- System.ClientModel
These assemblies appear in bin/Debug/net9.0/
after build.
Program.cs
constructs an OpenAI chat client pointed at the local endpoint and adapts it toIChatClient
.- User input is sent along with a small system prompt that asks the model to respond with and sections.
- Streaming deltas are parsed; only complete tagged sections are printed.
Change these variables in Program.cs
to match your local setup:
endpoint
: URI to your OpenAI-compatible server (LM Studio default ishttp://localhost:1234/v1
).apiKey
: For LM Studio, any non-empty string works (e.g."lm-studio"
).modelId
: The model name exposed by your server (e.g.openai/gpt-oss-20b
).
If you're using VS Code, a build task is provided. From the terminal:
dotnet build
Run the produced app (adjust path if using Release):
dotnet run
- Make sure your local server is running and the model is loaded before starting the app, otherwise requests will fail.
- If your server requires a real API key, set
apiKey
accordingly or use an environment variable wiring as needed.
This repo provides helper scripts to install prerequisites and prepare LM Studio with the gpt-oss-20b
model.
- On Linux or macOS: run
./install.sh
(ensures PowerShell 7, then calls the PowerShell installer) - Alternatively, on macOS/Windows: run
pwsh -File ./install.ps1
Hardware note: The gpt-oss-20b
model requires more than 16 GB GPU VRAM. On Apple Silicon (Unified Memory), this means more than 16 GB system RAM. Otherwise, LMStudio may not be able to load it. If you try with --gpu=off it may be very slow.
What the installer does:
- Installs LM Studio if missing
- macOS:
brew install --cask lm-studio
- Windows:
winget install --id ElementLabs.LMStudio -e
- Linux: prompts to download the AppImage from
https://lmstudio.ai/download
-
Ensures .NET 9 SDK is installed (winget/brew/dotnet-install)
-
Boots the
lms
CLI, starts the local server, and pulls the model
- Starts LM Studio local server on port 1234
- Downloads and loads
openai/gpt-oss-20b
(or a custom-Model
argument)
Examples:
# Linux
chmod +x ./install.sh
./install.sh
# macOS or Windows
pwsh -File ./install.ps1
Choose a different model:
pwsh -File ./install.ps1 -Model "lmstudio-community/Phi-3.5-mini-instruct-GGUF/Phi-3.5-mini-instruct-Q4_K_M.gguf"
Tip: Use the exact GGUF filename shown on the model page in LM Studio to lock the quantization you want.
After the script completes, LM Studio’s OpenAI-compatible API should be available at:
http://localhost:1234/v1/
Then run the app:
dotnet run
If you are using the tool but are unable to contribute technically, please consider promoting it and donating an amount that reflects its value to you. You can do so either via PayPal
or via GitHub Sponsors.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star 😉 Thanks!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.