Skip to content

Commit

Permalink
test: Added CreateGeneration example/test.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 25, 2024
1 parent 7cbe7ba commit 4a4883a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,43 @@
- Updated and supported automatically if there are no breaking changes
- All modern .NET features - nullability, trimming, NativeAOT, etc.
- Support .Net Framework/.Net Standard 2.0
- DreamMachine API support

### Usage
```csharp
using Luma;

using var api = new LumaClient(apiKey);

Generation generation = await client.Generations.CreateGenerationAsync(
prompt: "No camera movement. The girl just stands there and smiles. The waves in the background move a little.",
aspectRatio: AspectRatio.x4_3,
loop: false,
keyframes: new Keyframes
{
Frame0 = new ImageReference
{
Url = "https://i.ibb.co/WFJyPcR/cool-girl.png",
},
// Frame1 = new GenerationReference
// {
// Id = Guid.Empty,
// },
});

while (generation.State != State.Failed && generation.State != State.Completed)
{
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);

generation = await client.Generations.GetGenerationAsync(
id: generation.Id?.Value.ToString(),
cancellationToken: cancellationToken);
}

Console.WriteLine($"Id: {generation.Id}");
Console.WriteLine($"State: {generation.State}");
Console.WriteLine($"FailureReason: {generation.FailureReason}");
Console.WriteLine($"Video URL: {generation.Assets?.Video}");
```

## Support
Expand Down
54 changes: 54 additions & 0 deletions src/tests/IntegrationTests/Tests.CreateGeneration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace Luma.IntegrationTests;

public partial class Tests
{
[TestMethod]
public async Task CreateGeneration()
{
using var client = GetAuthenticatedClient();
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(5));
var cancellationToken = cancellationTokenSource.Token;

Generation generation = await client.Generations.CreateGenerationAsync(
prompt: "The girl just smiles",
aspectRatio: AspectRatio.x4_3,
loop: false,
keyframes: new Keyframes
{
Frame0 = new ImageReference
{
Url = "https://i.ibb.co/WFJyPcR/cool-girl.png",
},
// Frame1 = new GenerationReference
// {
// Id = Guid.Empty,
// },
},
cancellationToken: cancellationToken);

if (generation.Id == null)
{
throw new InvalidOperationException("Generation Id is null.");
}

while (generation.State != State.Failed && generation.State != State.Completed)
{
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);

generation = await client.Generations.GetGenerationAsync(
id: generation.Id!.Value.ToString(),
cancellationToken: cancellationToken);
}

Console.WriteLine($"Id: {generation.Id}");
Console.WriteLine($"FailureReason: {generation.FailureReason}");
Console.WriteLine($"Video URL: {generation.Assets?.Video}");
Console.WriteLine($"State: {generation.State}");

generation.FailureReason.Should().BeNull();
generation.Id.Should().NotBeEmpty();
generation.Assets.Should().NotBeNull();
generation.Assets!.Video.Should().NotBeNull();
generation.State.Should().Be(State.Completed);
}
}
4 changes: 2 additions & 2 deletions src/tests/IntegrationTests/Tests.Ping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ public partial class Tests
[TestMethod]
public async Task Ping()
{
using var api = new LumaClient();
using var client = new LumaClient();

PingResponse response = await api.Ping.PingAsync();
PingResponse response = await client.Ping.PingAsync();
response.Message.Should().Be("pong");
}
}
6 changes: 3 additions & 3 deletions src/tests/IntegrationTests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ namespace Luma.IntegrationTests;
public partial class Tests
{
[TestMethod]
public LumaClient GetAuthenticatedApi()
public LumaClient GetAuthenticatedClient()
{
var apiKey =
Environment.GetEnvironmentVariable("LUMA_API_KEY") ??
throw new AssertInconclusiveException("LUMA_API_KEY environment variable is not found.");

var api = new LumaClient(apiKey);
var client = new LumaClient(apiKey);

return api;
return client;
}
}

0 comments on commit 4a4883a

Please sign in to comment.