commonMain.com.xebia.functional.openai.generated.api.Files.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xef-openai-client Show documentation
Show all versions of xef-openai-client Show documentation
Building applications with LLMs through composability in Kotlin
The newest version!
/**
*
* 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.generated.api
import com.xebia.functional.openai.generated.model.DeleteFileResponse
import com.xebia.functional.openai.generated.model.ListFilesResponse
import com.xebia.functional.openai.generated.model.OpenAIFile
import com.xebia.functional.openai.Config
import com.xebia.functional.openai.UploadFile
import com.xebia.functional.openai.appendGen
import com.xebia.functional.openai.generated.api.Files.*
import com.xebia.functional.openai.streamEvents
import com.xebia.functional.openai.errors.serializeOrThrowWithResponseInfo
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.timeout
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.accept
import io.ktor.client.request.header
import io.ktor.client.request.forms.formData
import io.ktor.client.request.parameter
import io.ktor.client.request.prepareRequest
import io.ktor.client.request.request
import io.ktor.client.request.setBody
import io.ktor.client.statement.HttpResponse
import io.ktor.client.statement.HttpStatement
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpMethod
import io.ktor.http.contentType
import io.ktor.http.path
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.JsonPrimitive
import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
/**
*
*/
interface Files {
/**
* enum for parameter purpose
*/
@Serializable
enum class PurposeCreateFile(val value: kotlin.String) {
@SerialName(value = "assistants")
assistants("assistants"),
@SerialName(value = "batch")
batch("batch"),
@SerialName(value = "fine-tune")
fine_tune("fine-tune"),
@SerialName(value = "vision")
vision("vision")
}
/**
* Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB. The Assistants API supports files up to 2 million tokens and of specific file types. See the [Assistants Tools guide](/docs/assistants/tools) for details. The Fine-tuning API only supports `.jsonl` files. The input also has certain required formats for fine-tuning [chat](/docs/api-reference/fine-tuning/chat-input) or [completions](/docs/api-reference/fine-tuning/completions-input) models. The Batch API only supports `.jsonl` files up to 100 MB in size. The input also has a specific required [format](/docs/api-reference/batch/request-input). 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 \\\"assistants\\\" for [Assistants](/docs/api-reference/assistants) and [Message](/docs/api-reference/messages) files, \\\"vision\\\" for Assistants image file inputs, \\\"batch\\\" for [Batch API](/docs/guides/batch), and \\\"fine-tune\\\" for [Fine-tuning](/docs/api-reference/fine-tuning).
* @param configure optional configuration for the request, allows overriding the default configuration.
* @return OpenAIFile
*/
suspend fun createFile(file: UploadFile, purpose: PurposeCreateFile, configure: HttpRequestBuilder.() -> Unit = {}): OpenAIFile
/**
* Delete a file.
*
* @param fileId The ID of the file to use for this request.
* @param configure optional configuration for the request, allows overriding the default configuration.
* @return DeleteFileResponse
*/
suspend fun deleteFile(fileId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): DeleteFileResponse
/**
* Returns the contents of the specified file.
*
* @param fileId The ID of the file to use for this request.
* @param configure optional configuration for the request, allows overriding the default configuration.
* @return kotlin.String
*/
suspend fun downloadFile(fileId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): kotlin.String
/**
* Returns a list of files that belong to the user's organization.
*
* @param purpose Only return files with the given purpose. (optional)
* @param configure optional configuration for the request, allows overriding the default configuration.
* @return ListFilesResponse
*/
suspend fun listFiles(purpose: kotlin.String? = null, configure: HttpRequestBuilder.() -> Unit = {}): ListFilesResponse
/**
* Returns information about a specific file.
*
* @param fileId The ID of the file to use for this request.
* @param configure optional configuration for the request, allows overriding the default configuration.
* @return OpenAIFile
*/
suspend fun retrieveFile(fileId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): OpenAIFile
}
fun Files(client: HttpClient, config: Config): com.xebia.functional.openai.generated.api.Files = object : com.xebia.functional.openai.generated.api.Files {
override suspend fun createFile(file: UploadFile,purpose: PurposeCreateFile, configure: HttpRequestBuilder.() -> Unit): OpenAIFile =
client.request {
configure()
method = HttpMethod.Post
contentType(ContentType.Application.Json)
url { path("files") }
setBody(
formData {
file?.apply { appendGen("file", file) }
purpose?.apply { appendGen("purpose", purpose) }
}
)
}.serializeOrThrowWithResponseInfo()
override suspend fun deleteFile(fileId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): DeleteFileResponse =
client.request {
configure()
method = HttpMethod.Delete
contentType(ContentType.Application.Json)
url { path("files/{file_id}".replace("{" + "file_id" + "}", "$fileId")) }
setBody(
io.ktor.client.utils.EmptyContent
)
}.serializeOrThrowWithResponseInfo()
override suspend fun downloadFile(fileId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): kotlin.String =
client.request {
configure()
method = HttpMethod.Get
contentType(ContentType.Application.Json)
url { path("files/{file_id}/content".replace("{" + "file_id" + "}", "$fileId")) }
setBody(
io.ktor.client.utils.EmptyContent
)
}.serializeOrThrowWithResponseInfo()
override suspend fun listFiles(purpose: kotlin.String?, configure: HttpRequestBuilder.() -> Unit): ListFilesResponse =
client.request {
configure()
method = HttpMethod.Get
contentType(ContentType.Application.Json)
parameter("purpose", purpose)
url { path("files") }
setBody(
io.ktor.client.utils.EmptyContent
)
}.serializeOrThrowWithResponseInfo()
override suspend fun retrieveFile(fileId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): OpenAIFile =
client.request {
configure()
method = HttpMethod.Get
contentType(ContentType.Application.Json)
url { path("files/{file_id}".replace("{" + "file_id" + "}", "$fileId")) }
setBody(
io.ktor.client.utils.EmptyContent
)
}.serializeOrThrowWithResponseInfo()
}