Covers core local LLM concepts using native .NET libraries.
| Technology | Purpose |
|---|---|
| LLamaSharp 0.27 | Runs GGUF models locally |
Microsoft.Extensions.AI (IChatClient) | Standard AI abstraction layer |
| Microsoft.Extensions.AI | Chat history pattern / memory |
| Blazor Server | Chat UI |
LLamaSharp.Backend.Cuda12 for CPU/GPU Hybrid mode)Download Llama-3.2-3B-Instruct-Q4_K_M.gguf from Hugging Face and place it in the models/ folder:
https://huggingface.co/hugging-quants/Llama-3.2-3B-Instruct-Q4_K_M-GGUF
The folder structure should look like:
local-llm-csharp/
└── models/
└── Llama-3.2-3B-Instruct-Q4_K_M.gguf ← place it here
You can also set a
MODEL_PATHenvironment variable to point to any GGUF file elsewhere on disk.
dotnet run --project LocalLlm.Console
Pick a demo from the interactive menu:
| # | Demo | Description |
|---|---|---|
| 1 | Simple Completion | Run one prompt, print result |
| 2 | Streaming Answer | Stream tokens to console as they arrive |
| 3 | Chat Prompt Engineering | Manually build system/user/response prompt format |
| 4 | Conversational Memory | Maintain history, inject into prompt |
| 5 | Agent Demo (MEAI) | Use IChatClient and session memory |
dotnet run --project LocalLlm.Web
Open https://localhost:5001 in your browser for the chat interface.
This project is configured to use LLamaSharp.Backend.Cuda12 with gpuLayerCount: 35.
Because the Llama-3.2-3B-Instruct-Q4_K_M model is small enough (~1.9 GB), this offloads 100% of the layers to your GTX VRAM.
If you decide to use a larger model that exceeds your 3GB of VRAM, you can lower the gpuLayerCount in Program.cs. This will act in a true hybrid mode, keeping some layers on your GPU and falling back to your CPU and system RAM for the rest!
If you don't have an NVIDIA GPU, edit both .csproj files:
- <PackageReference Include="LLamaSharp.Backend.Cuda12" Version="0.27.0" />
+ <PackageReference Include="LLamaSharp.Backend.Cpu" Version="0.27.0" />
Then run dotnet restore and inference will use only the CPU.
local-llm-csharp/
├── LocalLlm.sln
├── README.md
├── models/ ← Put your .gguf file here
├── LocalLlm.Console/ ← Console demos (Phase 1)
│ ├── Program.cs
│ ├── ModelLoader.cs
│ ├── LlamaSharpChatClient.cs ← IChatClient bridge
│ └── Demos/
│ ├── SimpleCompletionDemo.cs
│ ├── StreamAnswerDemo.cs
│ ├── ChatPromptDemo.cs
│ ├── ConversationalMemoryDemo.cs
│ └── AgentDemo.cs
└── LocalLlm.Web/ ← Blazor chat UI (Phase 2)
├── Program.cs
├── LlamaSharpChatClient.cs
└── Components/Pages/Chat.razor
Covers core local LLM concepts using native .NET libraries.
| Technology | Purpose |
|---|---|
| LLamaSharp 0.27 | Runs GGUF models locally |
Microsoft.Extensions.AI (IChatClient) | Standard AI abstraction layer |
| Microsoft.Extensions.AI | Chat history pattern / memory |
| Blazor Server | Chat UI |
LLamaSharp.Backend.Cuda12 for CPU/GPU Hybrid mode)Download Llama-3.2-3B-Instruct-Q4_K_M.gguf from Hugging Face and place it in the models/ folder:
https://huggingface.co/hugging-quants/Llama-3.2-3B-Instruct-Q4_K_M-GGUF
The folder structure should look like:
local-llm-csharp/
└── models/
└── Llama-3.2-3B-Instruct-Q4_K_M.gguf ← place it here
You can also set a
MODEL_PATHenvironment variable to point to any GGUF file elsewhere on disk.
dotnet run --project LocalLlm.Console
Pick a demo from the interactive menu:
| # | Demo | Description |
|---|---|---|
| 1 | Simple Completion | Run one prompt, print result |
| 2 | Streaming Answer | Stream tokens to console as they arrive |
| 3 | Chat Prompt Engineering | Manually build system/user/response prompt format |
| 4 | Conversational Memory | Maintain history, inject into prompt |
| 5 | Agent Demo (MEAI) | Use IChatClient and session memory |
dotnet run --project LocalLlm.Web
Open https://localhost:5001 in your browser for the chat interface.
This project is configured to use LLamaSharp.Backend.Cuda12 with gpuLayerCount: 35.
Because the Llama-3.2-3B-Instruct-Q4_K_M model is small enough (~1.9 GB), this offloads 100% of the layers to your GTX VRAM.
If you decide to use a larger model that exceeds your 3GB of VRAM, you can lower the gpuLayerCount in Program.cs. This will act in a true hybrid mode, keeping some layers on your GPU and falling back to your CPU and system RAM for the rest!
If you don't have an NVIDIA GPU, edit both .csproj files:
- <PackageReference Include="LLamaSharp.Backend.Cuda12" Version="0.27.0" />
+ <PackageReference Include="LLamaSharp.Backend.Cpu" Version="0.27.0" />
Then run dotnet restore and inference will use only the CPU.
local-llm-csharp/
├── LocalLlm.sln
├── README.md
├── models/ ← Put your .gguf file here
├── LocalLlm.Console/ ← Console demos (Phase 1)
│ ├── Program.cs
│ ├── ModelLoader.cs
│ ├── LlamaSharpChatClient.cs ← IChatClient bridge
│ └── Demos/
│ ├── SimpleCompletionDemo.cs
│ ├── StreamAnswerDemo.cs
│ ├── ChatPromptDemo.cs
│ ├── ConversationalMemoryDemo.cs
│ └── AgentDemo.cs
└── LocalLlm.Web/ ← Blazor chat UI (Phase 2)
├── Program.cs
├── LlamaSharpChatClient.cs
└── Components/Pages/Chat.razor