OllamaSharp 3.0.11

There is a newer version of this package available.
See the version list below for details.
dotnet add package OllamaSharp --version 3.0.11
                    
NuGet\Install-Package OllamaSharp -Version 3.0.11
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OllamaSharp" Version="3.0.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OllamaSharp" Version="3.0.11" />
                    
Directory.Packages.props
<PackageReference Include="OllamaSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OllamaSharp --version 3.0.11
                    
#r "nuget: OllamaSharp, 3.0.11"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OllamaSharp@3.0.11
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OllamaSharp&version=3.0.11
                    
Install as a Cake Addin
#tool nuget:?package=OllamaSharp&version=3.0.11
                    
Install as a Cake Tool

<p align="center"> <img alt="ollama" height="200px" src="https://github.com/awaescher/OllamaSharp/blob/main/Ollama.png"> </p>

OllamaSharp 🦙

OllamaSharp provides .NET bindings for the Ollama API, simplifying interaction with Ollama both locally and remotely.

Features

  • Ease of use: Interact with Ollama in just a few lines of code.
  • API endpoint coverage: Support for all Ollama API endpoints including chats, embeddings, listing models, pulling and creating new models, and more.
  • Real-time streaming: Stream responses directly to your application.
  • Progress reporting: Get real-time progress feedback on tasks like model pulling.
  • Support for vision models and tools (function calling).

Usage

OllamaSharp wraps every Ollama API endpoint in awaitable methods that fully support response streaming.

The following list shows a few simple code examples.

Try our full-featured Ollama API client app OllamaSharpConsole to interact with your Ollama instance.

Initializing

// set up the client
var uri = new Uri("http://localhost:11434");
var ollama = new OllamaApiClient(uri);

// select a model which should be used for further operations
ollama.SelectedModel = "llama3.1:8b";

Listing all models that are available locally

var models = await ollama.ListLocalModels();

Pulling a model and reporting progress

await foreach (var status in ollama.PullModel("llama3.1:405b"))
    Console.WriteLine($"{status.Percent}% {status.Status}");

Generating a completion directly into the console

await foreach (var stream in ollama.Generate("How are you today?"))
    Console.Write(stream.Response);

Building interactive chats

var chat = new Chat(ollama);
while (true)
{
    var message = Console.ReadLine();
    await foreach (var answerToken in chat.Send(message))
        Console.Write(answerToken);
}
// messages including their roles and tool calls will automatically be tracked within the chat object
// and are accessible via the Messages property

Credits

Icon and name were reused from the amazing Ollama project.

I would like to thank all the contributors who take the time to improve OllamaSharp. First and foremost mili-tan, who always keeps OllamaSharp in sync with the Ollama API. ❤

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (22)

Showing the top 5 NuGet packages that depend on OllamaSharp:

Package Downloads
Microsoft.SemanticKernel.Connectors.Ollama

Semantic Kernel connector for Ollama. Contains services for text generation, chat completion and text embeddings.

Microsoft.KernelMemory.AI.Ollama

Provide access to Ollama LLM models in Kernel Memory to generate embeddings and text

CommunityToolkit.Aspire.Hosting.Ollama

An Aspire integration leveraging the Ollama container with support for downloading a model on startup.

CommunityToolkit.Aspire.OllamaSharp

A .NET Aspire client integration for the OllamaSharp library.

EnergyAssembly

Package Description

GitHub repositories (12)

Showing the top 12 popular GitHub repositories that depend on OllamaSharp:

