All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.xebia.functional.openai.generated.api.Uploads.kt Maven / Gradle / Ivy

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.CompleteUploadRequest
import com.xebia.functional.openai.generated.model.CreateUploadRequest
import com.xebia.functional.openai.generated.model.Upload
import com.xebia.functional.openai.generated.model.UploadPart
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.Uploads.*
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 Uploads {

    /**
    * Adds a [Part](/docs/api-reference/uploads/part-object) to an [Upload](/docs/api-reference/uploads/object) object. A Part represents a chunk of bytes from the file you are trying to upload.   Each Part can be at most 64 MB, and you can add Parts until you hit the Upload maximum of 8 GB.  It is possible to add multiple Parts in parallel. You can decide the intended order of the Parts when you [complete the Upload](/docs/api-reference/uploads/complete). 
    * 
     * @param uploadId The ID of the Upload. 
     * @param `data` The chunk of bytes for this Part. 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return UploadPart
    */
    suspend fun addUploadPart(uploadId: kotlin.String, `data`: UploadFile, configure: HttpRequestBuilder.() -> Unit = {}): UploadPart


    /**
    * Cancels the Upload. No Parts may be added after an Upload is cancelled. 
    * 
     * @param uploadId The ID of the Upload. 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return Upload
    */
    suspend fun cancelUpload(uploadId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): Upload


    /**
    * Completes the [Upload](/docs/api-reference/uploads/object).   Within the returned Upload object, there is a nested [File](/docs/api-reference/files/object) object that is ready to use in the rest of the platform.  You can specify the order of the Parts by passing in an ordered list of the Part IDs.  The number of bytes uploaded upon completion must match the number of bytes initially specified when creating the Upload object. No Parts may be added after an Upload is completed. 
    * 
     * @param uploadId The ID of the Upload. 
     * @param completeUploadRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return Upload
    */
    suspend fun completeUpload(uploadId: kotlin.String, completeUploadRequest: CompleteUploadRequest, configure: HttpRequestBuilder.() -> Unit = {}): Upload


    /**
    * Creates an intermediate [Upload](/docs/api-reference/uploads/object) object that you can add [Parts](/docs/api-reference/uploads/part-object) to. Currently, an Upload can accept at most 8 GB in total and expires after an hour after you create it.  Once you complete the Upload, we will create a [File](/docs/api-reference/files/object) object that contains all the parts you uploaded. This File is usable in the rest of our platform as a regular File object.  For certain `purpose`s, the correct `mime_type` must be specified. Please refer to documentation for the supported MIME types for your use case: - [Assistants](/docs/assistants/tools/file-search/supported-files)  For guidance on the proper filename extensions for each purpose, please follow the documentation on [creating a File](/docs/api-reference/files/create). 
    * 
     * @param createUploadRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return Upload
    */
    suspend fun createUpload(createUploadRequest: CreateUploadRequest, configure: HttpRequestBuilder.() -> Unit = {}): Upload

}

fun Uploads(client: HttpClient, config: Config): com.xebia.functional.openai.generated.api.Uploads = object : com.xebia.functional.openai.generated.api.Uploads {
    override suspend fun addUploadPart(uploadId: kotlin.String,`data`: UploadFile, configure: HttpRequestBuilder.() -> Unit): UploadPart =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("uploads/{upload_id}/parts".replace("{" + "upload_id" + "}", "$uploadId")) }
        setBody(
                    formData {
                            `data`?.apply { appendGen("data", `data`) }
                    }
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun cancelUpload(uploadId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): Upload =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("uploads/{upload_id}/cancel".replace("{" + "upload_id" + "}", "$uploadId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun completeUpload(uploadId: kotlin.String,completeUploadRequest: CompleteUploadRequest, configure: HttpRequestBuilder.() -> Unit): Upload =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("uploads/{upload_id}/complete".replace("{" + "upload_id" + "}", "$uploadId")) }
        setBody(completeUploadRequest
)
      }.serializeOrThrowWithResponseInfo()

    override suspend fun createUpload(createUploadRequest: CreateUploadRequest, configure: HttpRequestBuilder.() -> Unit): Upload =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("uploads") }
        setBody(createUploadRequest
)
      }.serializeOrThrowWithResponseInfo()

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy