Skip to content

Commit d104d9d

Browse files
committed
test: Added GenerateImage.
1 parent d22950b commit d104d9d

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

Diff for: README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ using Luma;
1919

2020
using var api = new LumaClient(apiKey);
2121

22+
// generate image
23+
Generation generation = await client.Generations.GenerateImageAsync(
24+
prompt: "The beautiful woman just smiles",
25+
aspectRatio: AspectRatio.x4_3,
26+
cancellationToken: cancellationToken);
27+
28+
// or generate video
2229
Generation generation = await client.Generations.CreateGenerationAsync(
23-
prompt: "No camera movement. The girl just stands there and smiles. The waves in the background move a little.",
30+
prompt: "No camera movement. The beautiful woman just stands there and smiles. The waves in the background move a little.",
2431
aspectRatio: AspectRatio.x4_3,
2532
loop: false,
2633
keyframes: new Keyframes

Diff for: src/tests/IntegrationTests/Tests.GenerateImage.cs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace Luma.IntegrationTests;
2+
3+
public partial class Tests
4+
{
5+
[TestMethod]
6+
public async Task GenerateImageAsync()
7+
{
8+
using var client = GetAuthenticatedClient();
9+
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(5));
10+
var cancellationToken = cancellationTokenSource.Token;
11+
12+
Generation generation = await client.Generations.GenerateImageAsync(
13+
prompt: "The beautiful woman just smiles",
14+
aspectRatio: AspectRatio.x4_3,
15+
cancellationToken: cancellationToken);
16+
17+
if (generation.Id == null)
18+
{
19+
throw new InvalidOperationException("Generation Id is null.");
20+
}
21+
22+
while (generation.State != State.Failed && generation.State != State.Completed)
23+
{
24+
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
25+
26+
generation = await client.Generations.GetGenerationAsync(
27+
id: generation.Id!.Value.ToString(),
28+
cancellationToken: cancellationToken);
29+
}
30+
31+
Console.WriteLine($"Id: {generation.Id}");
32+
Console.WriteLine($"FailureReason: {generation.FailureReason}");
33+
Console.WriteLine($"Image URL: {generation.Assets?.Image}");
34+
Console.WriteLine($"State: {generation.State}");
35+
36+
generation.FailureReason.Should().BeNull();
37+
generation.Id.Should().NotBeEmpty();
38+
generation.Assets.Should().NotBeNull();
39+
generation.Assets!.Image.Should().NotBeNull();
40+
generation.State.Should().Be(State.Completed);
41+
}
42+
}

Diff for: src/tests/IntegrationTests/Tests.CreateGeneration.cs renamed to src/tests/IntegrationTests/Tests.GenerateVideo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ namespace Luma.IntegrationTests;
33
public partial class Tests
44
{
55
[TestMethod]
6-
public async Task CreateGeneration()
6+
public async Task GenerateVideo()
77
{
88
using var client = GetAuthenticatedClient();
99
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(5));
1010
var cancellationToken = cancellationTokenSource.Token;
1111

1212
Generation generation = await client.Generations.CreateGenerationAsync(
13-
prompt: "The girl just smiles",
13+
prompt: "The beautiful woman just smiles",
1414
aspectRatio: AspectRatio.x4_3,
1515
loop: false,
1616
keyframes: new Keyframes

0 commit comments

Comments
 (0)