Skip to content

Commit f26049c

Browse files
committed
fix: Fixed.
1 parent 0d88fd2 commit f26049c

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/libs/Replicate/PredictionResponseExtensions.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ public static class PredictionResponseExtensions
1111
/// <param name="response"></param>
1212
/// <returns></returns>
1313
/// <exception cref="ArgumentNullException"></exception>
14-
public static bool IsSuccessful(this PredictionResponse response)
14+
public static bool IsCompleted(this SchemasPredictionResponse response)
1515
{
1616
response = response ?? throw new ArgumentNullException(nameof(response));
1717

18-
return response.Status == "succeeded";
18+
return response.Status is
19+
SchemasPredictionResponseStatus.Succeeded or
20+
SchemasPredictionResponseStatus.Canceled or
21+
SchemasPredictionResponseStatus.Failed;
1922
}
2023

2124
/// <summary>
@@ -27,22 +30,23 @@ public static bool IsSuccessful(this PredictionResponse response)
2730
/// <returns></returns>
2831
/// <exception cref="ArgumentNullException"></exception>
2932
/// <exception cref="ArgumentException"></exception>
30-
public static async Task<PredictionResponse> WaitUntilSuccessfulAsync(
31-
this PredictionResponse response,
33+
public static async Task<PredictionResponse?> WaitUntilSuccessfulAsync(
34+
this SchemasPredictionResponse response,
3235
ReplicateApi api,
3336
CancellationToken cancellationToken = default)
3437
{
3538
response = response ?? throw new ArgumentNullException(nameof(response));
3639
api = api ?? throw new ArgumentNullException(nameof(api));
3740
var id = response.Id ?? throw new ArgumentException(nameof(response.Id));
3841

39-
while (!response.IsSuccessful())
42+
PredictionResponse? predictionResponse = null;
43+
while (!response.IsCompleted())
4044
{
4145
await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
4246

43-
response = await api.PredictionsGetAsync(id, cancellationToken).ConfigureAwait(false);
47+
predictionResponse = await api.PredictionsGetAsync(id, cancellationToken).ConfigureAwait(false);
4448
}
4549

46-
return response;
50+
return predictionResponse;
4751
}
4852
}

src/tests/Replicate.IntegrationTests/Tests.Account.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public async Task Account()
1010
var response = await api.AccountGetAsync();
1111

1212
response.Should().NotBeNull();
13-
response.Type.HasValue.Should().BeTrue();
13+
response.Type.Should().Be(AccountGetResponseType.User);
1414
}
1515
}

src/tests/Replicate.IntegrationTests/Tests.CreatePredictionForFluxPro.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public async Task CreatePredictionForFluxPro()
2828

2929
var endResponse = await response.WaitUntilSuccessfulAsync(api);
3030

31-
Console.WriteLine($"Seed: {endResponse.Input?.Seed}.");
31+
Console.WriteLine($"Seed: {endResponse?.Input?.Seed}.");
3232
Console.WriteLine("Image available at:");
33-
Console.WriteLine(endResponse.Output);
33+
Console.WriteLine(endResponse?.Output);
3434

3535
//// ![output](https://raw.githubusercontent.com/tryAGI/Replicate/dd1e5c2cbebc53e9b343f1372e5a660159e79ef3/assets/output.webp)
3636
}

0 commit comments

Comments
 (0)