Koan.Ai.Provider.Ollama
0.5.2
dotnet add package Koan.Ai.Provider.Ollama --version 0.5.2
NuGet\Install-Package Koan.Ai.Provider.Ollama -Version 0.5.2
<PackageReference Include="Koan.Ai.Provider.Ollama" Version="0.5.2" />
<PackageVersion Include="Koan.Ai.Provider.Ollama" Version="0.5.2" />
<PackageReference Include="Koan.Ai.Provider.Ollama" />
paket add Koan.Ai.Provider.Ollama --version 0.5.2
#r "nuget: Koan.Ai.Provider.Ollama, 0.5.2"
#:package Koan.Ai.Provider.Ollama@0.5.2
#addin nuget:?package=Koan.Ai.Provider.Ollama&version=0.5.2
#tool nuget:?package=Koan.Ai.Provider.Ollama&version=0.5.2
Sylin.Koan.Ai.Provider.Ollama
Ollama AI provider for Koan: local LLM chat, stream, and embeddings via Ollama endpoint.
- Target framework: net9.0
- License: Apache-2.0
Install
dotnet add package Sylin.Koan.Ai.Provider.Ollama
Minimal setup
Register Koan + the Ollama provider (typical ASP.NET Program.cs):
// using Koan.AI; using Koan.Ai.Provider.Ollama; using Koan.AI.Web;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddKoan()
.AddAi()
.AddOllama(o =>
{
o.BaseAddress = new Uri("http://localhost:11434"); // default
o.DefaultModel = "qwen3:4b"; // or any local model/tag
})
.AddAiWeb(); // optional HTTP endpoints under /ai
var app = builder.Build();
app.MapControllers();
app.Run();
Then query the default engine:
using Koan.AI;
var res = await Engine.Prompt("Explain quantum entanglement briefly.");
Console.WriteLine(res.Text);
Or via HTTP (if AddAiWeb is enabled):
POST /ai/chat { "model": "qwen3:4b", "messages": [{ "role": "user", "content": "Explain quantum entanglement briefly." }] }
Using reasoning (think)
Set the optional think flag in prompt options. The Ollama adapter emits a top-level think
in its JSON payload for models that support it (e.g., Qwen3/R1/DeepSeek‑V3.1 quants).
using Koan.AI;
using Koan.AI.Contracts.Models;
var res = await Engine.Prompt(
"Briefly explain quantum entanglement.",
model: "qwen3:4b",
opts: new AiPromptOptions { Think = true }
);
Console.WriteLine(res.Text);
HTTP example:
POST /ai/chat { "model": "qwen3:4b", "messages": [{ "role": "user", "content": "Explain quantum entanglement briefly." }], "options": { "think": true } }
Vendor-specific options (passthrough)
Unknown fields posted under options
are forwarded to Ollama’s options
bag in the request. Use this for provider-specific parameters like mirostat
, repeat_penalty
, etc. Known Koan fields still map to Ollama (temperature
, top_p
, num_predict
, stop
). If keys overlap, your posted value wins.
HTTP example:
POST /ai/chat { "model": "qwen3:4b", "messages": [{ "role": "user", "content": "Summarize Bell’s theorem in one sentence." }], "options": { "temperature": 0.6, "topP": 0.95, "maxOutputTokens": 128, "mirostat": 2, "mirostat_tau": 5.0, "repeat_penalty": 1.1 } }
Programmatic example:
using Koan.AI;
using Koan.AI.Contracts.Models;
var opts = new AiPromptOptions
{
Temperature = 0.6,
TopP = 0.95,
MaxOutputTokens = 128,
// Add arbitrary vendor params via object initializer syntax in JSON calls
};
var res = await Engine.Prompt("Summarize Bell’s theorem in one sentence.", "qwen3:4b", opts);
Notes
- The Web API uses
messages[]
instead of a top-levelprompt
. - Embeddings are supported via POST /ai/embeddings with
model
andinput
(array of strings). - Streaming is supported via POST /ai/chat/stream with the same body as /ai/chat.
Links
- Ollama: https://ollama.com
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Koan.AI.Contracts (>= 0.5.2)
- Koan.Core (>= 0.5.2)
- Koan.Orchestration.Abstractions (>= 0.5.2)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
0.5.2 | 271 | 9/16/2025 |
See release notes: https://github.com/sylin-labs/Koan-framework/releases