@@ -10,7 +10,7 @@ import com.openai.core.checkRequired
1010import com.openai.core.http.Headers
1111import com.openai.core.http.QueryParams
1212import com.openai.core.toImmutable
13- import java.io.ByteArrayInputStream
13+ import com.openai.errors.OpenAIInvalidDataException
1414import java.io.InputStream
1515import java.nio.file.Path
1616import java.util.Objects
@@ -41,25 +41,36 @@ private constructor(
4141 private val additionalQueryParams: QueryParams ,
4242) : Params {
4343
44- /* * The File object (not file name) to be uploaded. */
44+ /* *
45+ * The File object (not file name) to be uploaded.
46+ *
47+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
48+ * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
49+ */
4550 fun file (): InputStream = body.file()
4651
4752 /* *
4853 * The intended purpose of the uploaded file. One of: - `assistants`: Used in the Assistants
4954 * API - `batch`: Used in the Batch API - `fine-tune`: Used for fine-tuning - `vision`: Images
5055 * used for vision fine-tuning - `user_data`: Flexible file type for any purpose - `evals`: Used
5156 * for eval data sets
57+ *
58+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
59+ * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
5260 */
5361 fun purpose (): FilePurpose = body.purpose()
5462
55- /* * The File object (not file name) to be uploaded. */
63+ /* *
64+ * Returns the raw multipart value of [file].
65+ *
66+ * Unlike [file], this method doesn't throw if the multipart field has an unexpected type.
67+ */
5668 fun _file (): MultipartField <InputStream > = body._file ()
5769
5870 /* *
59- * The intended purpose of the uploaded file. One of: - `assistants`: Used in the Assistants
60- * API - `batch`: Used in the Batch API - `fine-tune`: Used for fine-tuning - `vision`: Images
61- * used for vision fine-tuning - `user_data`: Flexible file type for any purpose - `evals`: Used
62- * for eval data sets
71+ * Returns the raw multipart value of [purpose].
72+ *
73+ * Unlike [purpose], this method doesn't throw if the multipart field has an unexpected type.
6374 */
6475 fun _purpose (): MultipartField <FilePurpose > = body._purpose ()
6576
@@ -83,25 +94,37 @@ private constructor(
8394 private val purpose: MultipartField <FilePurpose >,
8495 ) {
8596
86- /* * The File object (not file name) to be uploaded. */
97+ /* *
98+ * The File object (not file name) to be uploaded.
99+ *
100+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
101+ * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
102+ */
87103 fun file (): InputStream = file.value.getRequired(" file" )
88104
89105 /* *
90106 * The intended purpose of the uploaded file. One of: - `assistants`: Used in the Assistants
91107 * API - `batch`: Used in the Batch API - `fine-tune`: Used for fine-tuning - `vision`:
92108 * Images used for vision fine-tuning - `user_data`: Flexible file type for any purpose -
93109 * `evals`: Used for eval data sets
110+ *
111+ * @throws OpenAIInvalidDataException if the JSON field has an unexpected type or is
112+ * unexpectedly missing or null (e.g. if the server responded with an unexpected value).
94113 */
95114 fun purpose (): FilePurpose = purpose.value.getRequired(" purpose" )
96115
97- /* * The File object (not file name) to be uploaded. */
116+ /* *
117+ * Returns the raw multipart value of [file].
118+ *
119+ * Unlike [file], this method doesn't throw if the multipart field has an unexpected type.
120+ */
98121 fun _file (): MultipartField <InputStream > = file
99122
100123 /* *
101- * The intended purpose of the uploaded file. One of: - `assistants`: Used in the Assistants
102- * API - `batch`: Used in the Batch API - `fine-tune`: Used for fine-tuning - `vision`:
103- * Images used for vision fine-tuning - `user_data`: Flexible file type for any purpose -
104- * `evals`: Used for eval data sets
124+ * Returns the raw multipart value of [purpose].
125+ *
126+ * Unlike [purpose], this method doesn't throw if the multipart field has an unexpected
127+ * type.
105128 */
106129 fun _purpose (): MultipartField <FilePurpose > = purpose
107130
@@ -148,11 +171,17 @@ private constructor(
148171 /* * The File object (not file name) to be uploaded. */
149172 fun file (file : InputStream ) = file(MultipartField .of(file))
150173
151- /* * The File object (not file name) to be uploaded. */
174+ /* *
175+ * Sets [Builder.file] to an arbitrary multipart value.
176+ *
177+ * You should usually call [Builder.file] with a well-typed [InputStream] value instead.
178+ * This method is primarily for setting the field to an undocumented or not yet
179+ * supported value.
180+ */
152181 fun file (file : MultipartField <InputStream >) = apply { this .file = file }
153182
154183 /* * The File object (not file name) to be uploaded. */
155- fun file (file : ByteArray ) = file(ByteArrayInputStream ( file))
184+ fun file (file : ByteArray ) = file(file.inputStream( ))
156185
157186 /* * The File object (not file name) to be uploaded. */
158187 fun file (file : Path ) =
@@ -172,10 +201,11 @@ private constructor(
172201 fun purpose (purpose : FilePurpose ) = purpose(MultipartField .of(purpose))
173202
174203 /* *
175- * The intended purpose of the uploaded file. One of: - `assistants`: Used in the
176- * Assistants API - `batch`: Used in the Batch API - `fine-tune`: Used for fine-tuning -
177- * `vision`: Images used for vision fine-tuning - `user_data`: Flexible file type for
178- * any purpose - `evals`: Used for eval data sets
204+ * Sets [Builder.purpose] to an arbitrary multipart value.
205+ *
206+ * You should usually call [Builder.purpose] with a well-typed [FilePurpose] value
207+ * instead. This method is primarily for setting the field to an undocumented or not yet
208+ * supported value.
179209 */
180210 fun purpose (purpose : MultipartField <FilePurpose >) = apply { this .purpose = purpose }
181211
@@ -246,7 +276,13 @@ private constructor(
246276 /* * The File object (not file name) to be uploaded. */
247277 fun file (file : InputStream ) = apply { body.file(file) }
248278
249- /* * The File object (not file name) to be uploaded. */
279+ /* *
280+ * Sets [Builder.file] to an arbitrary multipart value.
281+ *
282+ * You should usually call [Builder.file] with a well-typed [InputStream] value instead.
283+ * This method is primarily for setting the field to an undocumented or not yet supported
284+ * value.
285+ */
250286 fun file (file : MultipartField <InputStream >) = apply { body.file(file) }
251287
252288 /* * The File object (not file name) to be uploaded. */
@@ -264,10 +300,11 @@ private constructor(
264300 fun purpose (purpose : FilePurpose ) = apply { body.purpose(purpose) }
265301
266302 /* *
267- * The intended purpose of the uploaded file. One of: - `assistants`: Used in the Assistants
268- * API - `batch`: Used in the Batch API - `fine-tune`: Used for fine-tuning - `vision`:
269- * Images used for vision fine-tuning - `user_data`: Flexible file type for any purpose -
270- * `evals`: Used for eval data sets
303+ * Sets [Builder.purpose] to an arbitrary multipart value.
304+ *
305+ * You should usually call [Builder.purpose] with a well-typed [FilePurpose] value instead.
306+ * This method is primarily for setting the field to an undocumented or not yet supported
307+ * value.
271308 */
272309 fun purpose (purpose : MultipartField <FilePurpose >) = apply { body.purpose(purpose) }
273310
0 commit comments