Skip to content

Commit

Permalink
[openai] Record request to fetch generated image when checking dimens…
Browse files Browse the repository at this point in the history
…ions (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>
  • Loading branch information
timovv and minhanh-phan authored Aug 25, 2023
1 parent 5eb0035 commit 556b545
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sdk/openai/openai/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "js",
"TagPrefix": "js/openai/openai",
"Tag": "js/openai/openai_d5f951ca47"
"Tag": "js/openai/openai_5a9957cec2"
}
9 changes: 8 additions & 1 deletion sdk/openai/openai/test/public/openai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { logger } from "./utils/logger.js";
import {
createDefaultHttpClient,
createEmptyPipeline,
createHttpHeaders,
createPipelineRequest,
} from "@azure/core-rest-pipeline";
Expand Down Expand Up @@ -396,14 +397,20 @@ describe("OpenAI", function () {

async function checkSize(imageUrl: string): Promise<void> {
const coreClient = createDefaultHttpClient();
const pipeline = createEmptyPipeline();

// Inject the recorder pipeline policy so that the request for image size gets recorded
pipeline.addPolicy(recorder.configureClientOptions({}).additionalPolicies![0].policy);

const set = new Set<number>();
const request = createPipelineRequest({
url: imageUrl,
method: "GET",
headers: createHttpHeaders(),
streamResponseStatusCodes: set.add(200),
});
const response = await coreClient.sendRequest(request);

const response = await pipeline.sendRequest(coreClient, request);

const dimensions = await getImageDimensions(response);
assert.isDefined(dimensions, "Unable to get dimensions");
Expand Down
9 changes: 9 additions & 0 deletions sdk/openai/openai/test/public/utils/recordedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ const envSetupForPlayback: { [k: string]: string } = {

const recorderStartOptions: RecorderStartOptions = {
envSetupForPlayback,
sanitizerOptions: {
generalSanitizers: [
{
regex: true,
target: `\\.png?[^"]+`,
value: ".png?sanitized",
},
],
},
};

export type AuthMethod = "AzureAPIKey" | "OpenAIKey" | "AAD" | "DummyAPIKey";
Expand Down

0 comments on commit 556b545

Please sign in to comment.