commonMain.com.xebia.functional.openai.generated.api.Batch.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
/**
*
* 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.Batch
import com.xebia.functional.openai.generated.model.CreateBatchRequest
import com.xebia.functional.openai.generated.model.ListBatchesResponse
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.Batch.*
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 Batch {
/**
* Cancels an in-progress batch.
*
* @param batchId The ID of the batch to cancel.
* @param configure optional configuration for the request, allows overriding the default configuration.
* @return Batch
*/
suspend fun cancelBatch(batchId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): Batch
/**
* Creates and executes a batch from an uploaded file of requests
*
* @param createBatchRequest
* @param configure optional configuration for the request, allows overriding the default configuration.
* @return Batch
*/
suspend fun createBatch(createBatchRequest: CreateBatchRequest, configure: HttpRequestBuilder.() -> Unit = {}): Batch
/**
* List your organization's batches.
*
* @param after A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. (optional)
* @param limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. (optional, default to 20)
* @param configure optional configuration for the request, allows overriding the default configuration.
* @return ListBatchesResponse
*/
suspend fun listBatches(after: kotlin.String? = null, limit: kotlin.Int? = 20, configure: HttpRequestBuilder.() -> Unit = {}): ListBatchesResponse
/**
* Retrieves a batch.
*
* @param batchId The ID of the batch to retrieve.
* @param configure optional configuration for the request, allows overriding the default configuration.
* @return Batch
*/
suspend fun retrieveBatch(batchId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): Batch
}
fun Batch(client: HttpClient, config: Config): com.xebia.functional.openai.generated.api.Batch = object : com.xebia.functional.openai.generated.api.Batch {
override suspend fun cancelBatch(batchId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): Batch =
client.request {
configure()
method = HttpMethod.Post
contentType(ContentType.Application.Json)
url { path("batches/{batch_id}/cancel".replace("{" + "batch_id" + "}", "$batchId")) }
setBody(
io.ktor.client.utils.EmptyContent
)
}.serializeOrThrowWithResponseInfo()
override suspend fun createBatch(createBatchRequest: CreateBatchRequest, configure: HttpRequestBuilder.() -> Unit): Batch =
client.request {
configure()
method = HttpMethod.Post
contentType(ContentType.Application.Json)
url { path("batches") }
setBody(createBatchRequest
)
}.serializeOrThrowWithResponseInfo()
override suspend fun listBatches(after: kotlin.String?,limit: kotlin.Int?, configure: HttpRequestBuilder.() -> Unit): ListBatchesResponse =
client.request {
configure()
method = HttpMethod.Get
contentType(ContentType.Application.Json)
parameter("after", after)
parameter("limit", limit)
url { path("batches") }
setBody(
io.ktor.client.utils.EmptyContent
)
}.serializeOrThrowWithResponseInfo()
override suspend fun retrieveBatch(batchId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): Batch =
client.request {
configure()
method = HttpMethod.Get
contentType(ContentType.Application.Json)
url { path("batches/{batch_id}".replace("{" + "batch_id" + "}", "$batchId")) }
setBody(
io.ktor.client.utils.EmptyContent
)
}.serializeOrThrowWithResponseInfo()
}