Cloud-based AI models like GPT-4 are powerful, but they come with trade-offs: latency, cost, and privacy. If you’re analyzing sensitive server logs or PII, sending that data to the cloud might be a non-starter.
In this post, we’ll build a Local Log Analyzer that runs entirely on your machine using Ollama and .NET.
Why Local AI?#
- Privacy: Your data never leaves your network.
- Cost: Zero API fees, no matter how many tokens you process.
- Latency: No network round-trips; speed depends entirely on your hardware.
- Offline: Works on an air-gapped server or a plane.
The Stack#
- Ollama: A lightweight tool to run models like Llama 3, Phi-3, or Mistral locally.
- Semantic Kernel: The .NET SDK to orchestrate the interaction.
- Llama 3 (8B): A powerful, efficient model that runs well on most modern laptops (requires ~8GB RAM).
Step 1: Setup Ollama#
Download Ollama from ollama.com. Once installed, pull the model we’ll use:
| |
By default, Ollama starts a local API server at http://localhost:11434.
Step 2: The Code (Log Analyzer)#
We’ll write a C# program that reads a raw, messy error log and asks the local AI to extract the key details into a clean format.
Prerequisites:
| |
The Code:
| |
Expected Output#
Because this runs locally, you’ll see the output appear almost instantly (depending on your GPU/CPU).
| |
Advanced Tips for Local Models#
Context Window Management#
Local models often have smaller context windows (e.g., 4k or 8k tokens) compared to cloud models (128k). If you’re analyzing huge log files, you’ll need to split them into chunks.
Temperature Settings#
For extraction tasks like this, you want the model to be precise, not creative. When creating your request, set the Temperature to 0.
| |
Hardware Requirements#
- 7B/8B Models (Llama 3, Mistral): Require ~8GB RAM. Runs decent on CPU, fast on Apple Silicon/NVIDIA.
- Phi-3 (3.8B): Requires ~4GB RAM. Runs great on almost anything.
- 70B Models: Require ~48GB RAM. You’ll need a serious workstation or Mac Studio.
Running AI locally puts you in full control. Whether for privacy compliance or just building cool tools that work offline, the combination of Ollama and .NET is incredibly potent.
Further Reading#
- Ollama Documentation - Official Ollama documentation
- Ollama Model Library - Browse available models
- Semantic Kernel Local Models - Using local models with SK
- Phi-3 Model Card - Details on Microsoft’s Phi-3 model