Repository Stars
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
testcontainers/testcontainers-dotnet
A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
dotnet/extensions
This repository contains a suite of libraries that provide facilities commonly needed when creating production-ready applications.
microsoft/kernel-memory
RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.
microsoft/Generative-AI-for-beginners-dotnet
Five lessons, learn how to really apply AI to your .NET Applications
microsoft/ai-dev-gallery
An open-source project for Windows developers to learn how to add AI with local models and APIs to Windows apps.
mixcore/mix.core
🚀 A future-proof enterprise web CMS supporting both headless and decoupled approaches. Build any type of app with customizable APIs on ASP.NET Core/.NET Core. Completely open-source and designed for flexibility.
dotnet/ai-samples
CommunityToolkit/Aspire
A community project with additional components and extensions for .NET Aspire
PowerShell/AIShell
An interactive shell to work with AI-powered assistance providers
axzxs2001/Asp.NetCoreExperiment
原来所有项目都移动到**OleVersion**目录下进行保留。新的案例装以.net 5.0为主,一部分对以前案例进行升级,一部分将以前的工作经验总结出来,以供大家参考!
lindexi/lindexi_gd
博客用到的代码
Version Downloads Last Updated
5.4.1 529 9/11/2025
5.3.12 410 9/10/2025
5.3.11 122 9/10/2025
5.3.10 124 9/10/2025
5.3.9 124 9/10/2025
5.3.8 125 9/10/2025
5.3.7 125 9/10/2025
5.3.6 9,231 8/20/2025
5.3.5 12,405 8/18/2025
5.3.4 6,547 8/2/2025
5.3.3 4,658 7/22/2025
5.3.2 867 7/22/2025
5.3.1 1,435 7/19/2025
5.2.10 3,041 7/14/2025
5.2.9 3,139 7/13/2025
5.2.8 2,195 7/10/2025
5.2.7 2,944 7/7/2025
5.2.6 1,201 7/4/2025
5.2.5 508 7/4/2025
5.2.4 503 7/4/2025
5.2.3 31,435 6/23/2025
5.2.2 20,352 5/30/2025
5.2.1 590 5/30/2025
5.1.20 606 5/30/2025
5.1.19 3,556 5/23/2025
5.1.18 15,040 5/19/2025
5.1.17 1,070 5/16/2025
5.1.16 1,277 5/13/2025
5.1.15 457 5/13/2025
5.1.14 26,841 5/6/2025
5.1.13 10,807 4/10/2025
5.1.12 147,118 4/10/2025
5.1.11 3,927 4/9/2025
5.1.10 2,010 4/7/2025
5.1.9 4,316 3/27/2025
5.1.8 287 3/27/2025
5.1.7 78,583 3/14/2025
5.1.6 279 3/14/2025
5.1.5 1,104 3/13/2025
5.1.4 2,881 3/5/2025
5.1.3 558 3/4/2025
5.1.2 24,045 2/24/2025
5.1.1 1,244 2/21/2025
5.1.0 269 2/21/2025
5.0.7 35,880 2/17/2025
5.0.6 31,118 2/3/2025
5.0.5 1,391 1/31/2025
5.0.4 4,094 1/27/2025
5.0.3 3,408 1/22/2025
5.0.2 8,741 1/15/2025
5.0.1 484 1/15/2025
4.0.22 10,121 1/10/2025
4.0.21 217 1/9/2025
4.0.20 465 1/8/2025
4.0.19 148 1/8/2025
4.0.18 523 1/8/2025
4.0.17 37,359 1/3/2025
4.0.16 191 1/3/2025
4.0.15 194 1/3/2025
4.0.14 207 1/3/2025
4.0.13 185 1/3/2025
4.0.12 184 1/3/2025
4.0.11 34,499 12/9/2024
4.0.10 182 12/9/2024
4.0.9 1,937 12/2/2024
4.0.8 35,358 11/22/2024
4.0.7 4,211 11/13/2024
4.0.6 14,773 11/7/2024
4.0.5 1,404 11/5/2024
4.0.4 661 11/4/2024
4.0.3 31,568 10/30/2024
4.0.2 362 10/29/2024
4.0.1 2,311 10/26/2024
4.0.0-preview.10 140 10/23/2024
4.0.0-preview.9 97 10/21/2024
4.0.0-preview.8 119 10/17/2024
3.0.15 5,412 10/21/2024
3.0.14 10,978 10/16/2024
3.0.13 156 10/16/2024
3.0.12 21,750 10/14/2024
3.0.11 1,527 10/9/2024
3.0.10 26,050 10/4/2024
3.0.9 176 10/4/2024
3.0.8 17,838 9/26/2024
3.0.7 34,904 9/12/2024
3.0.6 1,278 9/11/2024
3.0.5 847 9/11/2024
3.0.4 26,740 9/6/2024
3.0.3 174 9/6/2024
3.0.2 633 9/5/2024
3.0.1 23,530 9/2/2024
3.0.0 2,212 8/26/2024
2.1.3 2,763 8/23/2024
2.1.2 2,695 8/19/2024
2.1.1 4,475 8/5/2024
2.0.15 296 8/5/2024
2.0.14 154 8/3/2024
2.0.13 2,002 7/29/2024
2.0.12 178 7/28/2024
2.0.11 248 7/28/2024
2.0.10 5,103 7/12/2024
2.0.9 156 7/12/2024
2.0.8 186 7/12/2024
2.0.7 1,825 7/10/2024
2.0.6 3,185 6/25/2024
2.0.5 169 6/25/2024
2.0.4 631 6/24/2024
2.0.3 162 6/24/2024
2.0.2 221 6/24/2024
2.0.1 4,085 6/5/2024
1.1.13 631 6/5/2024
1.1.12 612 6/4/2024
1.1.11 354 6/2/2024
1.1.10 1,362 5/31/2024
1.1.9 7,330 5/15/2024
1.1.8 1,424 5/10/2024
1.1.7 180 5/10/2024
1.1.5 171 5/10/2024
1.1.4 307 5/10/2024
1.1.3 177 5/10/2024
1.1.2 170 5/10/2024
1.1.1 3,679 3/27/2024
1.1.0 2,300 1/8/2024
1.0.4 359 12/27/2023
1.0.3 434 11/30/2023
1.0.2 443 11/5/2023
1.0.1 275 10/16/2023
1.0.0 2,176 10/16/2023