-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,782 additions
and
2 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
SpongeEngine.KoboldSharp.Tests/Integration/Extra/AbortGenerate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace SpongeEngine.KoboldSharp.Tests.Integration.Extra | ||
{ | ||
[Trait("Category", "Integration")] | ||
[Trait("API", "Native")] | ||
public class AbortGenerate : IntegrationTestBase | ||
{ | ||
public AbortGenerate(ITestOutputHelper output) : base(output) {} | ||
|
||
[SkippableFact] | ||
public async Task AbortGenerate_DuringGeneration_ShouldStop() | ||
{ | ||
Skip.If(!ServerAvailable, "KoboldCpp server is not available"); | ||
|
||
// Arrange - Start a long generation | ||
var request = new KoboldSharpClient.KoboldSharpRequest | ||
{ | ||
Prompt = "Write a very long story about a journey", | ||
MaxLength = 200, | ||
Temperature = 0.7f, | ||
TopP = 0.9f | ||
}; | ||
|
||
// Start generation in a separate task | ||
var generationTask = Task.Run(async () => | ||
{ | ||
try | ||
{ | ||
await foreach (var token in Client.GenerateStreamAsync(request)) | ||
{ | ||
Output.WriteLine($"Generated token: {token}"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Output.WriteLine($"Generation stopped: {ex.Message}"); | ||
} | ||
}); | ||
|
||
// Give some time for generation to start | ||
await Task.Delay(1000); | ||
|
||
// Act | ||
var result = await Client.AbortGenerateAsync(); | ||
|
||
// Assert | ||
result.Should().BeTrue(); | ||
|
||
// Wait for generation task to complete due to abort | ||
var completedTask = await Task.WhenAny(generationTask, Task.Delay(5000)); | ||
completedTask.Should().Be(generationTask, "Generation should stop after abort"); | ||
} | ||
|
||
[SkippableFact] | ||
public async Task AbortGenerate_WhenNoGeneration_ShouldReturnTrue() | ||
{ | ||
Skip.If(!ServerAvailable, "KoboldCpp server is not available"); | ||
|
||
// Act | ||
var result = await Client.AbortGenerateAsync(); | ||
|
||
// Assert | ||
result.Should().BeTrue(); | ||
Output.WriteLine("Successfully called abort with no active generation"); | ||
} | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
SpongeEngine.KoboldSharp.Tests/Integration/Extra/LogProbs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace SpongeEngine.KoboldSharp.Tests.Integration.Extra | ||
{ | ||
[Trait("Category", "Integration")] | ||
[Trait("API", "Native")] | ||
public class LogProbs : IntegrationTestBase | ||
{ | ||
public LogProbs(ITestOutputHelper output) : base(output) {} | ||
|
||
[SkippableFact] | ||
public async Task GetPendingOutput_DuringGeneration_ShouldReturnPartialOutput() | ||
{ | ||
Skip.If(!ServerAvailable, "KoboldCpp server is not available"); | ||
|
||
// Arrange - Start a long generation | ||
var request = new KoboldSharpClient.KoboldSharpRequest | ||
{ | ||
Prompt = "Write a long story about an adventure", | ||
MaxLength = 100, | ||
Temperature = 0.7f, | ||
TopP = 0.9f | ||
}; | ||
|
||
// Start generation in background | ||
var generationTask = Task.Run(async () => | ||
{ | ||
await Client.GenerateAsync(request); | ||
}); | ||
|
||
// Give some time for generation to start | ||
await Task.Delay(500); | ||
|
||
// Act | ||
var pendingOutput = await Client.GetPendingOutputAsync(); | ||
|
||
// Assert | ||
pendingOutput.Should().NotBeNull(); | ||
if (!string.IsNullOrEmpty(pendingOutput)) | ||
{ | ||
Output.WriteLine($"Pending output received: {pendingOutput}"); | ||
} | ||
else | ||
{ | ||
Output.WriteLine("No pending output at the moment of check"); | ||
} | ||
|
||
// Cleanup - ensure generation completes or is aborted | ||
if (!generationTask.IsCompleted) | ||
{ | ||
await Client.AbortGenerateAsync(); | ||
} | ||
await Task.WhenAny(generationTask, Task.Delay(5000)); | ||
} | ||
|
||
[SkippableFact] | ||
public async Task GetPendingOutput_WithNoGeneration_ShouldReturnEmpty() | ||
{ | ||
Skip.If(!ServerAvailable, "KoboldCpp server is not available"); | ||
|
||
// First ensure no generation is running | ||
await Client.AbortGenerateAsync(); | ||
await Task.Delay(500); // Give time for any pending operations to complete | ||
|
||
// Act | ||
var result = await Client.GetPendingOutputAsync(); | ||
|
||
// Assert | ||
result.Should().BeEmpty(); | ||
Output.WriteLine("Successfully verified no pending output when no generation is active"); | ||
} | ||
|
||
[SkippableFact] | ||
public async Task GetPendingOutput_MultipleChecks_ShouldShowProgress() | ||
{ | ||
Skip.If(!ServerAvailable, "KoboldCpp server is not available"); | ||
|
||
// Arrange - Start a long generation | ||
var request = new KoboldSharpClient.KoboldSharpRequest | ||
{ | ||
Prompt = "Write a detailed story about a journey through time", | ||
MaxLength = 150, | ||
Temperature = 0.7f, | ||
TopP = 0.9f | ||
}; | ||
|
||
var generationTask = Task.Run(async () => | ||
{ | ||
await Client.GenerateAsync(request); | ||
}); | ||
|
||
// Act - Check output multiple times | ||
var outputs = new List<string>(); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
await Task.Delay(1000); // Wait between checks | ||
var pendingOutput = await Client.GetPendingOutputAsync(); | ||
outputs.Add(pendingOutput); | ||
Output.WriteLine($"Check {i + 1} output length: {pendingOutput.Length}"); | ||
Output.WriteLine($"Content: {pendingOutput}"); | ||
} | ||
|
||
// Assert | ||
outputs.Should().NotBeEmpty(); | ||
if (outputs.Count > 1) | ||
{ | ||
// Verify that at least some outputs show different content | ||
outputs.Distinct().Should().HaveCountGreaterThan(1, | ||
"Multiple checks should show generation progress"); | ||
} | ||
|
||
// Cleanup | ||
if (!generationTask.IsCompleted) | ||
{ | ||
await Client.AbortGenerateAsync(); | ||
} | ||
await Task.WhenAny(generationTask, Task.Delay(5000)); | ||
} | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
SpongeEngine.KoboldSharp.Tests/Integration/Extra/PendingOutput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace SpongeEngine.KoboldSharp.Tests.Integration.Extra | ||
{ | ||
[Trait("Category", "Integration")] | ||
[Trait("API", "Native")] | ||
public class PendingOutput : IntegrationTestBase | ||
{ | ||
public PendingOutput(ITestOutputHelper output) : base(output) {} | ||
|
||
[SkippableFact] | ||
public async Task GetPendingOutput_DuringGeneration_ShouldReturnPartialOutput() | ||
{ | ||
Skip.If(!ServerAvailable, "KoboldCpp server is not available"); | ||
|
||
// Arrange - Start a long generation | ||
var request = new KoboldSharpClient.KoboldSharpRequest | ||
{ | ||
Prompt = "Write a long story about an adventure", | ||
MaxLength = 100, | ||
Temperature = 0.7f, | ||
TopP = 0.9f | ||
}; | ||
|
||
// Start generation in background | ||
var generationTask = Task.Run(async () => | ||
{ | ||
await Client.GenerateAsync(request); | ||
}); | ||
|
||
// Give some time for generation to start | ||
await Task.Delay(500); | ||
|
||
// Act | ||
var pendingOutput = await Client.GetPendingOutputAsync(); | ||
|
||
// Assert | ||
pendingOutput.Should().NotBeNull(); | ||
if (!string.IsNullOrEmpty(pendingOutput)) | ||
{ | ||
Output.WriteLine($"Pending output received: {pendingOutput}"); | ||
} | ||
else | ||
{ | ||
Output.WriteLine("No pending output at the moment of check"); | ||
} | ||
|
||
// Cleanup - ensure generation completes or is aborted | ||
if (!generationTask.IsCompleted) | ||
{ | ||
await Client.AbortGenerateAsync(); | ||
} | ||
await Task.WhenAny(generationTask, Task.Delay(5000)); | ||
} | ||
|
||
[SkippableFact] | ||
public async Task GetPendingOutput_WithNoGeneration_ShouldReturnEmpty() | ||
{ | ||
Skip.If(!ServerAvailable, "KoboldCpp server is not available"); | ||
|
||
// First ensure no generation is running | ||
await Client.AbortGenerateAsync(); | ||
await Task.Delay(500); // Give time for any pending operations to complete | ||
|
||
// Act | ||
var result = await Client.GetPendingOutputAsync(); | ||
|
||
// Assert | ||
result.Should().BeEmpty(); | ||
Output.WriteLine("Successfully verified no pending output when no generation is active"); | ||
} | ||
|
||
[SkippableFact] | ||
public async Task GetPendingOutput_MultipleChecks_ShouldShowProgress() | ||
{ | ||
Skip.If(!ServerAvailable, "KoboldCpp server is not available"); | ||
|
||
// Arrange - Start a long generation | ||
var request = new KoboldSharpClient.KoboldSharpRequest | ||
{ | ||
Prompt = "Write a detailed story about a journey through time", | ||
MaxLength = 150, | ||
Temperature = 0.7f, | ||
TopP = 0.9f | ||
}; | ||
|
||
var generationTask = Task.Run(async () => | ||
{ | ||
await Client.GenerateAsync(request); | ||
}); | ||
|
||
// Act - Check output multiple times | ||
var outputs = new List<string>(); | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
await Task.Delay(1000); // Wait between checks | ||
var pendingOutput = await Client.GetPendingOutputAsync(); | ||
outputs.Add(pendingOutput); | ||
Output.WriteLine($"Check {i + 1} output length: {pendingOutput.Length}"); | ||
Output.WriteLine($"Content: {pendingOutput}"); | ||
} | ||
|
||
// Assert | ||
outputs.Should().NotBeEmpty(); | ||
if (outputs.Count > 1) | ||
{ | ||
// Verify that at least some outputs show different content | ||
outputs.Distinct().Should().HaveCountGreaterThan(1, | ||
"Multiple checks should show generation progress"); | ||
} | ||
|
||
// Cleanup | ||
if (!generationTask.IsCompleted) | ||
{ | ||
await Client.AbortGenerateAsync(); | ||
} | ||
await Task.WhenAny(generationTask, Task.Delay(5000)); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
SpongeEngine.KoboldSharp.Tests/Integration/Extra/PerfInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace SpongeEngine.KoboldSharp.Tests.Integration.Extra | ||
{ | ||
[Trait("Category", "Integration")] | ||
[Trait("API", "Native")] | ||
public class PerfInfo : IntegrationTestBase | ||
{ | ||
public PerfInfo(ITestOutputHelper output) : base(output) {} | ||
|
||
[SkippableFact] | ||
public async Task GetPerfInfo_ShouldReturnValidData() | ||
{ | ||
Skip.If(!ServerAvailable, "KoboldCpp server is not available"); | ||
|
||
// Act | ||
var result = await Client.GetPerfInfoAsync(); | ||
|
||
// Assert | ||
result.Should().NotBeNull(); | ||
result.TotalGenerations.Should().BeGreaterOrEqualTo(0); | ||
result.Uptime.Should().BeGreaterThan(0); | ||
|
||
// Log performance data | ||
Output.WriteLine($"Last Process Time: {result.LastProcessTime}s"); | ||
Output.WriteLine($"Last Eval Time: {result.LastEvalTime}s"); | ||
Output.WriteLine($"Last Token Count: {result.LastTokenCount}"); | ||
Output.WriteLine($"Total Generations: {result.TotalGenerations}"); | ||
Output.WriteLine($"Queue Size: {result.QueueSize}"); | ||
Output.WriteLine($"Uptime: {result.Uptime}s"); | ||
Output.WriteLine($"Idle Time: {result.IdleTime}s"); | ||
} | ||
|
||
[SkippableFact] | ||
public async Task GetPerfInfo_AfterGeneration_ShouldShowActivity() | ||
{ | ||
Skip.If(!ServerAvailable, "KoboldCpp server is not available"); | ||
|
||
// Arrange - Get initial performance info | ||
var initialInfo = await Client.GetPerfInfoAsync(); | ||
|
||
// Perform a generation | ||
var request = new KoboldSharpClient.KoboldSharpRequest | ||
{ | ||
Prompt = "Test generation for performance monitoring", | ||
MaxLength = 20 | ||
}; | ||
await Client.GenerateAsync(request); | ||
|
||
// Act - Get updated performance info | ||
var updatedInfo = await Client.GetPerfInfoAsync(); | ||
|
||
// Assert | ||
updatedInfo.Should().NotBeNull(); | ||
updatedInfo.TotalGenerations.Should().BeGreaterThan(initialInfo.TotalGenerations); | ||
updatedInfo.LastTokenCount.Should().BeGreaterThan(0); | ||
updatedInfo.LastProcessTime.Should().BeGreaterThan(0); | ||
|
||
Output.WriteLine($"Initial Total Generations: {initialInfo.TotalGenerations}"); | ||
Output.WriteLine($"Updated Total Generations: {updatedInfo.TotalGenerations}"); | ||
Output.WriteLine($"Last Process Time: {updatedInfo.LastProcessTime}s"); | ||
Output.WriteLine($"Last Token Count: {updatedInfo.LastTokenCount}"); | ||
} | ||
} | ||
} |
Oops, something went wrong.