This commit is contained in:
Deyaaeldeen Almahallawi 2024-11-20 21:09:00 +02:00 коммит произвёл GitHub
Родитель 93ad213554
Коммит de56a388eb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
18 изменённых файлов: 71 добавлений и 61 удалений

Просмотреть файл

@ -3,9 +3,9 @@
import { assert, describe, beforeEach, it } from "vitest";
import { matrix } from "@azure-tools/test-utils-vitest";
import OpenAI, { AzureOpenAI } from "openai";
import type { OpenAI, AzureOpenAI } from "openai";
import { createClient } from "./utils/createClient.js";
import { APIMatrix, APIVersion } from "./utils/utils.js";
import { APIMatrix, type APIVersion } from "./utils/utils.js";
describe("AbortSignal", () => {
let client: AzureOpenAI | OpenAI;
@ -31,7 +31,6 @@ describe("AbortSignal", () => {
];
const deploymentName = "gpt-35-turbo";
let currentMessage = "";
try {
const events = client.beta.chat.completions.stream({
model: deploymentName,
@ -46,7 +45,6 @@ describe("AbortSignal", () => {
assert.isDefined(event);
events.abort();
}
assert.isDefined(currentMessage);
assert.fail("Expected to abort streaming");
} catch (error: any) {
assert.isTrue(error.message.includes("aborted"));

Просмотреть файл

@ -5,8 +5,8 @@ import { matrix } from "@azure-tools/test-utils-vitest";
import { assert, describe, beforeEach, it } from "vitest";
import { assertAssistantEquality } from "./utils/asserts.js";
import { createClient } from "./utils/createClient.js";
import OpenAI, { AzureOpenAI } from "openai";
import { APIVersion, isRateLimitRun, Metadata } from "./utils/utils.js";
import type { OpenAI, AzureOpenAI } from "openai";
import { APIVersion, isRateLimitRun, type Metadata } from "./utils/utils.js";
describe("OpenAIAssistants", () => {
matrix([[APIVersion.Preview]] as const, async function (apiVersion: APIVersion) {
@ -217,7 +217,7 @@ describe("OpenAIAssistants", () => {
}
const instructions =
"Please address the user as Jane Doe. The user has a premium account.";
let run = await client.beta.threads.runs.createAndPoll(thread.id, {
const run = await client.beta.threads.runs.createAndPoll(thread.id, {
assistant_id: assistant.id,
instructions,
});

Просмотреть файл

@ -4,8 +4,8 @@
import { matrix } from "@azure-tools/test-utils-vitest";
import { assert, describe, beforeEach, it, beforeAll } from "vitest";
import { createClient } from "./utils/createClient.js";
import { APIMatrix, APIVersion, DeploymentInfo } from "./utils/utils.js";
import OpenAI, { AzureOpenAI } from "openai";
import { APIMatrix, type APIVersion, type DeploymentInfo } from "./utils/utils.js";
import type { OpenAI, AzureOpenAI } from "openai";
import {
assertChatCompletions,
assertChatCompletionsList,
@ -20,7 +20,7 @@ import {
updateWithSucceeded,
withDeployments,
} from "./utils/utils.js";
import { ChatCompletionMessageParam } from "openai/resources/chat/completions.mjs";
import { type ChatCompletionMessageParam } from "openai/resources/chat/completions.mjs";
import { completionsModelsToSkip, functionCallModelsToSkip } from "./utils/models.js";
import "../../src/types/index.js";
@ -364,7 +364,7 @@ describe("Completions", function () {
if (!content) assert.fail("Undefined content");
try {
JSON.parse(content);
} catch (e) {
} catch {
assert.fail(`Invalid JSON: ${content}`);
}
},

Просмотреть файл

@ -6,12 +6,12 @@ import { describe, it, beforeAll } from "vitest";
import { createClient } from "./utils/createClient.js";
import {
APIMatrix,
APIVersion,
DeploymentInfo,
type APIVersion,
type DeploymentInfo,
getDeployments,
withDeployments,
} from "./utils/utils.js";
import OpenAI, { AzureOpenAI } from "openai";
import type { OpenAI, AzureOpenAI } from "openai";
import { assertEmbeddings } from "./utils/asserts.js";
describe("Embeddings", function () {

Просмотреть файл

@ -5,15 +5,15 @@ import { matrix } from "@azure-tools/test-utils-vitest";
import { createClient } from "./utils/createClient.js";
import {
APIMatrix,
APIVersion,
DeploymentInfo,
type APIVersion,
type DeploymentInfo,
getDeployments,
getSucceeded,
updateWithSucceeded,
withDeployments,
} from "./utils/utils.js";
import { assertImagesWithJSON, assertImagesWithURLs } from "./utils/asserts.js";
import OpenAI, { AzureOpenAI } from "openai";
import type { OpenAI, AzureOpenAI } from "openai";
import { describe, it, beforeAll } from "vitest";
describe("Images", function () {

Просмотреть файл

@ -3,7 +3,7 @@
import { matrix } from "@azure-tools/test-utils-vitest";
import { assert, describe, beforeEach, it } from "vitest";
import OpenAI, { AzureOpenAI, toFile } from "openai";
import { type OpenAI, type AzureOpenAI, toFile } from "openai";
import { createClient } from "../utils/createClient.js";
import { APIVersion } from "../utils/utils.js";

Просмотреть файл

@ -1,13 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// Licensed under the MIT License.
import { matrix } from "@azure-tools/test-utils-vitest";
import { describe, beforeEach, it } from "vitest";
import OpenAI, { AzureOpenAI, toFile } from "openai";
import { type OpenAI, type AzureOpenAI, toFile } from "openai";
import { createClient } from "../utils/createClient.js";
import { APIVersion, DeploymentInfo, getDeployments, withDeployments } from "../utils/utils.js";
import {
APIVersion,
type DeploymentInfo,
getDeployments,
withDeployments,
} from "../utils/utils.js";
import { assertBatch, assertNonEmptyArray } from "../utils/asserts.js";
import { delay } from "@azure-tools/test-recorder";
import type { FileObject } from "openai/resources/index";
describe("Batches", () => {
matrix([[APIVersion.Preview]] as const, async function (apiVersion: APIVersion) {
@ -21,9 +27,9 @@ describe("Batches", () => {
});
describe("all CRUD APIs", function () {
async function createBatchFile(deploymentName: string) {
async function createBatchFile(deploymentName: string): Promise<FileObject> {
const inputObject = `{ "custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": { "model": "${deploymentName}", "messages": [{ "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "What is 2+2?" }] } }`;
let file = await client.files.create({
const file = await client.files.create({
file: await toFile(Buffer.from(inputObject), "batch.jsonl"),
purpose: "batch",
});

Просмотреть файл

@ -5,17 +5,17 @@ import { createReadStream } from "fs";
import { matrix } from "@azure-tools/test-utils-vitest";
import { describe, it, beforeAll } from "vitest";
import { createClient } from "../utils/createClient.js";
import OpenAI, { AzureOpenAI } from "openai";
import type { OpenAI, AzureOpenAI } from "openai";
import {
APIMatrix,
APIVersion,
DeploymentInfo,
type APIVersion,
type DeploymentInfo,
getDeployments,
maxRetriesOption,
withDeployments,
} from "../utils/utils.js";
import { assertAudioResult } from "../utils/asserts.js";
import { AudioResultFormat } from "../utils/audioTypes.js";
import type { AudioResultFormat } from "../utils/audioTypes.js";
describe("OpenAI", function () {
matrix([APIMatrix] as const, async function (apiVersion: APIVersion) {

Просмотреть файл

@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// Licensed under the MIT License.
import { matrix } from "@azure-tools/test-utils-vitest";
import { describe, beforeEach, it, assert, beforeAll } from "vitest";
import { createClient } from "./utils/createClient.js";
import { APIVersion, DeploymentInfo, getDeployments, withDeployments } from "./utils/utils.js";
import OpenAI, { AzureOpenAI } from "openai";
import { APIVersion, type DeploymentInfo, getDeployments, withDeployments } from "./utils/utils.js";
import type { OpenAI, AzureOpenAI } from "openai";
import { ttsModelsToSkip } from "./utils/models.js";
describe("OpenAI", function () {

Просмотреть файл

@ -1,7 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { assert } from "vitest";
import { get, Metadata } from "./utils.js";
import { get, type Metadata } from "./utils.js";
import { getImageDimensionsFromResponse, getImageDimensionsFromString } from "./images.js";
import {
import type {
AzureChatExtensionDataSourceResponseCitationOutput,
AzureChatExtensionsMessageContextOutput,
ContentFilterCitedDetectionResultOutput,
@ -11,8 +14,8 @@ import {
ContentFilterResultsForChoiceOutput,
ContentFilterResultsForPromptOutput,
} from "../../../src/types/index.js";
import { Assistant, AssistantCreateParams } from "openai/resources/beta/assistants.mjs";
import {
import type { Assistant, AssistantCreateParams } from "openai/resources/beta/assistants.mjs";
import type {
Batch,
BatchError,
BatchRequestCounts,
@ -25,13 +28,13 @@ import {
CreateEmbeddingResponse,
ImagesResponse,
} from "openai/resources/index";
import { ErrorModel } from "@azure-rest/core-client";
import {
import type { ErrorModel } from "@azure-rest/core-client";
import type {
ChatCompletion,
ChatCompletionMessageToolCall,
} from "openai/resources/chat/completions.mjs";
import { Transcription } from "openai/resources/audio/transcriptions.mjs";
import { AudioSegment, AudioResultVerboseJson, AudioResultFormat } from "./audioTypes.js";
import type { Transcription } from "openai/resources/audio/transcriptions.mjs";
import type { AudioSegment, AudioResultVerboseJson, AudioResultFormat } from "./audioTypes.js";
export function assertAudioResult(responseFormat: AudioResultFormat, result: Transcription): void {
switch (responseFormat) {
@ -83,7 +86,7 @@ export function assertChatCompletions(
function assertChatCompletionsNoUsage(
completions: ChatCompletion,
{ allowEmptyChoices, allowEmptyId, ...opts }: ChatCompletionTestOptions,
{ allowEmptyChoices, ...opts }: ChatCompletionTestOptions,
): void {
if (!allowEmptyChoices || completions.choices.length > 0) {
assertNonEmptyArray(completions.choices, (choice) => assertChoice(choice, opts));
@ -93,7 +96,7 @@ function assertChatCompletionsNoUsage(
function assertChatCompletionsChunkNoUsage(
completions: ChatCompletionChunk,
{ allowEmptyChoices, allowEmptyId, ...opts }: ChatCompletionTestOptions,
{ allowEmptyChoices, ...opts }: ChatCompletionTestOptions,
): void {
if (!allowEmptyChoices || completions.choices.length > 0) {
assertNonEmptyArray(completions.choices, (choice) => assertChoice(choice, opts));
@ -220,8 +223,8 @@ function assertChoice(
if (stream) {
const delta = (choice as ChatCompletionChunk.Choice).delta;
// TODO: Relevant issue https://github.com/openai/openai-python/issues/1677
ifDefined(delta, (delta) => {
assertMessage(delta, options);
ifDefined(delta, (d) => {
assertMessage(d, options);
});
assert.isFalse("message" in choice);
} else {
@ -384,7 +387,7 @@ export function assertImagesWithJSON(image: ImagesResponse, height: number, widt
export function assertEmbeddings(
embeddings: CreateEmbeddingResponse,
options?: EmbeddingTestOptions,
) {
): void {
assert.isNotNull(embeddings.data);
assert.equal(embeddings.data.length > 0, true);
assert.isNotNull(embeddings.data[0].embedding);

Просмотреть файл

@ -1,4 +1,7 @@
import { Transcription } from "openai/resources/audio/transcriptions.mjs";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import type { Transcription } from "openai/resources/audio/transcriptions.mjs";
export type AudioResultFormat = "json" | "verbose_json" | "text" | "srt" | "vtt";

Просмотреть файл

@ -3,11 +3,11 @@
import {
Recorder,
RecorderStartOptions,
TestInfo,
type RecorderStartOptions,
type TestInfo,
assertEnvironmentVariable,
} from "@azure-tools/test-recorder";
import OpenAI, { AzureClientOptions, AzureOpenAI } from "openai";
import OpenAI, { type AzureClientOptions, AzureOpenAI } from "openai";
import { getBearerTokenProvider } from "@azure/identity";
import {
EnvironmentVariableNames,
@ -15,7 +15,7 @@ import {
EnvironmentVariableNamesForVision,
EnvironmentVariableNamesForAudio,
} from "./envVars.js";
import { APIVersion, DeploymentType } from "./utils.js";
import { APIVersion, type DeploymentType } from "./utils.js";
import { createTestCredential } from "@azure-tools/test-credential";
const scope = "https://cognitiveservices.azure.com/.default";

Просмотреть файл

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { PipelineResponse } from "@azure/core-rest-pipeline";
import type { PipelineResponse } from "@azure/core-rest-pipeline";
interface Dimensions {
width: number;

Просмотреть файл

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { PipelineResponse } from "@azure/core-rest-pipeline";
import type { PipelineResponse } from "@azure/core-rest-pipeline";
export interface Dimensions {
width: number;

Просмотреть файл

@ -2,7 +2,7 @@
// Licensed under the MIT License.
import { afterAll, beforeAll, inject } from "vitest";
import { AzureLogLevel, setLogLevel } from "@azure/logger";
import { type AzureLogLevel, setLogLevel } from "@azure/logger";
const logLevel = inject("AZURE_LOG_LEVEL") as AzureLogLevel;
const localStorage: { debug?: string } = {};

Просмотреть файл

@ -6,10 +6,10 @@ enum EnvVarKeys {
AZURE_LOG_LEVEL = "AZURE_LOG_LEVEL",
}
declare module "vitest" {
type MyEnvVarKeys = {
type MyEnvVarKey = {
[K in keyof typeof EnvVarKeys]: string;
};
export interface ProvidedContext extends MyEnvVarKeys {}
export interface ProvidedContext extends MyEnvVarKey {}
}
const defaultLogLevel = "info";
@ -28,7 +28,7 @@ function assertEnvironmentVariable(key: string): string {
return value;
}
export default async function ({ provide }: GlobalSetupContext) {
export default async function ({ provide }: GlobalSetupContext): Promise<() => void> {
for (const key of Object.values(EnvVarKeys)) {
provide(key, assertEnvironmentVariable(key));
}

Просмотреть файл

@ -3,8 +3,8 @@
import { assert } from "vitest";
import {
PipelineRequest,
PipelineResponse,
type PipelineRequest,
type PipelineResponse,
RestError,
createDefaultHttpClient,
createEmptyPipeline,
@ -21,9 +21,9 @@ import {
EnvironmentVariableNamesForVision,
EnvironmentVariableNamesForAudio,
} from "./envVars.js";
import { Run } from "openai/resources/beta/threads/runs/runs.mjs";
import type { Run } from "openai/resources/beta/threads/runs/runs.mjs";
import { createClientLogger } from "@azure/logger";
import { AzureChatExtensionConfiguration } from "../../../src/types/models.js";
import type { AzureChatExtensionConfiguration } from "../../../src/types/models.js";
const logger = createClientLogger("openai");

Просмотреть файл

@ -7,12 +7,12 @@ import { createClient } from "./utils/createClient.js";
import { assertChatCompletions } from "./utils/asserts.js";
import {
APIMatrix,
APIVersion,
DeploymentInfo,
type APIVersion,
type DeploymentInfo,
getDeployments,
withDeployments,
} from "./utils/utils.js";
import OpenAI, { AzureOpenAI } from "openai";
import type { OpenAI, AzureOpenAI } from "openai";
import { logger } from "@azure/identity";
import { RestError } from "@azure/core-rest-pipeline";
import { visionModelsToSkip } from "./utils/models.js";