Skip to content

Commit 50e9583

Browse files
authored
added withResponse overload method for ImageGeneration (#41047)
1 parent 53a7d6f commit 50e9583

File tree

9 files changed

+128
-3
lines changed

9 files changed

+128
-3
lines changed

sdk/openai/azure-ai-openai/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## 1.0.0-beta.11 (Unreleased)
44

55
### Features Added
6+
- Added a new overload `getImageGenerationsWithResponse` that takes `RequestOptions` to provide the flexibility to
7+
modify the HTTP request.
68

79
### Breaking Changes
810

sdk/openai/azure-ai-openai/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/openai/azure-ai-openai",
5-
"Tag": "java/openai/azure-ai-openai_0e2b3dee1d"
5+
"Tag": "java/openai/azure-ai-openai_6aab94ce2d"
66
}

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,39 @@ Mono<Response<BinaryData>> getImageGenerationsWithResponse(String deploymentOrMo
13521352

13531353
/**
13541354
* Creates an image given a prompt.
1355+
* <p>
1356+
* <strong>Request Body Schema</strong>
1357+
* </p>
1358+
*
1359+
* <pre>{@code
1360+
* {
1361+
* model: String (Optional)
1362+
* prompt: String (Required)
1363+
* n: Integer (Optional)
1364+
* size: String(256x256/512x512/1024x1024/1792x1024/1024x1792) (Optional)
1365+
* response_format: String(url/b64_json) (Optional)
1366+
* quality: String(standard/hd) (Optional)
1367+
* style: String(natural/vivid) (Optional)
1368+
* user: String (Optional)
1369+
* }
1370+
* }</pre>
1371+
*
1372+
* <p>
1373+
* <strong>Response Body Schema</strong>
1374+
* </p>
1375+
*
1376+
* <pre>{@code
1377+
* {
1378+
* created: long (Required)
1379+
* data (Required): [
1380+
* (Required){
1381+
* url: String (Optional)
1382+
* b64_json: String (Optional)
1383+
* revised_prompt: String (Optional)
1384+
* }
1385+
* ]
1386+
* }
1387+
* }</pre>
13551388
*
13561389
* @param deploymentOrModelName Specifies either the model deployment name (when using Azure OpenAI) or model name
13571390
* (when using non-Azure OpenAI) to use for this request.
@@ -1365,7 +1398,7 @@ Mono<Response<BinaryData>> getImageGenerationsWithResponse(String deploymentOrMo
13651398
* completion of {@link Mono}.
13661399
*/
13671400
@ServiceMethod(returns = ReturnType.SINGLE)
1368-
Mono<Response<ImageGenerations>> getImageGenerationsWithResponse(String deploymentOrModelName,
1401+
public Mono<Response<ImageGenerations>> getImageGenerationsWithResponse(String deploymentOrModelName,
13691402
ImageGenerationOptions imageGenerationOptions, RequestOptions requestOptions) {
13701403
return getImageGenerationsWithResponse(deploymentOrModelName, BinaryData.fromObject(imageGenerationOptions),
13711404
requestOptions)

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,39 @@ Response<BinaryData> getImageGenerationsWithResponse(String deploymentOrModelNam
13131313

13141314
/**
13151315
* Creates an image given a prompt.
1316+
* <p>
1317+
* <strong>Request Body Schema</strong>
1318+
* </p>
1319+
*
1320+
* <pre>{@code
1321+
* {
1322+
* model: String (Optional)
1323+
* prompt: String (Required)
1324+
* n: Integer (Optional)
1325+
* size: String(256x256/512x512/1024x1024/1792x1024/1024x1792) (Optional)
1326+
* response_format: String(url/b64_json) (Optional)
1327+
* quality: String(standard/hd) (Optional)
1328+
* style: String(natural/vivid) (Optional)
1329+
* user: String (Optional)
1330+
* }
1331+
* }</pre>
1332+
*
1333+
* <p>
1334+
* <strong>Response Body Schema</strong>
1335+
* </p>
1336+
*
1337+
* <pre>{@code
1338+
* {
1339+
* created: long (Required)
1340+
* data (Required): [
1341+
* (Required){
1342+
* url: String (Optional)
1343+
* b64_json: String (Optional)
1344+
* revised_prompt: String (Optional)
1345+
* }
1346+
* ]
1347+
* }
1348+
* }</pre>
13161349
*
13171350
* @param deploymentOrModelName Specifies either the model deployment name (when using Azure OpenAI) or model name
13181351
* (when using non-Azure OpenAI) to use for this request.
@@ -1325,7 +1358,7 @@ Response<BinaryData> getImageGenerationsWithResponse(String deploymentOrModelNam
13251358
* @return the result of a successful image generation operation along with {@link Response}.
13261359
*/
13271360
@ServiceMethod(returns = ReturnType.SINGLE)
1328-
Response<ImageGenerations> getImageGenerationsWithResponse(String deploymentOrModelName,
1361+
public Response<ImageGenerations> getImageGenerationsWithResponse(String deploymentOrModelName,
13291362
ImageGenerationOptions imageGenerationOptions, RequestOptions requestOptions) {
13301363
Response<BinaryData> response = getImageGenerationsWithResponse(deploymentOrModelName,
13311364
BinaryData.fromObject(imageGenerationOptions), requestOptions);

sdk/openai/azure-ai-openai/src/test/java/com/azure/ai/openai/NonAzureOpenAIAsyncClientTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,20 @@ public void testGenerateImage(HttpClient httpClient, OpenAIServiceVersion servic
288288
.verifyComplete());
289289
}
290290

291+
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
292+
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
293+
public void testGenerateImageWithResponse(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {
294+
client = getNonAzureOpenAIAsyncClient(httpClient);
295+
getImageGenerationWithResponseRunner(deploymentId -> options -> requestOptions -> {
296+
StepVerifier.create(client.getImageGenerationsWithResponse(deploymentId, options, requestOptions))
297+
.assertNext(response -> {
298+
assertResponseRequestHeader(response.getRequest());
299+
assertImageGenerations(response.getValue());
300+
})
301+
.verifyComplete();
302+
});
303+
}
304+
291305
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
292306
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
293307
public void testChatFunctionAutoPreset(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {

sdk/openai/azure-ai-openai/src/test/java/com/azure/ai/openai/NonAzureOpenAISyncClientTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.azure.ai.openai.models.Embeddings;
2424
import com.azure.ai.openai.models.FunctionCall;
2525
import com.azure.ai.openai.models.FunctionCallConfig;
26+
import com.azure.ai.openai.models.ImageGenerations;
2627
import com.azure.ai.openai.models.SpeechGenerationResponseFormat;
2728
import com.azure.core.credential.KeyCredential;
2829
import com.azure.core.exception.ClientAuthenticationException;
@@ -243,6 +244,17 @@ public void testGenerateImage(HttpClient httpClient, OpenAIServiceVersion servic
243244
assertImageGenerations(client.getImageGenerations(deploymentOrModelName, options)));
244245
}
245246

247+
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
248+
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
249+
public void testGenerateImageWithResponse(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {
250+
client = getNonAzureOpenAISyncClient(httpClient);
251+
getImageGenerationWithResponseRunner(deploymentId -> options -> requestOptions -> {
252+
Response<ImageGenerations> response = client.getImageGenerationsWithResponse(deploymentId, options, requestOptions);
253+
assertResponseRequestHeader(response.getRequest());
254+
assertImageGenerations(response.getValue());
255+
});
256+
}
257+
246258
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
247259
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
248260
public void testChatFunctionAutoPreset(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {

sdk/openai/azure-ai-openai/src/test/java/com/azure/ai/openai/OpenAIAsyncClientTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ public void testGenerateImage(HttpClient httpClient, OpenAIServiceVersion servic
286286
.verifyComplete());
287287
}
288288

289+
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
290+
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
291+
public void testGenerateImageWithResponse(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {
292+
client = getOpenAIAsyncClient(httpClient, serviceVersion);
293+
getImageGenerationWithResponseRunner(deploymentId -> options -> requestOptions -> {
294+
StepVerifier.create(client.getImageGenerationsWithResponse(deploymentId, options, requestOptions))
295+
.assertNext(response -> {
296+
assertResponseRequestHeader(response.getRequest());
297+
assertImageGenerationsForAzure(response.getValue());
298+
}).verifyComplete();
299+
});
300+
}
301+
289302
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
290303
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
291304
public void testContentFilterInputExceptionInImageGeneration(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {

sdk/openai/azure-ai-openai/src/test/java/com/azure/ai/openai/OpenAIClientTestBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ void getImageGenerationRunner(BiConsumer<String, ImageGenerationOptions> testRun
274274
);
275275
}
276276

277+
void getImageGenerationWithResponseRunner(Function<String, Function<ImageGenerationOptions, Consumer<RequestOptions>>> testRunner) {
278+
testRunner.apply("dall-e-3")
279+
.apply(new ImageGenerationOptions("A drawing of the Seattle skyline in the style of Van Gogh"))
280+
.accept(getRequestOption());
281+
}
282+
277283
void contentFilterInputExceptionRunner(BiConsumer<String, ImageGenerationOptions> testRunner) {
278284
testRunner.accept("dall-e-3", new ImageGenerationOptions("Go kill yourself"));
279285
}

sdk/openai/azure-ai-openai/src/test/java/com/azure/ai/openai/OpenAISyncClientTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.azure.ai.openai.models.Embeddings;
2727
import com.azure.ai.openai.models.FunctionCall;
2828
import com.azure.ai.openai.models.FunctionCallConfig;
29+
import com.azure.ai.openai.models.ImageGenerations;
2930
import com.azure.ai.openai.models.OnYourDataApiKeyAuthenticationOptions;
3031
import com.azure.ai.openai.models.OnYourDataContextProperty;
3132
import com.azure.ai.openai.models.SpeechGenerationResponseFormat;
@@ -240,6 +241,17 @@ public void testGenerateImage(HttpClient httpClient, OpenAIServiceVersion servic
240241
assertImageGenerationsForAzure(client.getImageGenerations(deploymentId, options)));
241242
}
242243

244+
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
245+
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
246+
public void testGenerateImageWithResponse(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {
247+
client = getOpenAIClient(httpClient, serviceVersion);
248+
getImageGenerationWithResponseRunner(deploymentId -> options -> requestOptions -> {
249+
Response<ImageGenerations> response = client.getImageGenerationsWithResponse(deploymentId, options, requestOptions);
250+
assertResponseRequestHeader(response.getRequest());
251+
assertImageGenerationsForAzure(response.getValue());
252+
});
253+
}
254+
243255
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
244256
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
245257
public void testContentFilterInputExceptionInImageGeneration(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {

0 commit comments

Comments
 (0)