Skip to content

Commit 8c0bd25

Browse files
committed
Update TODO spec and regenerate openai specs with new MFD
1 parent e4e32d3 commit 8c0bd25

29 files changed

Lines changed: 933 additions & 272 deletions

File tree

packages/typespec-test/test/ai/generated/typespec-ts/review/ai-client.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,9 @@ export interface FileContentResponse {
646646
content: Uint8Array;
647647
}
648648

649+
// @public
650+
export type FileContents = string | NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array | Blob;
651+
649652
// @public
650653
export interface FileDeletionStatus {
651654
deleted: boolean;

packages/typespec-test/test/ai/generated/typespec-ts/src/index.ts

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

4+
import { FileContents } from "./static-helpers/multipartHelpers.js";
45
import {
56
PageSettings,
67
ContinuablePage,
@@ -274,3 +275,4 @@ export {
274275
EvaluationsOperations,
275276
} from "./classic/index.js";
276277
export { PageSettings, ContinuablePage, PagedAsyncIterableIterator };
278+
export { FileContents };
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
/**
5+
* Valid values for the contents of a binary file.
6+
*/
7+
export type FileContents =
8+
| string
9+
| NodeJS.ReadableStream
10+
| ReadableStream<Uint8Array>
11+
| Uint8Array
12+
| Blob;
13+
14+
export function createFilePartDescriptor(
15+
partName: string,
16+
fileInput: any,
17+
defaultContentType?: string,
18+
): any {
19+
if (fileInput.contents) {
20+
return {
21+
name: partName,
22+
body: fileInput.contents,
23+
contentType: fileInput.contentType ?? defaultContentType,
24+
filename: fileInput.filename,
25+
};
26+
} else {
27+
return {
28+
name: partName,
29+
body: fileInput,
30+
contentType: defaultContentType,
31+
};
32+
}
33+
}

packages/typespec-test/test/openai_generic/generated/typespec-ts/review/openai-generic.api.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,11 @@ export interface CreateEmbeddingResponse {
225225

226226
// @public
227227
export interface CreateFileRequest {
228-
file: Uint8Array;
228+
file: FileContents | {
229+
contents: FileContents;
230+
contentType?: string;
231+
filename?: string;
232+
};
229233
purpose: string;
230234
}
231235

@@ -258,8 +262,16 @@ export interface CreateFineTuningJobRequest {
258262

259263
// @public
260264
export interface CreateImageEditRequest {
261-
image: Uint8Array;
262-
mask?: Uint8Array;
265+
image: FileContents | {
266+
contents: FileContents;
267+
contentType?: string;
268+
filename?: string;
269+
};
270+
mask?: FileContents | {
271+
contents: FileContents;
272+
contentType?: string;
273+
filename?: string;
274+
};
263275
n?: number | null;
264276
prompt: string;
265277
response_format?: ("url" | "b64_json") | null;
@@ -280,7 +292,11 @@ export interface CreateImageRequest {
280292

281293
// @public
282294
export interface CreateImageVariationRequest {
283-
image: Uint8Array;
295+
image: FileContents | {
296+
contents: FileContents;
297+
contentType?: string;
298+
filename?: string;
299+
};
284300
n?: number | null;
285301
response_format?: ("url" | "b64_json") | null;
286302
size?: ("256x256" | "512x512" | "1024x1024") | null;
@@ -331,7 +347,11 @@ export interface CreateModerationResponse {
331347

332348
// @public
333349
export interface CreateTranscriptionRequest {
334-
file: Uint8Array;
350+
file: FileContents | {
351+
contents: FileContents;
352+
contentType?: string;
353+
filename?: string;
354+
};
335355
language?: string;
336356
model: "whisper-1";
337357
prompt?: string;
@@ -347,7 +367,11 @@ export interface CreateTranscriptionResponse {
347367

348368
// @public
349369
export interface CreateTranslationRequest {
350-
file: Uint8Array;
370+
file: FileContents | {
371+
contents: FileContents;
372+
contentType?: string;
373+
filename?: string;
374+
};
351375
model: "whisper-1";
352376
prompt?: string;
353377
response_format?: "json" | "text" | "srt" | "verbose_json" | "vtt";
@@ -407,6 +431,9 @@ export interface EmbeddingsOperations {
407431
create: (embedding: CreateEmbeddingRequest, options?: EmbeddingsCreateOptionalParams) => Promise<CreateEmbeddingResponse>;
408432
}
409433

434+
// @public
435+
export type FileContents = string | NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array | Blob;
436+
410437
// @public
411438
export interface FilesCreateOptionalParams extends OperationOptions {
412439
}

packages/typespec-test/test/openai_generic/generated/typespec-ts/src/index.ts

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

4+
import { FileContents } from "./static-helpers/multipartHelpers.js";
5+
46
export { OpenAIClient } from "./openAIClient.js";
57
export {
68
CreateModerationRequest,
@@ -97,3 +99,4 @@ export {
9799
ChatCompletionsOperations,
98100
FineTuningJobsOperations,
99101
} from "./classic/index.js";
102+
export { FileContents };

packages/typespec-test/test/openai_generic/generated/typespec-ts/src/models/models.ts

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

4-
import { uint8ArrayToString, stringToUint8Array } from "@azure/core-util";
4+
import {
5+
FileContents,
6+
createFilePartDescriptor,
7+
} from "../static-helpers/multipartHelpers.js";
8+
import { stringToUint8Array } from "@azure/core-util";
59

610
/** model interface CreateModerationRequest */
711
export interface CreateModerationRequest {
@@ -316,13 +320,17 @@ export interface CreateImageEditRequest {
316320
* The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not
317321
* provided, image must have transparency, which will be used as the mask.
318322
*/
319-
image: Uint8Array;
323+
image:
324+
| FileContents
325+
| { contents: FileContents; contentType?: string; filename?: string };
320326
/**
321327
* An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where
322328
* `image` should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions
323329
* as `image`.
324330
*/
325-
mask?: Uint8Array;
331+
mask?:
332+
| FileContents
333+
| { contents: FileContents; contentType?: string; filename?: string };
326334
/** The number of images to generate. Must be between 1 and 10. */
327335
n?: number | null;
328336
/** The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. */
@@ -335,17 +343,23 @@ export interface CreateImageEditRequest {
335343
export function createImageEditRequestSerializer(
336344
item: CreateImageEditRequest,
337345
): any {
338-
return {
339-
prompt: item["prompt"],
340-
image: uint8ArrayToString(item["image"], "base64"),
341-
mask: !item["mask"]
342-
? item["mask"]
343-
: uint8ArrayToString(item["mask"], "base64"),
344-
n: item["n"],
345-
size: item["size"],
346-
response_format: item["response_format"],
347-
user: item["user"],
348-
};
346+
return [
347+
{ name: "prompt", body: item["prompt"] },
348+
createFilePartDescriptor("image", item["image"], undefined),
349+
...(item["mask"] === undefined
350+
? []
351+
: [createFilePartDescriptor("mask", item["mask"], undefined)]),
352+
...(item["n"] === undefined ? [] : [{ name: "n", body: item["n"] }]),
353+
...(item["size"] === undefined
354+
? []
355+
: [{ name: "size", body: item["size"] }]),
356+
...(item["response_format"] === undefined
357+
? []
358+
: [{ name: "response_format", body: item["response_format"] }]),
359+
...(item["user"] === undefined
360+
? []
361+
: [{ name: "user", body: item["user"] }]),
362+
];
349363
}
350364

351365
/** model interface CreateImageVariationRequest */
@@ -354,7 +368,9 @@ export interface CreateImageVariationRequest {
354368
* The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB,
355369
* and square.
356370
*/
357-
image: Uint8Array;
371+
image:
372+
| FileContents
373+
| { contents: FileContents; contentType?: string; filename?: string };
358374
/** The number of images to generate. Must be between 1 and 10. */
359375
n?: number | null;
360376
/** The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. */
@@ -367,13 +383,19 @@ export interface CreateImageVariationRequest {
367383
export function createImageVariationRequestSerializer(
368384
item: CreateImageVariationRequest,
369385
): any {
370-
return {
371-
image: uint8ArrayToString(item["image"], "base64"),
372-
n: item["n"],
373-
size: item["size"],
374-
response_format: item["response_format"],
375-
user: item["user"],
376-
};
386+
return [
387+
createFilePartDescriptor("image", item["image"], undefined),
388+
...(item["n"] === undefined ? [] : [{ name: "n", body: item["n"] }]),
389+
...(item["size"] === undefined
390+
? []
391+
: [{ name: "size", body: item["size"] }]),
392+
...(item["response_format"] === undefined
393+
? []
394+
: [{ name: "response_format", body: item["response_format"] }]),
395+
...(item["user"] === undefined
396+
? []
397+
: [{ name: "user", body: item["user"] }]),
398+
];
377399
}
378400

379401
/** model interface ListModelsResponse */
@@ -801,7 +823,9 @@ export interface CreateFileRequest {
801823
*
802824
* If the `purpose` is set to "fine-tune", the file will be used for fine-tuning.
803825
*/
804-
file: Uint8Array;
826+
file:
827+
| FileContents
828+
| { contents: FileContents; contentType?: string; filename?: string };
805829
/**
806830
* The intended purpose of the uploaded documents. Use "fine-tune" for
807831
* [fine-tuning](/docs/api-reference/fine-tuning). This allows us to validate the format of the
@@ -811,10 +835,10 @@ export interface CreateFileRequest {
811835
}
812836

813837
export function createFileRequestSerializer(item: CreateFileRequest): any {
814-
return {
815-
file: uint8ArrayToString(item["file"], "base64"),
816-
purpose: item["purpose"],
817-
};
838+
return [
839+
createFilePartDescriptor("file", item["file"], undefined),
840+
{ name: "purpose", body: item["purpose"] },
841+
];
818842
}
819843

820844
/** model interface DeleteFileResponse */
@@ -2019,7 +2043,9 @@ export interface CreateTranslationRequest {
20192043
* The audio file object (not file name) to translate, in one of these formats: flac, mp3, mp4,
20202044
* mpeg, mpga, m4a, ogg, wav, or webm.
20212045
*/
2022-
file: Uint8Array;
2046+
file:
2047+
| FileContents
2048+
| { contents: FileContents; contentType?: string; filename?: string };
20232049
/** ID of the model to use. Only `whisper-1` is currently available. */
20242050
model: "whisper-1";
20252051
/**
@@ -2044,13 +2070,19 @@ export interface CreateTranslationRequest {
20442070
export function createTranslationRequestSerializer(
20452071
item: CreateTranslationRequest,
20462072
): any {
2047-
return {
2048-
file: uint8ArrayToString(item["file"], "base64"),
2049-
model: item["model"],
2050-
prompt: item["prompt"],
2051-
response_format: item["response_format"],
2052-
temperature: item["temperature"],
2053-
};
2073+
return [
2074+
createFilePartDescriptor("file", item["file"], undefined),
2075+
{ name: "model", body: item["model"] },
2076+
...(item["prompt"] === undefined
2077+
? []
2078+
: [{ name: "prompt", body: item["prompt"] }]),
2079+
...(item["response_format"] === undefined
2080+
? []
2081+
: [{ name: "response_format", body: item["response_format"] }]),
2082+
...(item["temperature"] === undefined
2083+
? []
2084+
: [{ name: "temperature", body: item["temperature"] }]),
2085+
];
20542086
}
20552087

20562088
/** model interface CreateTranslationResponse */
@@ -2072,7 +2104,9 @@ export interface CreateTranscriptionRequest {
20722104
* The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4,
20732105
* mpeg, mpga, m4a, ogg, wav, or webm.
20742106
*/
2075-
file: Uint8Array;
2107+
file:
2108+
| FileContents
2109+
| { contents: FileContents; contentType?: string; filename?: string };
20762110
/** ID of the model to use. Only `whisper-1` is currently available. */
20772111
model: "whisper-1";
20782112
/**
@@ -2103,14 +2137,22 @@ export interface CreateTranscriptionRequest {
21032137
export function createTranscriptionRequestSerializer(
21042138
item: CreateTranscriptionRequest,
21052139
): any {
2106-
return {
2107-
file: uint8ArrayToString(item["file"], "base64"),
2108-
model: item["model"],
2109-
prompt: item["prompt"],
2110-
response_format: item["response_format"],
2111-
temperature: item["temperature"],
2112-
language: item["language"],
2113-
};
2140+
return [
2141+
createFilePartDescriptor("file", item["file"], undefined),
2142+
{ name: "model", body: item["model"] },
2143+
...(item["prompt"] === undefined
2144+
? []
2145+
: [{ name: "prompt", body: item["prompt"] }]),
2146+
...(item["response_format"] === undefined
2147+
? []
2148+
: [{ name: "response_format", body: item["response_format"] }]),
2149+
...(item["temperature"] === undefined
2150+
? []
2151+
: [{ name: "temperature", body: item["temperature"] }]),
2152+
...(item["language"] === undefined
2153+
? []
2154+
: [{ name: "language", body: item["language"] }]),
2155+
];
21142156
}
21152157

21162158
/** model interface CreateTranscriptionResponse */
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
/**
5+
* Valid values for the contents of a binary file.
6+
*/
7+
export type FileContents =
8+
| string
9+
| NodeJS.ReadableStream
10+
| ReadableStream<Uint8Array>
11+
| Uint8Array
12+
| Blob;
13+
14+
export function createFilePartDescriptor(
15+
partName: string,
16+
fileInput: any,
17+
defaultContentType?: string,
18+
): any {
19+
if (fileInput.contents) {
20+
return {
21+
name: partName,
22+
body: fileInput.contents,
23+
contentType: fileInput.contentType ?? defaultContentType,
24+
filename: fileInput.filename,
25+
};
26+
} else {
27+
return {
28+
name: partName,
29+
body: fileInput,
30+
contentType: defaultContentType,
31+
};
32+
}
33+
}

0 commit comments

Comments
 (0)