SpongeEngine.KoboldSharp
1.81.1.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SpongeEngine.KoboldSharp --version 1.81.1.3
NuGet\Install-Package SpongeEngine.KoboldSharp -Version 1.81.1.3
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.KoboldSharp" Version="1.81.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SpongeEngine.KoboldSharp --version 1.81.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SpongeEngine.KoboldSharp, 1.81.1.3"
#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.KoboldSharp as a Cake Addin #addin nuget:?package=SpongeEngine.KoboldSharp&version=1.81.1.3 // Install SpongeEngine.KoboldSharp as a Cake Tool #tool nuget:?package=SpongeEngine.KoboldSharp&version=1.81.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
KoboldSharp
C# client for interacting with KoboldCpp through its native API.
Features
- Complete support for KoboldCpp's native API
- Streaming text generation
- Built-in error handling and logging
- Cross-platform compatibility
- Full async/await support
- Support for Stable Diffusion image generation
- Support for Whisper audio transcription
- Support for WebSearch integration
- Support for multiplayer features
Installation
Install via NuGet:
dotnet add package SpongeEngine.KoboldSharp
Quick Start
Basic Usage
using SpongeEngine.KoboldSharp;
// Configure the client
var options = new KoboldSharpClientOptions
{
BaseUrl = "http://localhost:5001",
// Optional client-side settings
MultiplayerEnabled = false,
WebSearchEnabled = false
};
// Create client instance
using var client = new KoboldSharpClient(options);
// Generate completion
var request = new KoboldSharpRequest
{
Prompt = "Write a short story about a robot:",
MaxLength = 200,
Temperature = 0.7f,
TopP = 0.9f
};
var response = await client.GenerateAsync(request);
Console.WriteLine(response.Results[0].Text);
// Stream completion
await foreach (var token in client.GenerateStreamAsync(request))
{
Console.Write(token);
}
Configuration
Client Options
var options = new KoboldSharpClientOptions
{
// Base configuration
BaseUrl = "http://localhost:5001", // KoboldCpp server URL
ApiKey = "optional_api_key", // Optional API key if server requires auth
// Optional features
MultiplayerEnabled = false, // Enable multiplayer support
WebSearchEnabled = false, // Enable web search integration
// Stable Diffusion settings (if using image generation)
StableDiffusionModelPath = "path/to/model.safetensors",
StableDiffusionVaePath = "path/to/vae.safetensors",
StableDiffusionUseQuantization = false,
StableDiffusionMaxResolution = 512,
StableDiffusionThreads = -1,
// HTTP and resilience settings
Timeout = TimeSpan.FromMinutes(10),
MaxRetryAttempts = 3,
RetryDelay = TimeSpan.FromSeconds(2)
};
Generation Parameters
var request = new KoboldSharpRequest
{
// Basic Parameters
Prompt = "Your prompt here",
MaxLength = 200, // Maximum tokens to generate
MaxContextLength = 2048, // Maximum context length
Temperature = 0.7f, // Randomness (0.0-1.0)
// Sampling Parameters
TopP = 0.9f, // Nucleus sampling threshold
TopK = 40, // Top-K sampling
TopA = 0.0f, // Top-A sampling
MinP = 0.0f, // Minimum P sampling
Typical = 1.0f, // Typical sampling
Tfs = 1.0f, // Tail-free sampling
// Repetition Control
RepetitionPenalty = 1.1f, // Base repetition penalty
RepetitionPenaltyRange = 320, // How far back to apply penalty
RepetitionPenaltySlope = 1.0f, // Penalty application slope
PresencePenalty = 0.0f, // Presence penalty
// Mirostat Parameters
MirostatMode = 0, // Mirostat sampling mode (0, 1, 2)
MirostatTau = 5.0f, // Target entropy
MirostatEta = 0.1f, // Learning rate
// Advanced Control
Seed = -1, // RNG seed (-1 for random)
StopSequences = new List<string>(), // Stop generation sequences
Stream = false, // Enable streaming
TrimStop = true, // Trim stop sequences
Grammar = null, // Optional grammar constraints
GrammarRetainState = false, // Retain grammar state
Memory = null, // Optional context memory
BannedTokens = null, // Tokens to never generate
LogitBias = null, // Token generation biases
// Special Features
Images = null, // Images for multimodal models
AllowEosToken = true, // Allow end of sequence token
BypassEosToken = false, // Bypass EOS token
RenderSpecial = false, // Render special tokens
// Dynamic Temperature
DynamicTemperatureRange = 0.0f, // Dynamic temperature range
DynamicTemperatureExponent = 1.0f, // Dynamic temperature exponent
SmoothingFactor = 0.0f // Output smoothing factor
};
Error Handling
try
{
var response = await client.GenerateAsync(request);
}
catch (LlmSharpException ex)
{
Console.WriteLine($"Generation error: {ex.Message}");
if (ex.StatusCode.HasValue)
{
Console.WriteLine($"Status code: {ex.StatusCode}");
}
if (ex.ResponseContent != null)
{
Console.WriteLine($"Response content: {ex.ResponseContent}");
}
}
Logging
The client supports Microsoft.Extensions.Logging:
ILogger logger = LoggerFactory
.Create(builder => builder
.AddConsole()
.SetMinimumLevel(LogLevel.Debug))
.CreateLogger<KoboldSharpClient>();
var client = new KoboldSharpClient(options, logger);
Testing
To run the tests:
dotnet test
Configure test environment:
Environment.SetEnvironmentVariable("KOBOLDCPP_BASE_URL", "http://localhost:5001");
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 | Versions 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.
-
net6.0
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- OllamaSharp (>= 4.0.11)
- Polly (>= 8.5.0)
- SpongeEngine.LLMSharp.Core (>= 1.1.2)
- System.Linq.Async (>= 6.0.1)
-
net7.0
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- OllamaSharp (>= 4.0.11)
- Polly (>= 8.5.0)
- SpongeEngine.LLMSharp.Core (>= 1.1.2)
- System.Linq.Async (>= 6.0.1)
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
- OllamaSharp (>= 4.0.11)
- Polly (>= 8.5.0)
- SpongeEngine.LLMSharp.Core (>= 1.1.2)
- System.Linq.Async (>= 6.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SpongeEngine.KoboldSharp:
Package | Downloads |
---|---|
SpongeEngine.SpongeLLM
Unified C# client for LLM providers. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.82.4.2 | 62 | 1/26/2025 |
1.82.4.1 | 93 | 1/24/2025 |
1.81.1.6 | 65 | 1/22/2025 |
1.81.1.5 | 64 | 1/22/2025 |
1.81.1.4 | 73 | 1/18/2025 |
1.81.1.3 | 64 | 1/17/2025 |
1.81.1.2 | 64 | 1/17/2025 |
1.81.1 | 68 | 1/17/2025 |
1.2.2 | 42 | 1/14/2025 |
1.2.1 | 67 | 1/13/2025 |
1.2.0 | 64 | 1/13/2025 |
1.1.3 | 62 | 1/13/2025 |
1.1.2 | 54 | 1/9/2025 |
1.1.1 | 94 | 1/2/2025 |