AgentTools.Llm 1.0.0

dotnet add package AgentTools.Llm --version 1.0.0
                    
NuGet\Install-Package AgentTools.Llm -Version 1.0.0
                    
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="AgentTools.Llm" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AgentTools.Llm" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AgentTools.Llm" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AgentTools.Llm --version 1.0.0
                    
#r "nuget: AgentTools.Llm, 1.0.0"
                    
#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.
#addin nuget:?package=AgentTools.Llm&version=1.0.0
                    
Install AgentTools.Llm as a Cake Addin
#tool nuget:?package=AgentTools.Llm&version=1.0.0
                    
Install AgentTools.Llm as a Cake Tool

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"
);

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 424 3/24/2025