Ollama 1.9.0
dotnet add package Ollama --version 1.9.0
NuGet\Install-Package Ollama -Version 1.9.0
<PackageReference Include="Ollama" Version="1.9.0" />
paket add Ollama --version 1.9.0
#r "nuget: Ollama, 1.9.0"
// Install Ollama as a Cake Addin #addin nuget:?package=Ollama&version=1.9.0 // Install Ollama as a Cake Tool #tool nuget:?package=Ollama&version=1.9.0
Ollama SDK for .NET 🦙
Features 🔥
- Fully generated C# SDK based on OpenAPI specification using OpenApiGenerator
- Automatic releases of new preview versions if there was an update to the OpenAPI specification
- Source generator to define tools natively through C# interfaces
- All modern .NET features - nullability, trimming, NativeAOT, etc.
- Support .Net Framework/.Net Standard 2.0
- Support for all Ollama API endpoints including chats, embeddings, listing models, pulling and creating new models, and more.
Usage
Initializing
using var ollama = new OllamaApiClient();
var models = await ollama.Models.ListModelsAsync();
// Pulling a model and reporting progress
await foreach (var response in ollama.PullModelAsync("all-minilm", stream: true))
{
Console.WriteLine($"{response.Status}. Progress: {response.Completed}/{response.Total}");
}
// or just pull the model and wait for it to finish
await ollama.Models.PullModelAsync("all-minilm").EnsureSuccessAsync();
// Generating an embedding
var embedding = await ollama.Embeddings.GenerateEmbeddingAsync(
model: "all-minilm",
prompt: "hello");
// Streaming a completion directly into the console
// keep reusing the context to keep the chat topic going
IList<long>? context = null;
var enumerable = ollama.Completions.GenerateCompletionAsync("llama3", "answer 5 random words");
await foreach (var response in enumerable)
{
Console.WriteLine($"> {response.Response}");
context = response.Context;
}
var lastResponse = await ollama.Completions.GenerateCompletionAsync("llama3", "answer 123", stream: false, context: context).WaitAsync();
Console.WriteLine(lastResponse.Response);
var chat = ollama.Chat("mistral");
while (true)
{
var message = await chat.SendAsync("answer 123");
Console.WriteLine(message.Content);
var newMessage = Console.ReadLine();
await chat.Send(newMessage);
}
Tools
using var ollama = new OllamaApiClient();
var chat = ollama.Chat(
model: "llama3.1",
systemMessage: "You are a helpful weather assistant.",
autoCallTools: true);
var service = new WeatherService();
chat.AddToolService(service.AsTools(), service.AsCalls());
try
{
_ = await chat.SendAsync("What is the current temperature in Dubai, UAE in Celsius?");
}
finally
{
Console.WriteLine(chat.PrintMessages());
}
> System:
You are a helpful weather assistant.
> User:
What is the current temperature in Dubai, UAE in Celsius?
> Assistant:
Tool calls:
GetCurrentWeather({"location":"Dubai, UAE","unit":"celsius"})
> Tool:
{"location":"Dubai, UAE","temperature":22,"unit":"celsius","description":"Sunny"}
> Assistant:
The current temperature in Dubai, UAE is 22°C.
public enum Unit
{
Celsius,
Fahrenheit,
}
public class Weather
{
public string Location { get; set; } = string.Empty;
public double Temperature { get; set; }
public Unit Unit { get; set; }
public string Description { get; set; } = string.Empty;
}
[OllamaTools]
public interface IWeatherFunctions
{
[Description("Get the current weather in a given location")]
public Task<Weather> GetCurrentWeatherAsync(
[Description("The city and state, e.g. San Francisco, CA")] string location,
Unit unit = Unit.Celsius,
CancellationToken cancellationToken = default);
}
public class WeatherService : IWeatherFunctions
{
public Task<Weather> GetCurrentWeatherAsync(string location, Unit unit = Unit.Celsius, CancellationToken cancellationToken = default)
{
return Task.FromResult(new Weather
{
Location = location,
Temperature = 22.0,
Unit = unit,
Description = "Sunny",
});
}
}
Credits
Icon and name were reused from the amazing Ollama project.
The project was forked from this repository,
after which automatic code generation was applied based on this OpenAPI specification
(in the future it will be replaced by the official one, if one appears)
Support
Priority place for bugs: https://github.com/tryAGI/Ollama/issues
Priority place for ideas and general questions: https://github.com/tryAGI/Ollama/discussions
Discord: https://discord.gg/Ca2xhfBf3v
Acknowledgments
This project is supported by JetBrains through the Open Source Support Program.
This project is supported by CodeRabbit through the Open Source Support Program.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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 is compatible. 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. |
-
.NETFramework 4.6.2
- System.Text.Json (>= 8.0.4)
-
.NETStandard 2.0
- System.Text.Json (>= 8.0.4)
-
net6.0
- System.Text.Json (>= 8.0.4)
-
net8.0
- System.Text.Json (>= 8.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Ollama:
Package | Downloads |
---|---|
LangChain.Providers.Ollama
Ollama Chat model provider. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.9.0 | 135 | 9/1/2024 |
1.8.1 | 144 | 8/24/2024 |
1.8.1-dev.1 | 41 | 8/24/2024 |
1.8.0 | 72 | 8/24/2024 |
1.7.2-dev.9 | 45 | 8/21/2024 |
1.7.2-dev.8 | 43 | 8/20/2024 |
1.7.2-dev.5 | 43 | 8/19/2024 |
1.7.2-dev.4 | 38 | 8/19/2024 |
1.7.2-dev.3 | 45 | 8/19/2024 |
1.7.2-dev.2 | 50 | 8/16/2024 |
1.7.2-dev.1 | 43 | 8/16/2024 |
1.7.1 | 149 | 8/16/2024 |
1.7.1-dev.1 | 50 | 8/16/2024 |
1.7.0 | 80 | 8/16/2024 |
1.6.2-dev.19 | 41 | 8/16/2024 |
1.6.2-dev.12 | 50 | 8/15/2024 |
1.6.2-dev.10 | 45 | 8/13/2024 |
1.6.2-dev.9 | 37 | 8/13/2024 |
1.6.2-dev.7 | 34 | 8/12/2024 |
1.6.2-dev.6 | 29 | 8/12/2024 |
1.6.2-dev.5 | 34 | 8/12/2024 |
1.6.2-dev.4 | 36 | 8/6/2024 |
1.6.2-dev.3 | 29 | 8/6/2024 |
1.6.2-dev.2 | 35 | 8/5/2024 |
1.6.1 | 125 | 7/30/2024 |
1.6.1-dev.7 | 28 | 7/30/2024 |
1.6.1-dev.6 | 25 | 7/29/2024 |
1.6.1-dev.4 | 39 | 7/29/2024 |
1.6.1-dev.3 | 41 | 7/29/2024 |
1.6.1-dev.2 | 36 | 7/29/2024 |
1.6.1-dev.1 | 39 | 7/29/2024 |
1.6.0 | 71 | 7/29/2024 |
1.5.2-dev.2 | 42 | 7/29/2024 |
1.5.2-dev.1 | 51 | 7/25/2024 |
1.5.1 | 88 | 7/25/2024 |
1.4.3 | 824 | 7/14/2024 |
1.4.2 | 70 | 7/12/2024 |
1.4.1 | 103 | 7/8/2024 |
1.3.2 | 1,271 | 6/6/2024 |
1.3.1 | 85 | 6/5/2024 |
1.3.0 | 85 | 6/5/2024 |
1.2.0 | 139 | 5/26/2024 |
1.1.3 | 117 | 5/23/2024 |
1.1.2 | 95 | 5/22/2024 |
1.1.1 | 350 | 5/21/2024 |
1.1.0 | 98 | 5/20/2024 |
1.0.0 | 231 | 5/12/2024 |
0.9.4 | 74 | 5/11/2024 |
0.9.3 | 67 | 5/11/2024 |
0.9.2 | 69 | 5/11/2024 |
0.9.0 | 81 | 5/10/2024 |
0.0.0-dev.53 | 40 | 7/25/2024 |
0.0.0-dev.52 | 49 | 7/25/2024 |