AgentTools.Llm
1.0.2
dotnet add package AgentTools.Llm --version 1.0.2
NuGet\Install-Package AgentTools.Llm -Version 1.0.2
<PackageReference Include="AgentTools.Llm" Version="1.0.2" />
<PackageVersion Include="AgentTools.Llm" Version="1.0.2" />
<PackageReference Include="AgentTools.Llm" />
paket add AgentTools.Llm --version 1.0.2
#r "nuget: AgentTools.Llm, 1.0.2"
#:package AgentTools.Llm@1.0.2
#addin nuget:?package=AgentTools.Llm&version=1.0.2
#tool nuget:?package=AgentTools.Llm&version=1.0.2
AgentTools.Llm
A flexible .NET library for integrating with various Large Language Model (LLM) providers. This library provides a unified interface for working with different LLM providers while maintaining the ability to use provider-specific features.
Features
- Unified interface for different LLM providers
- Support for both text completion and chat completion
- Configurable completion options
- Easy provider registration and management
- Extensible architecture for adding new providers
Installation
Add the package to your project using NuGet:
dotnet add package AgentTools.Llm
Usage
Basic Usage
using AgentTools.Llm.Providers;
using AgentTools.Llm.Models;
// Create a provider factory
var factory = new LlmProviderFactory();
// Create and register OpenAI providers with different models
var gpt35Provider = new OpenAiProvider(
apiKey: "your-api-key-here",
modelName: "gpt-3.5-turbo",
providerId: "gpt-35" // Unique identifier for this provider instance
);
var gpt4Provider = new OpenAiProvider(
apiKey: "your-api-key-here",
modelName: "gpt-4",
providerId: "gpt-4"
);
factory.RegisterProvider(gpt35Provider);
factory.RegisterProvider(gpt4Provider);
// Get the specific provider instance you want to use
var provider = factory.GetProvider("gpt-35"); // or "gpt-4"
// Generate a completion
var response = await provider.GenerateCompletionAsync(
"What is the capital of France?",
new CompletionOptions { Temperature = 0.7f }
);
Using Different Models for Different Scenarios
// Create a provider registry to manage different models
public class LlmProviderRegistry
{
private readonly LlmProviderFactory _factory;
public LlmProviderRegistry(LlmProviderFactory factory)
{
_factory = factory;
}
public ILlmProvider GetProviderForScenario(string scenario)
{
return scenario switch
{
"chat" => _factory.GetProvider("gpt-35"),
"code" => _factory.GetProvider("gpt-4"),
"analysis" => _factory.GetProvider("gpt-4"),
_ => _factory.GetProvider("gpt-35") // Default fallback
};
}
}
// Usage
var registry = new LlmProviderRegistry(factory);
var chatProvider = registry.GetProviderForScenario("chat");
var codeProvider = registry.GetProviderForScenario("code");
Chat Completion
var messages = new[]
{
new ChatMessage("system", "You are a helpful assistant."),
new ChatMessage("user", "What is the capital of France?")
};
var response = await provider.GenerateChatCompletionAsync(messages);
Using Custom Options
var options = new CompletionOptions
{
Temperature = 0.2f,
MaxTokens = 100,
TopP = 0.9f,
FrequencyPenalty = 0.5f,
PresencePenalty = 0.5f,
StopSequences = new[] { "\n" }
};
var response = await provider.GenerateCompletionAsync("Write a short poem.", options);
Configuration
OpenAI Configuration
var config = new OpenAiConfiguration(
apiKey: "your-api-key-here",
defaultModel: "gpt-3.5-turbo",
organizationId: "optional-org-id"
);
Publish to Nuget
dotnet pack
dotnet push AgentTools.Llm.1.0.1.nupkg --source https://api.nuget.org/v3/index.json --api-key <your-api-key>
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AgentTools.Llm:
| Package | Downloads |
|---|---|
|
AgentTools.Collection
A library of tools for AI Agents to perform various operations such as web searches, web content reading, and LLM completions. |
GitHub repositories
This package is not used by any popular GitHub repositories.