TimHanewich.Ollama
0.1.0
dotnet add package TimHanewich.Ollama --version 0.1.0
NuGet\Install-Package TimHanewich.Ollama -Version 0.1.0
<PackageReference Include="TimHanewich.Ollama" Version="0.1.0" />
<PackageVersion Include="TimHanewich.Ollama" Version="0.1.0" />
<PackageReference Include="TimHanewich.Ollama" />
paket add TimHanewich.Ollama --version 0.1.0
#r "nuget: TimHanewich.Ollama, 0.1.0"
#:package TimHanewich.Ollama@0.1.0
#addin nuget:?package=TimHanewich.Ollama&version=0.1.0
#tool nuget:?package=TimHanewich.Ollama&version=0.1.0
TimHanewich.Ollama

TimHanewich.Ollama is a lightweight .NET library for interfacing with local language models running via Ollama. It provides a clean, strongly-typed interface for chatting with models, making tool (function) calls, and receiving structured JSON outputs.
Key Features
- 💬 Chat Completions: Simple, strongly-typed request/response model for the Ollama Chat API.
- 🛠️ Function Calling: Native support for defining tools and handling tool calls from the model.
- 📦 JSON Mode: Built-in support for structured JSON outputs from the model.
- 🧠 Thinking Tokens: Access model reasoning/thinking tokens when available.
Installing
TimHanewich.Ollama is available on NuGet! Install it by running:
dotnet add package TimHanewich.Ollama
Example Use
Below are some examples on how to use this library. These examples assume you have Ollama installed and running locally on the default port (11434).
Basic Prompting
using TimHanewich.Ollama;
ChatRequest req = new ChatRequest();
req.Model = "qwen3.5:0.8b";
req.Messages.Add(new Message(Role.user, "Why is the sky blue?"));
OllamaClient ollama = new OllamaClient();
ChatResponse resp = await ollama.ChatAsync(req);
Console.WriteLine("Model: " + resp.Model);
Console.WriteLine("Input tokens: " + resp.InputTokens.ToString());
Console.WriteLine("Output tokens: " + resp.OutputTokens.ToString());
Console.WriteLine("Response: " + resp.Message.Content);
Function Calling (Tools)
You can define tools the model can call and then handle the results:
using TimHanewich.Ollama;
using Newtonsoft.Json.Linq;
ChatRequest req = new ChatRequest();
req.Model = "qwen3.5:0.8b";
req.Messages.Add(new Message(Role.user, "What is the temperature in Chicago?"));
// Define a tool
Tool t = new Tool("check_weather", "Check the weather for any city.");
t.Parameters.Add(new ToolInputParameter("city", "The name of the city to check the weather for"));
req.Tools.Add(t);
// Call the model
OllamaClient ollama = new OllamaClient();
ChatResponse resp = await ollama.ChatAsync(req);
// Handle tool calls
foreach (ToolCall tc in resp.Message.ToolCalls)
{
if (tc.ToolName == "check_weather")
{
JProperty? prop_city = tc.Arguments.Property("city");
if (prop_city != null)
{
string city = prop_city.Value.ToString();
Console.WriteLine("Model wants weather for: " + city);
}
}
}
Providing a Tool Call Result
After the model makes a tool call, provide the result and re-prompt:
// Add the assistant's message (with tool calls) back into the conversation
req.Messages.Add(resp.Message);
// Add the tool response
Message tool_response = new Message();
tool_response.Role = Role.tool;
tool_response.Content = "Weather in Chicago: 72°F and sunny.";
req.Messages.Add(tool_response);
// Re-prompt the model with the tool result
ChatResponse resp2 = await ollama.ChatAsync(req);
Console.WriteLine("Response: " + resp2.Message.Content);
JSON Mode
Force the model to respond with structured JSON:
ChatRequest req = new ChatRequest();
req.Model = "qwen3.5:0.8b";
req.JsonMode = true;
req.Messages.Add(new Message(Role.user, "List three colors and their hex codes as a JSON array."));
OllamaClient ollama = new OllamaClient();
ChatResponse resp = await ollama.ChatAsync(req);
Console.WriteLine(resp.Message.Content); // structured JSON output
| 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 is compatible. 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. |
-
net10.0
- Newtonsoft.Json (>= 13.0.3)
-
net9.0
- 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.1.0 | 105 | 4/16/2026 |