LlmTornado 3.0.3
See the version list below for details.
dotnet add package LlmTornado --version 3.0.3
NuGet\Install-Package LlmTornado -Version 3.0.3
<PackageReference Include="LlmTornado" Version="3.0.3" />
paket add LlmTornado --version 3.0.3
#r "nuget: LlmTornado, 3.0.3"
// Install LlmTornado as a Cake Addin #addin nuget:?package=LlmTornado&version=3.0.3 // Install LlmTornado as a Cake Tool #tool nuget:?package=LlmTornado&version=3.0.3
🌪️ LLM Tornado - one .NET library to consume OpenAI, Anthropic, Cohere, Azure, and self-hosted APIs.
Each month at least one new large language model is released. Would it be awesome if using the new model was as easy as switching one argument? LLM Tornado acts as an aggregator allowing you to do just that. Think SearX but for LLMs!
OpenAI, Cohere, Anthropic, and Azure are currently supported along with KoboldCpp and Ollama.
⚡Getting Started
Install LLM Tornado via NuGet:
Install-Package LlmTornado
🔮 Quick Inference
Switching vendors
TornadoApi api = new TornadoApi(new List<ProviderAuthentication>
{
new ProviderAuthentication(LLmProviders.OpenAi, Program.ApiKeys.OpenAi),
new ProviderAuthentication(LLmProviders.Anthropic, Program.ApiKeys.Anthropic),
new ProviderAuthentication(LLmProviders.Cohere, Program.ApiKeys.Cohere)
});
List<ChatModel> models =
[
ChatModel.OpenAi.Gpt4.Turbo,
ChatModel.Anthropic.Claude3.Sonnet,
ChatModel.Cohere.CommandRPlus
];
foreach (ChatModel model in models)
{
string? response = await api.Chat.CreateConversation(model)
.AppendSystemMessage("You are a fortune teller.")
.AppendUserInput("What will my future bring?")
.GetResponse();
Console.WriteLine(response);
}
Switching the vendor is as easy as changing ChatModel
! Tornado instance can be constructed with multiple API keys, the correct key is then used based on the model.
Streaming
await api.Chat.CreateConversation(ChatModel.Anthropic.Claude3.Sonnet)
.AppendSystemMessage("You are a fortune teller.")
.AppendUserInput("What will my future bring?")
.StreamResponse(Console.Write);
Functions with deferred resolve
Conversation chat = Program.Connect().Chat.CreateConversation(new ChatRequest
{
Model = ChatModel.OpenAi.Gpt4.Turbo,
Tools = new List<Tool>
{
new Tool
{
Function = new ToolFunction("get_weather", "gets the current weather")
}
},
ToolChoice = new OutboundToolChoice(OutboundToolChoiceModes.Required)
});
chat.AppendUserInput("Who are you?"); // user asks something unrelated, but we force the model to use the tool
ChatBlocksResponse response = await chat.GetResponseWithFunctions(); // the response contains one block of type Function
Functions with immediate resolve
StringBuilder sb = new StringBuilder();
Conversation chat = Program.Connect().Chat.CreateConversation(new ChatRequest
{
Model = ChatModel.OpenAi.Gpt4.Turbo,
Tools = [
new Tool(new ToolFunction("get_weather", "gets the current weather", new
{
type = "object",
properties = new
{
location = new
{
type = "string",
description = "The location for which the weather information is required."
}
},
required = new List<string> { "location" }
}))
]
});
chat.OnAfterToolsCall = async (result) =>
{
string? str = await chat.GetResponse();
if (str is not null)
{
sb.Append(str);
}
};
chat.AppendMessage(ChatMessageRole.System, "You are a helpful assistant");
Guid msgId = Guid.NewGuid();
chat.AppendMessage(ChatMessageRole.User, "What is the weather like today in Prague?", msgId);
await chat.StreamResponseEnumerableWithFunctions(msgId, (x) =>
{
sb.Append(x);
return Task.CompletedTask;
}, functions =>
{
List<FunctionResult> results = [];
foreach (FunctionCall fn in functions)
{
results.Add(new FunctionResult(fn.Name, "A mild rain is expected around noon."));
}
return Task.FromResult(results);
}, null, null);
string response = sb.ToString();
Console.WriteLine(response);
Other endpoints such as Images, Embedding, Speech, Assistants, Threads and Vision are also supported!
Check the links for simple to-understand examples!
Why Tornado?
- 25,000+ installs on NuGet under previous names Lofcz.Forks.OpenAI, OpenAiNg.
- Used in commercial projects incurring charges of thousands of dollars monthly.
- The license will never change. Looking at you HashiCorp and Tiny.
- Supports streaming, functions/tools, and strongly typed LLM plugins/connectors.
- Great performance, nullability annotations.
- Extensive tests suite.
- Maintained actively for over half a year.
Documentation
Every public class, method, and property has extensive XML documentation, using LLM Tornado should be intuitive if you've used any other LLM library previously. Feel free to open an issue here if you have any questions.
PRs are welcome! ❤️
License
This library is licensed under MIT license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on LlmTornado:
Package | Downloads |
---|---|
LlmTornado.Contrib
Provides extra functionality to LlmTornado. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.1.26 | 167 | 11/22/2024 |
3.1.25 | 67 | 11/22/2024 |
3.1.24 | 79 | 11/21/2024 |
3.1.23 | 77 | 11/20/2024 |
3.1.22 | 86 | 11/20/2024 |
3.1.21 | 80 | 11/18/2024 |
3.1.20 | 64 | 11/18/2024 |
3.1.19 | 76 | 11/17/2024 |
3.1.18 | 71 | 11/16/2024 |
3.1.17 | 139 | 11/5/2024 |
3.1.16 | 75 | 11/4/2024 |
3.1.15 | 161 | 10/22/2024 |
3.1.14 | 338 | 9/14/2024 |
3.1.13 | 152 | 9/1/2024 |
3.1.12 | 154 | 8/20/2024 |
3.1.11 | 119 | 8/18/2024 |
3.1.10 | 110 | 8/6/2024 |
3.1.9 | 89 | 8/6/2024 |
3.1.8 | 90 | 7/24/2024 |
3.1.7 | 76 | 7/24/2024 |
3.1.6 | 72 | 7/23/2024 |
3.1.5 | 110 | 7/19/2024 |
3.1.4 | 90 | 7/19/2024 |
3.1.3 | 133 | 6/23/2024 |
3.1.2 | 127 | 6/15/2024 |
3.1.1 | 101 | 6/15/2024 |
3.1.0 | 91 | 6/15/2024 |
3.0.17 | 99 | 6/8/2024 |
3.0.16 | 92 | 6/8/2024 |
3.0.15 | 142 | 5/21/2024 |
3.0.14 | 110 | 5/21/2024 |
3.0.13 | 129 | 5/20/2024 |
3.0.11 | 106 | 5/18/2024 |
3.0.10 | 111 | 5/15/2024 |
3.0.9 | 125 | 5/15/2024 |
3.0.8 | 112 | 5/9/2024 |
3.0.7 | 136 | 5/5/2024 |
3.0.6 | 85 | 5/2/2024 |
3.0.5 | 93 | 5/1/2024 |
3.0.4 | 96 | 5/1/2024 |
3.0.3 | 90 | 5/1/2024 |
3.0.2 | 92 | 5/1/2024 |
3.0.1 | 119 | 4/27/2024 |
3.0.0 | 119 | 4/27/2024 |
OAI: support tool_choice: "required"