Skip to content

Commit 7968d68

Browse files
authored
Refactor completions.spec.ts to use testWithDeployments (Azure#33642)
1 parent 61a8ba6 commit 7968d68

File tree

1 file changed

+45
-51
lines changed

1 file changed

+45
-51
lines changed
Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import { matrix } from "@azure-tools/test-utils-vitest";
54
import { describe, beforeEach, it } from "vitest";
65
import { createClientsAndDeployments } from "../utils/createClients.js";
76
import type { APIVersion } from "../utils/utils.js";
@@ -11,46 +10,43 @@ import { completionsModelsToSkip } from "../utils/models.js";
1110
import "../../src/types/index.js";
1211
import type { ClientsAndDeploymentsInfo } from "../utils/types.js";
1312

14-
describe("Legacy Completions", function () {
15-
matrix([APIMatrix] as const, async function (apiVersion: APIVersion) {
16-
describe(`[${apiVersion}] Client`, () => {
17-
let clientsAndDeployments: ClientsAndDeploymentsInfo;
13+
describe.each(APIMatrix)("Legacy Completions [%s]", function (apiVersion: APIVersion) {
14+
let clientsAndDeployments: ClientsAndDeploymentsInfo;
1815

19-
beforeEach(async () => {
20-
clientsAndDeployments = createClientsAndDeployments(
21-
apiVersion,
22-
{ completion: "true" },
23-
{ clientOptions: { maxRetries: 0 }, deploymentsToSkip: ["computer-use-preview"] },
24-
);
25-
});
16+
beforeEach(async () => {
17+
clientsAndDeployments = createClientsAndDeployments(
18+
apiVersion,
19+
{ completion: "true" },
20+
{ clientOptions: { maxRetries: 0 }, deploymentsToSkip: ["computer-use-preview"] },
21+
);
22+
});
2623

27-
describe("completions.create", function () {
28-
it("returns completions across all models", async () => {
29-
const prompt = ["What is Azure OpenAI?"];
30-
await withDeployments(
31-
clientsAndDeployments,
32-
(client, deploymentName) =>
33-
client.completions.create({ model: deploymentName, prompt }),
34-
assertCompletions,
35-
completionsModelsToSkip,
36-
);
37-
});
24+
describe("completions.create", function () {
25+
it("returns completions across all models", async () => {
26+
const prompt = ["What is Azure OpenAI?"];
27+
await withDeployments(
28+
clientsAndDeployments,
29+
(client, deploymentName) => client.completions.create({ model: deploymentName, prompt }),
30+
assertCompletions,
31+
completionsModelsToSkip,
32+
);
33+
});
3834

39-
it("returns completions stream", async () => {
40-
const prompt = ["This is Azure OpenAI?"];
41-
await withDeployments(
42-
clientsAndDeployments,
43-
(client, deploymentName) =>
44-
client.completions.create({ model: deploymentName, prompt, stream: true }),
45-
// The API returns an empty choice in the first event for some
46-
// reason. This should be fixed in the API.
47-
(result) => assertCompletionsStream(result, { allowEmptyChoices: true }),
48-
);
49-
});
35+
it("returns completions stream", async () => {
36+
const prompt = ["This is Azure OpenAI?"];
37+
await withDeployments(
38+
clientsAndDeployments,
39+
(client, deploymentName) =>
40+
client.completions.create({ model: deploymentName, prompt, stream: true }),
41+
// The API returns an empty choice in the first event for some
42+
// reason. This should be fixed in the API.
43+
(result) => assertCompletionsStream(result, { allowEmptyChoices: true }),
44+
);
45+
});
5046

51-
it("stream long completions", async () => {
52-
const prompt = [
53-
`##### Translate this code snippet into Python. Use Azure SDKs where possible.
47+
it("stream long completions", async () => {
48+
const prompt = [
49+
`##### Translate this code snippet into Python. Use Azure SDKs where possible.
5450
\`\`\`
5551
using System.Threading.Tasks;
5652
using Microsoft.AspNetCore.Mvc;
@@ -104,21 +100,19 @@ describe("Legacy Completions", function () {
104100
105101
\`\`\`
106102
`,
107-
];
108-
await withDeployments(
109-
clientsAndDeployments,
110-
(client, deploymentName) =>
111-
client.completions.create(
112-
{ model: deploymentName, prompt, stream: true, max_tokens: 2048 },
113-
{ timeout: 10000 },
114-
),
103+
];
104+
await withDeployments(
105+
clientsAndDeployments,
106+
(client, deploymentName) =>
107+
client.completions.create(
108+
{ model: deploymentName, prompt, stream: true, max_tokens: 2048 },
109+
{ timeout: 10000 },
110+
),
115111

116-
// The API returns an empty choice in the first event for some
117-
// reason. This should be fixed in the API.
118-
(result) => assertCompletionsStream(result, { allowEmptyChoices: true }),
119-
);
120-
});
121-
});
112+
// The API returns an empty choice in the first event for some
113+
// reason. This should be fixed in the API.
114+
(result) => assertCompletionsStream(result, { allowEmptyChoices: true }),
115+
);
122116
});
123117
});
124118
});

0 commit comments

Comments
 (0)