How can I help you?
Ollama Configuration
2 Apr 20268 minutes to read
The Syncfusion® Blazor Smart Rich Text Editor supports Ollama for running open-source models locally. This is ideal for privacy-conscious applications and development environments.
What is Ollama?
Ollama is a lightweight, open-source framework for running large language models locally on your machine. It provides:
- Privacy: All processing happens locally
- No API costs: No cloud service fees
- Offline capability: Works without internet connection
- Model variety: Access to many open-source models
- Easy setup: Simple installation and management
Prerequisites
- Windows 10/11, macOS, or Linux
- At least 8GB RAM (16GB+ recommended)
- GPU support optional but recommended for performance
- Docker (optional, for containerized deployment)
Installation
Step 1: Download and Install Ollama
Visit Ollama’s Official Website and download the installer for your operating system.
Windows
- Download the Windows installer
- Run the installer and follow the setup wizard
- Accept default installation path or customize
- Complete installation
macOS
- Download the macOS installer
- Open the
.dmg file - Drag Ollama to Applications folder
- Launch from Applications
Linux
Use the installation script:
curl https://ollama.ai/install.sh | shStep 2: Verify Installation
Open a terminal/command prompt and verify:
ollama --versionStep 3: Start Ollama Service
Windows
Ollama starts automatically. Access at http://localhost:11434
macOS/Linux
Start the Ollama service:
ollama serveInstalling Models
Available Models
Browse available models at Ollama Library
Popular models for text generation:
-
Mistral:
mistral- Fast, efficient -
Llama 2:
llama2- General purpose -
Neural Chat:
neural-chat- Conversational -
Orca Mini:
orca-mini- Lightweight -
Dolphin:
dolphin-mixtral- Advanced
Install a Model
ollama pull mistralThis downloads and prepares the model (may take several minutes).
List Installed Models
ollama listRun a Model Directly
Test the model:
ollama run mistralType your prompt and press Enter. Type /bye to exit.
Configuration in Blazor
Note: OllamaSharp is a community package for local model integration. Ensure compliance with your organization’s policy on third-party NuGet packages before using in production.
Installation
Install required NuGet packages:
Install-Package Syncfusion.Blazor.SmartRichTextEditor
Install-Package Syncfusion.Blazor.Themes
Install-Package Microsoft.Extensions.AI
Install-Package OllamaSharpSetup in Program.cs
using Syncfusion.Blazor;
using Syncfusion.Blazor.AI;
using Microsoft.Extensions.AI;
using OllamaSharp;
var builder = WebApplication.CreateBuilder(args);
// Add services
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSyncfusionBlazor();
// Configure Ollama
string ollamaEndpoint = "http://localhost:11434";
string modelName = "mistral"; // or any other installed model
// Create Ollama client
IOllamaApiClient ollamaClient = new OllamaApiClient(ollamaEndpoint, modelName);
// Convert to IChatClient
IChatClient chatClient = ollamaClient;
builder.Services.AddChatClient(chatClient);
// Register Smart Rich Text Editor Components with Azure OpenAI
builder.Services.AddSingleton<IChatInferenceService, SyncfusionAIService>();
var app = builder.Build();
// ... rest of setupAdd to _Imports.razor
@using Syncfusion.Blazor
@using Syncfusion.Blazor.SmartRichTextEditorUse Ollama AI with Smart Rich Text Editor Component
@using Syncfusion.Blazor.SmartRichTextEditor
<SfSmartRichTextEditor>
<AssistViewSettings Placeholder="Edit with local AI assistance..."/>
<div>
<h3>Ollama + Smart Rich Text Editor</h3>
<p>Use AI Commands to improve selected text or change tone.</p>
<ul>
<li>Select text and request suggestions</li>
<li>Press Alt+Enter for AI Query</li>
</ul>
</div>
</SfSmartRichTextEditor>Configuration Options
Custom Endpoint
If Ollama runs on different host/port:
string ollamaEndpoint = "http://192.168.1.100:11434";
IOllamaApiClient ollamaClient = new OllamaApiClient(ollamaEndpoint, "mistral");Model Parameters
Configure model behavior:
// Create client with parameters
IOllamaApiClient ollamaClient = new OllamaApiClient("http://localhost:11434", "mistral");
// Set parameters (varies by OllamaSharp version)
var request = new GenerateRequest
{
Model = "mistral",
Prompt = "Your prompt",
Temperature = 0.7f,
TopK = 40,
TopP = 0.9f,
};Dynamic Model Selection
// Read model name from configuration
string modelName = builder.Configuration["Ollama:ModelName"] ?? "mistral";
string endpoint = builder.Configuration["Ollama:Endpoint"] ?? "http://localhost:11434";
IOllamaApiClient ollamaClient = new OllamaApiClient(endpoint, modelName);Docker Deployment
Docker Compose Setup
version: '3.8'
services:
ollama:
image: ollama/ollama:latest
ports:
- "11434:11434"
volumes:
- ollama_data:/root/.ollama
environment:
- OLLAMA_HOST=0.0.0.0:11434
volumes:
ollama_data:Start with Docker
docker-compose up -dPull Models in Container
docker exec -it <container-id> ollama pull mistralAdvanced Configuration
Multiple Models
Run different models for different purposes:
// For general editing
var generalClient = new OllamaApiClient("http://localhost:11434", "mistral");
// For code-related tasks
var codeClient = new OllamaApiClient("http://localhost:11434", "neural-chat");
// Conditionally use based on context
IChatClient chatClient = useForCode ? codeClient : generalClient;Performance Optimization
Tips for Better Performance
-
Use GPU Acceleration
- NVIDIA GPUs: Install CUDA toolkit
- AMD GPUs: Install ROCm
- Intel GPUs: Install Intel oneAPI
-
Increase Memory Allocation
# Linux/macOS export OLLAMA_NUM_PARALLEL=1 ollama serve -
Choose Efficient Models
- Mistral is fastest
-
Orca-minifor lightweight deployment -
Dolphin-mixtralfor best quality
-
Implement Caching
- Cache common prompts
- Reuse model responses
-
Optimize Request Size
- Keep prompts concise
- Limit response length with max tokens
Troubleshooting
Connection Issues
Error: Unable to connect to Ollama
- Verify Ollama is running:
curl http://localhost:11434/api/tags -
Check endpoint configuration in Program.cs
- If running on different machine, update endpoint URL
Model Issues
Model not found
# List available models
ollama list
# Pull the model
ollama pull mistralOut of memory errors
- Use smaller models (
orca-mini,mistral) - Close other applications
- Restart Ollama service
Performance Issues
Slow response times
- Check CPU/GPU usage
- Enable GPU acceleration if available
- Use faster models
- Increase system RAM
Model Recommendations
| Use Case | Model | Pros | Cons |
|---|---|---|---|
| General editing | Mistral | Fast, good quality | Less context |
| Content creation | Llama 2 | Balanced | Larger model |
| Code assistance | Neural-chat | Good reasoning | Slower |
| Lightweight | Orca-mini | Very fast | Limited capability |
| Best quality | Dolphin-mixtral | Excellent | Resource heavy |
Security Considerations
Local Processing Benefits
- All data stays on your machine
- No external API calls
- Compliance with data regulations
- Full control over data retention
Best Practices
- Restrict network access to Ollama
- Use firewall rules if networked
- Keep Ollama updated
- Monitor resource usage