Skip to content

Commit 033e765

Browse files
authored
[OpenAI] Use sync internal method instead of async method and block it (Azure#36445)
1 parent 62c89d2 commit 033e765

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/OpenAIClient.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@
3030
import com.azure.core.util.IterableStream;
3131
import com.azure.core.util.logging.ClientLogger;
3232
import com.azure.core.util.polling.SyncPoller;
33-
import java.io.IOException;
34-
import java.io.UncheckedIOException;
3533
import java.nio.ByteBuffer;
36-
import reactor.core.Exceptions;
3734
import reactor.core.publisher.Flux;
3835

3936
/** Initializes a new instance of the synchronous OpenAIClient type. */
@@ -505,27 +502,10 @@ public ImageResponse getImages(ImageGenerationOptions imageGenerationOptions) {
505502
.getValue()
506503
.toObject(ImageResponse.class);
507504
} else {
508-
// TODO: Currently, we use async client block() to avoid a unknown LRO status "notRunning" which Azure Core
509-
// will
510-
// fix the issue in August release and we will reuse the method
511-
// "SyncPoller<BinaryData, BinaryData> beginBeginAzureBatchImageGeneration()" after.
512-
try {
513-
return this.serviceClient
514-
.beginBeginAzureBatchImageGenerationAsync(imageGenerationOptionsBinaryData, requestOptions)
515-
.last()
516-
.flatMap(it -> it.getFinalResult())
517-
.map(it -> it.toObject(ImageOperationResponse.class).getResult())
518-
.block();
519-
} catch (Exception e) {
520-
Throwable unwrapped = Exceptions.unwrap(e);
521-
if (unwrapped instanceof RuntimeException) {
522-
throw LOGGER.logExceptionAsError((RuntimeException) unwrapped);
523-
} else if (unwrapped instanceof IOException) {
524-
throw LOGGER.logExceptionAsError(new UncheckedIOException((IOException) unwrapped));
525-
} else {
526-
throw LOGGER.logExceptionAsError(new RuntimeException(unwrapped));
527-
}
528-
}
505+
return beginBeginAzureBatchImageGeneration(imageGenerationOptionsBinaryData, requestOptions)
506+
.getFinalResult()
507+
.toObject(ImageOperationResponse.class)
508+
.getResult();
529509
}
530510
}
531511

0 commit comments

Comments
 (0)