-
Notifications
You must be signed in to change notification settings - Fork 16
/
FilesApi.kt
205 lines (168 loc) · 6.99 KB
/
FilesApi.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* Please note: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*/
@file:Suppress("ArrayInDataClass", "EnumEntryName", "RemoveRedundantQualifierName", "UnusedImport")
package com.xebia.functional.openai.apis
import com.xebia.functional.openai.infrastructure.*
import com.xebia.functional.openai.models.DeleteFileResponse
import com.xebia.functional.openai.models.ListFilesResponse
import com.xebia.functional.openai.models.OpenAIFile
import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.HttpClientEngine
import io.ktor.client.request.forms.formData
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.Json
open class FilesApi : ApiClient {
constructor(
baseUrl: String = ApiClient.BASE_URL,
httpClientEngine: HttpClientEngine? = null,
httpClientConfig: ((HttpClientConfig<*>) -> Unit)? = null,
jsonSerializer: Json = ApiClient.JSON_DEFAULT
) : super(
baseUrl = baseUrl,
httpClientEngine = httpClientEngine,
httpClientConfig = httpClientConfig,
jsonBlock = jsonSerializer
)
constructor(
baseUrl: String,
httpClient: HttpClient
) : super(baseUrl = baseUrl, httpClient = httpClient)
/** enum for parameter purpose */
@Serializable
enum class PurposeCreateFile(val value: kotlin.String) {
@SerialName(value = "fine-tune") fine_tune("fine-tune"),
@SerialName(value = "assistants") assistants("assistants")
}
/**
* Upload a file that can be used across various endpoints. The size of all the files uploaded by
* one organization can be up to 100 GB. The size of individual files can be a maximum of 512 MB
* or 2 million tokens for Assistants. See the [Assistants Tools guide](/docs/assistants/tools) to
* learn more about the types of files supported. The Fine-tuning API only supports
* `.jsonl` files. Please [contact us](https://help.openai.com/) if you need to increase
* these storage limits.
*
* @param file The File object (not file name) to be uploaded.
* @param purpose The intended purpose of the uploaded file. Use \\\"fine-tune\\\" for
* [Fine-tuning](/docs/api-reference/fine-tuning) and \\\"assistants\\\" for
* [Assistants](/docs/api-reference/assistants) and [Messages](/docs/api-reference/messages).
* This allows us to validate the format of the uploaded file is correct for fine-tuning.
* @return OpenAIFile
*/
@Suppress("UNCHECKED_CAST")
open suspend fun createFile(
file: com.xebia.functional.openai.apis.UploadFile,
purpose: PurposeCreateFile
): HttpResponse<OpenAIFile> {
val localVariableAuthNames = listOf<String>("ApiKeyAuth")
val localVariableBody = formData {
file?.apply { appendGen("file", file) }
purpose?.apply { appendGen("purpose", purpose) }
}
val localVariableQuery = mutableMapOf<String, List<String>>()
val localVariableHeaders = mutableMapOf<String, String>()
val localVariableConfig =
RequestConfig<kotlin.Any?>(
RequestMethod.POST,
"/files",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
return multipartFormRequest(localVariableConfig, localVariableBody, localVariableAuthNames)
.wrap()
}
/**
* Delete a file.
*
* @param fileId The ID of the file to use for this request.
* @return DeleteFileResponse
*/
@Suppress("UNCHECKED_CAST")
open suspend fun deleteFile(fileId: kotlin.String): HttpResponse<DeleteFileResponse> {
val localVariableAuthNames = listOf<String>("ApiKeyAuth")
val localVariableBody = io.ktor.client.utils.EmptyContent
val localVariableQuery = mutableMapOf<String, List<String>>()
val localVariableHeaders = mutableMapOf<String, String>()
val localVariableConfig =
RequestConfig<kotlin.Any?>(
RequestMethod.DELETE,
"/files/{file_id}".replace("{" + "file_id" + "}", "$fileId"),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
return request(localVariableConfig, localVariableBody, localVariableAuthNames).wrap()
}
/**
* Returns the contents of the specified file.
*
* @param fileId The ID of the file to use for this request.
* @return kotlin.String
*/
@Suppress("UNCHECKED_CAST")
open suspend fun downloadFile(fileId: kotlin.String): HttpResponse<kotlin.String> {
val localVariableAuthNames = listOf<String>("ApiKeyAuth")
val localVariableBody = io.ktor.client.utils.EmptyContent
val localVariableQuery = mutableMapOf<String, List<String>>()
val localVariableHeaders = mutableMapOf<String, String>()
val localVariableConfig =
RequestConfig<kotlin.Any?>(
RequestMethod.GET,
"/files/{file_id}/content".replace("{" + "file_id" + "}", "$fileId"),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
return request(localVariableConfig, localVariableBody, localVariableAuthNames).wrap()
}
/**
* Returns a list of files that belong to the user's organization.
*
* @param purpose Only return files with the given purpose. (optional)
* @return ListFilesResponse
*/
@Suppress("UNCHECKED_CAST")
open suspend fun listFiles(purpose: kotlin.String? = null): HttpResponse<ListFilesResponse> {
val localVariableAuthNames = listOf<String>("ApiKeyAuth")
val localVariableBody = io.ktor.client.utils.EmptyContent
val localVariableQuery = mutableMapOf<String, List<String>>()
purpose?.apply { localVariableQuery["purpose"] = listOf("$purpose") }
val localVariableHeaders = mutableMapOf<String, String>()
val localVariableConfig =
RequestConfig<kotlin.Any?>(
RequestMethod.GET,
"/files",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
return request(localVariableConfig, localVariableBody, localVariableAuthNames).wrap()
}
/**
* Returns information about a specific file.
*
* @param fileId The ID of the file to use for this request.
* @return OpenAIFile
*/
@Suppress("UNCHECKED_CAST")
open suspend fun retrieveFile(fileId: kotlin.String): HttpResponse<OpenAIFile> {
val localVariableAuthNames = listOf<String>("ApiKeyAuth")
val localVariableBody = io.ktor.client.utils.EmptyContent
val localVariableQuery = mutableMapOf<String, List<String>>()
val localVariableHeaders = mutableMapOf<String, String>()
val localVariableConfig =
RequestConfig<kotlin.Any?>(
RequestMethod.GET,
"/files/{file_id}".replace("{" + "file_id" + "}", "$fileId"),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
return request(localVariableConfig, localVariableBody, localVariableAuthNames).wrap()
}
}