Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ export interface FileContentResponse {
content: Uint8Array;
}

// @public
export type FileContents = string | NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array | Blob;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious why this is added? is this expected?

Copy link
Copy Markdown
Member Author

@timovv timovv Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this spec has an anonymous model for MFD which isn't properly supported yet. FileContents should be used in uploadFile but is currently Uint8Array. Will fix.

Copy link
Copy Markdown
Member Author

@timovv timovv Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address anonymous models including this case in a follow up issue


// @public
export interface FileDeletionStatus {
deleted: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { FileContents } from "./static-helpers/multipartHelpers.js";
import {
PageSettings,
ContinuablePage,
Expand Down Expand Up @@ -274,3 +275,4 @@ export {
EvaluationsOperations,
} from "./classic/index.js";
export { PageSettings, ContinuablePage, PagedAsyncIterableIterator };
export { FileContents };
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
* Valid values for the contents of a binary file.
*/
export type FileContents =
| string
| NodeJS.ReadableStream
| ReadableStream<Uint8Array>
| Uint8Array
| Blob;

export function createFilePartDescriptor(
partName: string,
fileInput: any,
defaultContentType?: string,
): any {
if (fileInput.contents) {
return {
name: partName,
body: fileInput.contents,
contentType: fileInput.contentType ?? defaultContentType,
filename: fileInput.filename,
};
} else {
return {
name: partName,
body: fileInput,
contentType: defaultContentType,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ export interface CreateEmbeddingResponse {

// @public
export interface CreateFileRequest {
file: Uint8Array;
file: FileContents | {
contents: FileContents;
contentType?: string;
filename?: string;
};
purpose: string;
}

Expand Down Expand Up @@ -258,8 +262,16 @@ export interface CreateFineTuningJobRequest {

// @public
export interface CreateImageEditRequest {
image: Uint8Array;
mask?: Uint8Array;
image: FileContents | {
contents: FileContents;
contentType?: string;
filename?: string;
};
mask?: FileContents | {
contents: FileContents;
contentType?: string;
filename?: string;
};
n?: number | null;
prompt: string;
response_format?: ("url" | "b64_json") | null;
Expand All @@ -280,7 +292,11 @@ export interface CreateImageRequest {

// @public
export interface CreateImageVariationRequest {
image: Uint8Array;
image: FileContents | {
contents: FileContents;
contentType?: string;
filename?: string;
};
n?: number | null;
response_format?: ("url" | "b64_json") | null;
size?: ("256x256" | "512x512" | "1024x1024") | null;
Expand Down Expand Up @@ -331,7 +347,11 @@ export interface CreateModerationResponse {

// @public
export interface CreateTranscriptionRequest {
file: Uint8Array;
file: FileContents | {
contents: FileContents;
contentType?: string;
filename?: string;
};
language?: string;
model: "whisper-1";
prompt?: string;
Expand All @@ -347,7 +367,11 @@ export interface CreateTranscriptionResponse {

// @public
export interface CreateTranslationRequest {
file: Uint8Array;
file: FileContents | {
contents: FileContents;
contentType?: string;
filename?: string;
};
model: "whisper-1";
prompt?: string;
response_format?: "json" | "text" | "srt" | "verbose_json" | "vtt";
Expand Down Expand Up @@ -407,6 +431,9 @@ export interface EmbeddingsOperations {
create: (embedding: CreateEmbeddingRequest, options?: EmbeddingsCreateOptionalParams) => Promise<CreateEmbeddingResponse>;
}

// @public
export type FileContents = string | NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array | Blob;

// @public
export interface FilesCreateOptionalParams extends OperationOptions {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { FileContents } from "./static-helpers/multipartHelpers.js";

export { OpenAIClient } from "./openAIClient.js";
export {
CreateModerationRequest,
Expand Down Expand Up @@ -97,3 +99,4 @@ export {
ChatCompletionsOperations,
FineTuningJobsOperations,
} from "./classic/index.js";
export { FileContents };
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { uint8ArrayToString, stringToUint8Array } from "@azure/core-util";
import {
FileContents,
createFilePartDescriptor,
} from "../static-helpers/multipartHelpers.js";
import { stringToUint8Array } from "@azure/core-util";

/** model interface CreateModerationRequest */
export interface CreateModerationRequest {
Expand Down Expand Up @@ -316,13 +320,17 @@ export interface CreateImageEditRequest {
* The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not
* provided, image must have transparency, which will be used as the mask.
*/
image: Uint8Array;
image:
| FileContents
| { contents: FileContents; contentType?: string; filename?: string };
/**
* An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where
* `image` should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions
* as `image`.
*/
mask?: Uint8Array;
mask?:
| FileContents
| { contents: FileContents; contentType?: string; filename?: string };
/** The number of images to generate. Must be between 1 and 10. */
n?: number | null;
/** The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. */
Expand All @@ -335,17 +343,23 @@ export interface CreateImageEditRequest {
export function createImageEditRequestSerializer(
item: CreateImageEditRequest,
): any {
return {
prompt: item["prompt"],
image: uint8ArrayToString(item["image"], "base64"),
mask: !item["mask"]
? item["mask"]
: uint8ArrayToString(item["mask"], "base64"),
n: item["n"],
size: item["size"],
response_format: item["response_format"],
user: item["user"],
};
return [
{ name: "prompt", body: item["prompt"] },
createFilePartDescriptor("image", item["image"], undefined),
...(item["mask"] === undefined
? []
: [createFilePartDescriptor("mask", item["mask"], undefined)]),
...(item["n"] === undefined ? [] : [{ name: "n", body: item["n"] }]),
...(item["size"] === undefined
? []
: [{ name: "size", body: item["size"] }]),
...(item["response_format"] === undefined
? []
: [{ name: "response_format", body: item["response_format"] }]),
...(item["user"] === undefined
? []
: [{ name: "user", body: item["user"] }]),
];
}

/** model interface CreateImageVariationRequest */
Expand All @@ -354,7 +368,9 @@ export interface CreateImageVariationRequest {
* The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB,
* and square.
*/
image: Uint8Array;
image:
| FileContents
| { contents: FileContents; contentType?: string; filename?: string };
/** The number of images to generate. Must be between 1 and 10. */
n?: number | null;
/** The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. */
Expand All @@ -367,13 +383,19 @@ export interface CreateImageVariationRequest {
export function createImageVariationRequestSerializer(
item: CreateImageVariationRequest,
): any {
return {
image: uint8ArrayToString(item["image"], "base64"),
n: item["n"],
size: item["size"],
response_format: item["response_format"],
user: item["user"],
};
return [
createFilePartDescriptor("image", item["image"], undefined),
...(item["n"] === undefined ? [] : [{ name: "n", body: item["n"] }]),
...(item["size"] === undefined
? []
: [{ name: "size", body: item["size"] }]),
...(item["response_format"] === undefined
? []
: [{ name: "response_format", body: item["response_format"] }]),
...(item["user"] === undefined
? []
: [{ name: "user", body: item["user"] }]),
];
}

/** model interface ListModelsResponse */
Expand Down Expand Up @@ -801,7 +823,9 @@ export interface CreateFileRequest {
*
* If the `purpose` is set to "fine-tune", the file will be used for fine-tuning.
*/
file: Uint8Array;
file:
| FileContents
| { contents: FileContents; contentType?: string; filename?: string };
/**
* The intended purpose of the uploaded documents. Use "fine-tune" for
* [fine-tuning](/docs/api-reference/fine-tuning). This allows us to validate the format of the
Expand All @@ -811,10 +835,10 @@ export interface CreateFileRequest {
}

export function createFileRequestSerializer(item: CreateFileRequest): any {
return {
file: uint8ArrayToString(item["file"], "base64"),
purpose: item["purpose"],
};
return [
createFilePartDescriptor("file", item["file"], undefined),
{ name: "purpose", body: item["purpose"] },
];
}

/** model interface DeleteFileResponse */
Expand Down Expand Up @@ -2019,7 +2043,9 @@ export interface CreateTranslationRequest {
* The audio file object (not file name) to translate, in one of these formats: flac, mp3, mp4,
* mpeg, mpga, m4a, ogg, wav, or webm.
*/
file: Uint8Array;
file:
| FileContents
| { contents: FileContents; contentType?: string; filename?: string };
/** ID of the model to use. Only `whisper-1` is currently available. */
model: "whisper-1";
/**
Expand All @@ -2044,13 +2070,19 @@ export interface CreateTranslationRequest {
export function createTranslationRequestSerializer(
item: CreateTranslationRequest,
): any {
return {
file: uint8ArrayToString(item["file"], "base64"),
model: item["model"],
prompt: item["prompt"],
response_format: item["response_format"],
temperature: item["temperature"],
};
return [
createFilePartDescriptor("file", item["file"], undefined),
{ name: "model", body: item["model"] },
...(item["prompt"] === undefined
? []
: [{ name: "prompt", body: item["prompt"] }]),
...(item["response_format"] === undefined
? []
: [{ name: "response_format", body: item["response_format"] }]),
...(item["temperature"] === undefined
? []
: [{ name: "temperature", body: item["temperature"] }]),
];
}

/** model interface CreateTranslationResponse */
Expand All @@ -2072,7 +2104,9 @@ export interface CreateTranscriptionRequest {
* The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4,
* mpeg, mpga, m4a, ogg, wav, or webm.
*/
file: Uint8Array;
file:
| FileContents
| { contents: FileContents; contentType?: string; filename?: string };
/** ID of the model to use. Only `whisper-1` is currently available. */
model: "whisper-1";
/**
Expand Down Expand Up @@ -2103,14 +2137,22 @@ export interface CreateTranscriptionRequest {
export function createTranscriptionRequestSerializer(
item: CreateTranscriptionRequest,
): any {
return {
file: uint8ArrayToString(item["file"], "base64"),
model: item["model"],
prompt: item["prompt"],
response_format: item["response_format"],
temperature: item["temperature"],
language: item["language"],
};
return [
createFilePartDescriptor("file", item["file"], undefined),
{ name: "model", body: item["model"] },
...(item["prompt"] === undefined
? []
: [{ name: "prompt", body: item["prompt"] }]),
...(item["response_format"] === undefined
? []
: [{ name: "response_format", body: item["response_format"] }]),
...(item["temperature"] === undefined
? []
: [{ name: "temperature", body: item["temperature"] }]),
...(item["language"] === undefined
? []
: [{ name: "language", body: item["language"] }]),
];
}

/** model interface CreateTranscriptionResponse */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/**
* Valid values for the contents of a binary file.
*/
export type FileContents =
| string
| NodeJS.ReadableStream
| ReadableStream<Uint8Array>
| Uint8Array
| Blob;

export function createFilePartDescriptor(
partName: string,
fileInput: any,
defaultContentType?: string,
): any {
if (fileInput.contents) {
return {
name: partName,
body: fileInput.contents,
contentType: fileInput.contentType ?? defaultContentType,
filename: fileInput.filename,
};
} else {
return {
name: partName,
body: fileInput,
contentType: defaultContentType,
};
}
}
Loading