Skip to content

Commit 556b545

Browse files
timovvminhanh-phan
andauthored
[openai] Record request to fetch generated image when checking dimensions (Azure#26950)
### Packages impacted by this PR - `@azure/openai` Fixes a request not being intercepted by the recorder --------- Co-authored-by: Minh-Anh Phan <111523473+minhanh-phan@users.noreply.github.com>
1 parent 5eb0035 commit 556b545

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

sdk/openai/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": "js",
44
"TagPrefix": "js/openai/openai",
5-
"Tag": "js/openai/openai_d5f951ca47"
5+
"Tag": "js/openai/openai_5a9957cec2"
66
}

sdk/openai/openai/test/public/openai.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { logger } from "./utils/logger.js";
2222
import {
2323
createDefaultHttpClient,
24+
createEmptyPipeline,
2425
createHttpHeaders,
2526
createPipelineRequest,
2627
} from "@azure/core-rest-pipeline";
@@ -396,14 +397,20 @@ describe("OpenAI", function () {
396397

397398
async function checkSize(imageUrl: string): Promise<void> {
398399
const coreClient = createDefaultHttpClient();
400+
const pipeline = createEmptyPipeline();
401+
402+
// Inject the recorder pipeline policy so that the request for image size gets recorded
403+
pipeline.addPolicy(recorder.configureClientOptions({}).additionalPolicies![0].policy);
404+
399405
const set = new Set<number>();
400406
const request = createPipelineRequest({
401407
url: imageUrl,
402408
method: "GET",
403409
headers: createHttpHeaders(),
404410
streamResponseStatusCodes: set.add(200),
405411
});
406-
const response = await coreClient.sendRequest(request);
412+
413+
const response = await pipeline.sendRequest(coreClient, request);
407414

408415
const dimensions = await getImageDimensions(response);
409416
assert.isDefined(dimensions, "Unable to get dimensions");

sdk/openai/openai/test/public/utils/recordedClient.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ const envSetupForPlayback: { [k: string]: string } = {
2424

2525
const recorderStartOptions: RecorderStartOptions = {
2626
envSetupForPlayback,
27+
sanitizerOptions: {
28+
generalSanitizers: [
29+
{
30+
regex: true,
31+
target: `\\.png?[^"]+`,
32+
value: ".png?sanitized",
33+
},
34+
],
35+
},
2736
};
2837

2938
export type AuthMethod = "AzureAPIKey" | "OpenAIKey" | "AAD" | "DummyAPIKey";

0 commit comments

Comments
 (0)