OllamaSharp 2.0.4
See the version list below for details.
dotnet add package OllamaSharp --version 2.0.4
NuGet\Install-Package OllamaSharp -Version 2.0.4
<PackageReference Include="OllamaSharp" Version="2.0.4" />
paket add OllamaSharp --version 2.0.4
#r "nuget: OllamaSharp, 2.0.4"
// Install OllamaSharp as a Cake Addin #addin nuget:?package=OllamaSharp&version=2.0.4 // Install OllamaSharp as a Cake Tool #tool nuget:?package=OllamaSharp&version=2.0.4
OllamaSharp 🦙
OllamaSharp is a .NET binding for the Ollama API, making it easy to interact with Ollama using your favorite .NET languages.
Features
- Intuitive API client: Set up and 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.
- API Console: A ready-to-use API console to chat and manage your Ollama host remotely
Usage
OllamaSharp wraps every Ollama API endpoint in awaitable methods that fully support response streaming.
The follow list shows a few examples to get a glimpse on how easy it is to use. The list is not complete.
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 = "llama2";
Listing all models that are available locally
var models = await ollama.ListLocalModels();
Pulling a model and reporting progress
Callback Syntax
await ollama.PullModel("mistral", status => Console.WriteLine($"({status.Percent}%) {status.Status}"));
IAsyncEnumerable Syntax
await foreach (var status in ollama.PullModel("mistral"))
{
Console.WriteLine($"({status.Percent}%) {status.Status}");
}
Streaming a completion directly into the console
Callback Syntax
// keep reusing the context to keep the chat topic going
ConversationContext context = null;
context = await ollama.StreamCompletion("How are you today?", context, stream => Console.Write(stream.Response));
IAsyncEnumerable Syntax
// keep reusing the context to keep the chat topic going
ConversationContext context = null;
await foreach (var stream in ollama.StreamCompletion("How are you today?", context))
{
Console.Write(stream.Response);
context = stream.Context;
}
Building interactive chats
// uses the /chat api from Ollama 0.1.14
// messages including their roles will automatically be tracked within the chat object
var chat = ollama.Chat(stream => Console.WriteLine(stream.Message?.Content ?? ""));
while (true)
{
var message = Console.ReadLine();
await chat.Send(message);
}
Api Console
This project ships a full-featured demo console for all endpoints the Ollama API is exposing.
This is not only a great resource to learn about OllamaSharp, it can also be used to manage and chat with the Ollama host remotely. Image chat is supported for multi modal models.
Credits
Icon and name were reused from the amazing Ollama project.
Product | Versions 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. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- System.Text.Json (>= 8.0.3)
NuGet packages (9)
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. |
|
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. |
|
Atc.SemanticKernel.Connectors.Ollama
Atc.SemanticKernel.Connectors.Ollama contains a connector for integrating with local llms through Ollama. |
GitHub repositories (5)
Showing the top 5 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
博客用到的代码
|
|
CommunityToolkit/Aspire
A community project with additional components and extensions for .NET Aspire
|
Version | Downloads | Last updated |
---|---|---|
4.0.6 | 2,158 | 11/7/2024 |
4.0.5 | 1,261 | 11/5/2024 |
4.0.4 | 253 | 11/4/2024 |
4.0.3 | 1,446 | 10/30/2024 |
4.0.2 | 237 | 10/29/2024 |
4.0.1 | 2,025 | 10/26/2024 |
4.0.0-preview.10 | 64 | 10/23/2024 |
4.0.0-preview.9 | 42 | 10/21/2024 |
4.0.0-preview.8 | 65 | 10/17/2024 |
3.0.15 | 2,532 | 10/21/2024 |
3.0.14 | 4,909 | 10/16/2024 |
3.0.13 | 70 | 10/16/2024 |
3.0.12 | 10,348 | 10/14/2024 |
3.0.11 | 1,233 | 10/9/2024 |
3.0.10 | 7,028 | 10/4/2024 |
3.0.9 | 86 | 10/4/2024 |
3.0.8 | 10,308 | 9/26/2024 |
3.0.7 | 13,827 | 9/12/2024 |
3.0.6 | 1,134 | 9/11/2024 |
3.0.5 | 778 | 9/11/2024 |
3.0.4 | 24,189 | 9/6/2024 |
3.0.3 | 102 | 9/6/2024 |
3.0.2 | 332 | 9/5/2024 |
3.0.1 | 15,144 | 9/2/2024 |
3.0.0 | 1,811 | 8/26/2024 |
2.1.3 | 2,467 | 8/23/2024 |
2.1.2 | 2,047 | 8/19/2024 |
2.1.1 | 4,081 | 8/5/2024 |
2.0.15 | 79 | 8/5/2024 |
2.0.14 | 92 | 8/3/2024 |
2.0.13 | 1,649 | 7/29/2024 |
2.0.12 | 95 | 7/28/2024 |
2.0.11 | 102 | 7/28/2024 |
2.0.10 | 3,570 | 7/12/2024 |
2.0.9 | 88 | 7/12/2024 |
2.0.8 | 122 | 7/12/2024 |
2.0.7 | 1,475 | 7/10/2024 |
2.0.6 | 3,070 | 6/25/2024 |
2.0.5 | 96 | 6/25/2024 |
2.0.4 | 562 | 6/24/2024 |
2.0.3 | 96 | 6/24/2024 |
2.0.2 | 136 | 6/24/2024 |
2.0.1 | 3,637 | 6/5/2024 |
1.1.13 | 170 | 6/5/2024 |
1.1.12 | 370 | 6/4/2024 |
1.1.11 | 285 | 6/2/2024 |
1.1.10 | 882 | 5/31/2024 |
1.1.9 | 6,296 | 5/15/2024 |
1.1.8 | 1,350 | 5/10/2024 |
1.1.7 | 110 | 5/10/2024 |
1.1.5 | 104 | 5/10/2024 |
1.1.4 | 148 | 5/10/2024 |
1.1.3 | 104 | 5/10/2024 |
1.1.2 | 107 | 5/10/2024 |
1.1.1 | 3,002 | 3/27/2024 |
1.1.0 | 1,760 | 1/8/2024 |
1.0.4 | 286 | 12/27/2023 |
1.0.3 | 328 | 11/30/2023 |
1.0.2 | 292 | 11/5/2023 |
1.0.1 | 182 | 10/16/2023 |
1.0.0 | 1,401 | 10/16/2023 |