|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +import { APIResource } from '../../resource'; |
| 4 | +import * as Core from '../../core'; |
| 5 | +import * as UploadsAPI from './uploads'; |
| 6 | +import * as FilesAPI from '../files'; |
| 7 | +import * as PartsAPI from './parts'; |
| 8 | + |
| 9 | +export class Uploads extends APIResource { |
| 10 | + parts: PartsAPI.Parts = new PartsAPI.Parts(this._client); |
| 11 | + |
| 12 | + /** |
| 13 | + * Creates an intermediate |
| 14 | + * [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object |
| 15 | + * that you can add |
| 16 | + * [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to. |
| 17 | + * Currently, an Upload can accept at most 8 GB in total and expires after an hour |
| 18 | + * after you create it. |
| 19 | + * |
| 20 | + * Once you complete the Upload, we will create a |
| 21 | + * [File](https://platform.openai.com/docs/api-reference/files/object) object that |
| 22 | + * contains all the parts you uploaded. This File is usable in the rest of our |
| 23 | + * platform as a regular File object. |
| 24 | + * |
| 25 | + * For certain `purpose`s, the correct `mime_type` must be specified. Please refer |
| 26 | + * to documentation for the supported MIME types for your use case: |
| 27 | + * |
| 28 | + * - [Assistants](https://platform.openai.com/docs/assistants/tools/file-search/supported-files) |
| 29 | + * |
| 30 | + * For guidance on the proper filename extensions for each purpose, please follow |
| 31 | + * the documentation on |
| 32 | + * [creating a File](https://platform.openai.com/docs/api-reference/files/create). |
| 33 | + */ |
| 34 | + create(body: UploadCreateParams, options?: Core.RequestOptions): Core.APIPromise<Upload> { |
| 35 | + return this._client.post('/uploads', { body, ...options }); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Cancels the Upload. No Parts may be added after an Upload is cancelled. |
| 40 | + */ |
| 41 | + cancel(uploadId: string, options?: Core.RequestOptions): Core.APIPromise<Upload> { |
| 42 | + return this._client.post(`/uploads/${uploadId}/cancel`, options); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Completes the |
| 47 | + * [Upload](https://platform.openai.com/docs/api-reference/uploads/object). |
| 48 | + * |
| 49 | + * Within the returned Upload object, there is a nested |
| 50 | + * [File](https://platform.openai.com/docs/api-reference/files/object) object that |
| 51 | + * is ready to use in the rest of the platform. |
| 52 | + * |
| 53 | + * You can specify the order of the Parts by passing in an ordered list of the Part |
| 54 | + * IDs. |
| 55 | + * |
| 56 | + * The number of bytes uploaded upon completion must match the number of bytes |
| 57 | + * initially specified when creating the Upload object. No Parts may be added after |
| 58 | + * an Upload is completed. |
| 59 | + */ |
| 60 | + complete( |
| 61 | + uploadId: string, |
| 62 | + body: UploadCompleteParams, |
| 63 | + options?: Core.RequestOptions, |
| 64 | + ): Core.APIPromise<Upload> { |
| 65 | + return this._client.post(`/uploads/${uploadId}/complete`, { body, ...options }); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +/** |
| 70 | + * The Upload object can accept byte chunks in the form of Parts. |
| 71 | + */ |
| 72 | +export interface Upload { |
| 73 | + /** |
| 74 | + * The Upload unique identifier, which can be referenced in API endpoints. |
| 75 | + */ |
| 76 | + id: string; |
| 77 | + |
| 78 | + /** |
| 79 | + * The intended number of bytes to be uploaded. |
| 80 | + */ |
| 81 | + bytes: number; |
| 82 | + |
| 83 | + /** |
| 84 | + * The Unix timestamp (in seconds) for when the Upload was created. |
| 85 | + */ |
| 86 | + created_at: number; |
| 87 | + |
| 88 | + /** |
| 89 | + * The Unix timestamp (in seconds) for when the Upload was created. |
| 90 | + */ |
| 91 | + expires_at: number; |
| 92 | + |
| 93 | + /** |
| 94 | + * The name of the file to be uploaded. |
| 95 | + */ |
| 96 | + filename: string; |
| 97 | + |
| 98 | + /** |
| 99 | + * The object type, which is always "upload". |
| 100 | + */ |
| 101 | + object: 'upload'; |
| 102 | + |
| 103 | + /** |
| 104 | + * The intended purpose of the file. |
| 105 | + * [Please refer here](https://platform.openai.com/docs/api-reference/files/object#files/object-purpose) |
| 106 | + * for acceptable values. |
| 107 | + */ |
| 108 | + purpose: string; |
| 109 | + |
| 110 | + /** |
| 111 | + * The status of the Upload. |
| 112 | + */ |
| 113 | + status: 'pending' | 'completed' | 'cancelled' | 'expired'; |
| 114 | + |
| 115 | + /** |
| 116 | + * The ready File object after the Upload is completed. |
| 117 | + */ |
| 118 | + file?: FilesAPI.FileObject | null; |
| 119 | +} |
| 120 | + |
| 121 | +export interface UploadCreateParams { |
| 122 | + /** |
| 123 | + * The number of bytes in the file you are uploading. |
| 124 | + */ |
| 125 | + bytes: number; |
| 126 | + |
| 127 | + /** |
| 128 | + * The name of the file to upload. |
| 129 | + */ |
| 130 | + filename: string; |
| 131 | + |
| 132 | + /** |
| 133 | + * The MIME type of the file. |
| 134 | + * |
| 135 | + * This must fall within the supported MIME types for your file purpose. See the |
| 136 | + * supported MIME types for assistants and vision. |
| 137 | + */ |
| 138 | + mime_type: string; |
| 139 | + |
| 140 | + /** |
| 141 | + * The intended purpose of the uploaded file. |
| 142 | + * |
| 143 | + * See the |
| 144 | + * [documentation on File purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose). |
| 145 | + */ |
| 146 | + purpose: 'assistants' | 'batch' | 'fine-tune' | 'vision'; |
| 147 | +} |
| 148 | + |
| 149 | +export interface UploadCompleteParams { |
| 150 | + /** |
| 151 | + * The ordered list of Part IDs. |
| 152 | + */ |
| 153 | + part_ids: Array<string>; |
| 154 | + |
| 155 | + /** |
| 156 | + * The optional md5 checksum for the file contents to verify if the bytes uploaded |
| 157 | + * matches what you expect. |
| 158 | + */ |
| 159 | + md5?: string; |
| 160 | +} |
| 161 | + |
| 162 | +export namespace Uploads { |
| 163 | + export import Upload = UploadsAPI.Upload; |
| 164 | + export import UploadCreateParams = UploadsAPI.UploadCreateParams; |
| 165 | + export import UploadCompleteParams = UploadsAPI.UploadCompleteParams; |
| 166 | + export import Parts = PartsAPI.Parts; |
| 167 | + export import UploadPart = PartsAPI.UploadPart; |
| 168 | + export import PartCreateParams = PartsAPI.PartCreateParams; |
| 169 | +} |
0 commit comments