AI

Run local models in your .NET apps with Llama on Windows

.NET Blog Luis Quintanilla
AI

Hugging Face and the llama.cpp team's Windows 11 tray app Llama manages a llama.cpp server for you and exposes it on an OpenAI-compatible endpoint. The walkthrough shows a .NET 11 file-based app that calls your downloaded open model through Microsoft.Extensions.AI's IChatClient, tools included.

Key points

  • Llama installs from the Microsoft Store with `winget install 9PPPSM6Q21Q6 --source msstore`, or from llama.app.
  • It serves models at localhost:9931 through OpenAI-format `/v1/chat/completions` and `/v1/models` endpoints, with no API key required.
  • The file-based app pulls Microsoft.Extensions.AI and Microsoft.Extensions.AI.OpenAI 11.0.0 via `#:package` directives, with no project file.
  • `AsIChatClient()` plus `UseFunctionInvocation()` turn the OpenAI client into an IChatClient and enable automatic tool calling.
  • GetMachineInfo and ListModels become tools through `AIFunctionFactory.Create`, with their `[Description]` text telling the model what each does.
  • Llama unloads a model after five idle minutes, so the first request against a cold model takes longer.

Why it matters

The interesting part is that an abstraction .NET developers already have keeps working when the model moves to their own machine. Pointing the OpenAI client at a different endpoint means code written against `IChatClient` switches to a local model with no rewrite, so a cloud-dependent prototype becomes a configuration change rather than a migration.

The caveats are hardware and model choice: context length and quantization level drive memory use, and tool calling is not guaranteed on every model. Models unload after five idle minutes, so measure that cold-start latency against your own timeouts before shipping anything user-facing. And since Llama is a .NET 10 / WinUI 3 Windows app, teams on macOS or Linux still need to stand up a llama.cpp server themselves.

Real-world use

  • A desktop chat assistant that keeps prompts and responses on the machine and works offline after the model downloads.
  • A diagnostics helper where the local model calls a tool to collect the machine name, OS, core count and .NET version.
  • An IChatClient chat loop that can report which models are downloaded and loaded without tying code to one provider.
  • Prototypes that want to try streaming responses and tool calling without paying per request.

This summary was generated by the agent from the original post on .NET Blog. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message