SpongeEngine.OobaboogaSharp 1.1.0

dotnet add package SpongeEngine.OobaboogaSharp --version 1.1.0                
NuGet\Install-Package SpongeEngine.OobaboogaSharp -Version 1.1.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="SpongeEngine.OobaboogaSharp" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SpongeEngine.OobaboogaSharp --version 1.1.0                
#r "nuget: SpongeEngine.OobaboogaSharp, 1.1.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.
// Install SpongeEngine.OobaboogaSharp as a Cake Addin
#addin nuget:?package=SpongeEngine.OobaboogaSharp&version=1.1.0

// Install SpongeEngine.OobaboogaSharp as a Cake Tool
#tool nuget:?package=SpongeEngine.OobaboogaSharp&version=1.1.0                

OobaboogaSharp

NuGet NuGet Downloads License .NET

C# client for interacting with Oobabooga's text-generation-webui through its OpenAI-compatible API endpoints.

Features

  • OpenAI-compatible API support
  • Text completion and chat completion
  • Streaming responses support
  • Character templates and instruction formats
  • Comprehensive configuration options
  • Built-in error handling and logging
  • Cross-platform compatibility
  • Full async/await support

📦 View Package on NuGet

Installation

Install via NuGet:

dotnet add package SpongeEngine.OobaboogaSharp

Quick Start

using SpongeEngine.OobaboogaSharp;
using SpongeEngine.OobaboogaSharp.Models.Common;
using SpongeEngine.OobaboogaSharp.Models.Chat;

// Configure the client
var options = new Options
{
    BaseUrl = "http://localhost:5000",  // Default port for text-generation-webui
    TimeoutSeconds = 120
};

// Create client instance
using var client = new OobaboogaSharpClient(options);

// Simple completion
var response = await client.CompleteAsync(
    "Write a short story about a robot:",
    new CompletionOptions
    {
        MaxTokens = 200,
        Temperature = 0.7f,
        TopP = 0.9f
    });

Console.WriteLine(response);

// Chat completion
var messages = new List<ChatMessage>
{
    OobaboogaSharpClient.CreateChatMessage("user", "Write a poem about coding")
};

var chatResponse = await client.ChatCompleteAsync(
    messages,
    new ChatCompletionOptions
    {
        Mode = "instruct",
        InstructionTemplate = "Alpaca",
        MaxTokens = 200
    });

Console.WriteLine(chatResponse.Choices[0].Message.Content);

// Stream chat completion
await foreach (var message in client.StreamChatCompletionAsync(messages))
{
    Console.Write(message.Content);
}

Configuration Options

Basic Options

var options = new Options
{
    BaseUrl = "http://localhost:5000",    // text-generation-webui server URL
    ApiKey = "optional_api_key",          // Optional API key for authentication
    TimeoutSeconds = 120                  // Request timeout
};

Chat Completion Options

var options = new ChatCompletionOptions
{
    ModelName = "optional_model_name",    // Specific model to use
    MaxTokens = 200,                      // Maximum tokens to generate
    Temperature = 0.7f,                   // Randomness (0.0-1.0)
    TopP = 0.9f,                         // Nucleus sampling threshold
    StopSequences = new[] { "\n" },      // Stop sequences
    Mode = "chat",                       // "chat" or "instruct"
    InstructionTemplate = "Alpaca",      // Template for instruction format
    Character = "Assistant"              // Character template to use
};

Text Completion Options

var options = new CompletionOptions
{
    ModelName = "optional_model_name",
    MaxTokens = 200,
    Temperature = 0.7f,
    TopP = 0.9f,
    StopSequences = new[] { "\n" }
};

Error Handling

try
{
    var response = await client.ChatCompleteAsync(messages, options);
}
catch (Exception ex) when (ex is SpongeEngine.OobaboogaSharp.Models.Common.Exception oobaboogaEx)
{
    Console.WriteLine($"Oobabooga error: {ex.Message}");
    Console.WriteLine($"Provider: {oobaboogaEx.Provider}");
    Console.WriteLine($"Status code: {oobaboogaEx.StatusCode}");
    Console.WriteLine($"Response content: {oobaboogaEx.ResponseContent}");
}
catch (Exception ex)
{
    Console.WriteLine($"General error: {ex.Message}");
}

Logging

The client supports Microsoft.Extensions.Logging:

ILogger logger = LoggerFactory
    .Create(builder => builder
        .AddConsole()
        .SetMinimumLevel(LogLevel.Debug))
    .CreateLogger<OobaboogaSharpClient>();

var client = new OobaboogaSharpClient(options, logger);

JSON Serialization

Custom JSON settings can be provided:

var jsonSettings = new JsonSerializerSettings
{
    NullValueHandling = NullValueHandling.Ignore
};

var client = new OobaboogaSharpClient(options, logger, jsonSettings);

Testing

The library includes both unit and integration tests. Integration tests require a running text-generation-webui server.

To run the tests:

dotnet test

Configure test environment:

Environment.SetEnvironmentVariable("OOBABOOGA_BASE_URL", "http://localhost:5000");

License

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

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and feature requests, please use the GitHub issues page.

Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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.  net9.0 was computed.  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.

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.1.0 64 1/2/2025