OllamaSharp 3.0.8

dotnet add package OllamaSharp --version 3.0.8                
NuGet\Install-Package OllamaSharp -Version 3.0.8                
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.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OllamaSharp --version 3.0.8                
#r "nuget: OllamaSharp, 3.0.8"                
#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.
// Install OllamaSharp as a Cake Addin
#addin nuget:?package=OllamaSharp&version=3.0.8

// Install OllamaSharp as a Cake Tool
#tool nuget:?package=OllamaSharp&version=3.0.8                

<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. 
.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 (7)

Showing the top 5 NuGet packages that depend on OllamaSharp:

Package Downloads
Microsoft.KernelMemory.AI.Ollama

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

Microsoft.SemanticKernel.Connectors.Ollama

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

Atc.SemanticKernel.Connectors.Ollama

Atc.SemanticKernel.Connectors.Ollama contains a connector for integrating with local llms through Ollama.

Dependify.Aspire.Hosting.Ollama

Ollama support for .NET Aspire.

JinHao.CodeEase.DesignerManagement.Application

Package Description

GitHub repositories (4)

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

Repository Stars
microsoft/kernel-memory
RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.
dotnet/ai-samples
platformplatform/PlatformPlatform
🚀 Pre-alpha state. A platform designed for building enterprise-grade, multi-tenant products using Azure, .NET, React, TypeScript, Infrastructure as Code, etc.
lindexi/lindexi_gd
博客用到的代码
Version Downloads Last updated
3.0.8 110 9/26/2024
3.0.7 7,366 9/12/2024
3.0.6 797 9/11/2024
3.0.5 718 9/11/2024
3.0.4 10,160 9/6/2024
3.0.3 88 9/6/2024
3.0.2 169 9/5/2024
3.0.1 8,720 9/2/2024
3.0.0 1,549 8/26/2024
2.1.3 2,287 8/23/2024
2.1.2 1,838 8/19/2024
2.1.1 3,960 8/5/2024
2.0.15 59 8/5/2024
2.0.14 82 8/3/2024
2.0.13 1,456 7/29/2024
2.0.12 91 7/28/2024
2.0.11 97 7/28/2024
2.0.10 3,214 7/12/2024
2.0.9 81 7/12/2024
2.0.8 117 7/12/2024
2.0.7 1,394 7/10/2024
2.0.6 3,038 6/25/2024
2.0.5 94 6/25/2024
2.0.4 523 6/24/2024
2.0.3 92 6/24/2024
2.0.2 103 6/24/2024
2.0.1 3,597 6/5/2024
1.1.13 167 6/5/2024
1.1.12 298 6/4/2024
1.1.11 281 6/2/2024
1.1.10 729 5/31/2024
1.1.9 5,318 5/15/2024
1.1.8 1,318 5/10/2024
1.1.7 108 5/10/2024
1.1.5 101 5/10/2024
1.1.4 137 5/10/2024
1.1.3 101 5/10/2024
1.1.2 103 5/10/2024
1.1.1 2,876 3/27/2024
1.1.0 1,650 1/8/2024
1.0.4 277 12/27/2023
1.0.3 312 11/30/2023
1.0.2 281 11/5/2023
1.0.1 175 10/16/2023
1.0.0 1,353 10/16/2023