CreateGeneration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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}");