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

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

There is a newer version: 0.0.5-alpha.118
Show 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.AssistantObject
import com.xebia.functional.openai.generated.model.CreateAssistantRequest
import com.xebia.functional.openai.generated.model.CreateMessageRequest
import com.xebia.functional.openai.generated.model.CreateRunRequest
import com.xebia.functional.openai.generated.model.CreateThreadAndRunRequest
import com.xebia.functional.openai.generated.model.CreateThreadRequest
import com.xebia.functional.openai.generated.model.DeleteAssistantResponse
import com.xebia.functional.openai.generated.model.DeleteMessageResponse
import com.xebia.functional.openai.generated.model.DeleteThreadResponse
import com.xebia.functional.openai.generated.model.ListAssistantsResponse
import com.xebia.functional.openai.generated.model.ListMessagesResponse
import com.xebia.functional.openai.generated.model.ListRunStepsResponse
import com.xebia.functional.openai.generated.model.ListRunsResponse
import com.xebia.functional.openai.generated.model.MessageObject
import com.xebia.functional.openai.generated.model.ModifyAssistantRequest
import com.xebia.functional.openai.generated.model.ModifyMessageRequest
import com.xebia.functional.openai.generated.model.ModifyRunRequest
import com.xebia.functional.openai.generated.model.ModifyThreadRequest
import com.xebia.functional.openai.generated.model.RunObject
import com.xebia.functional.openai.generated.model.RunStepObject
import com.xebia.functional.openai.generated.model.SubmitToolOutputsRunRequest
import com.xebia.functional.openai.generated.model.ThreadObject
import com.xebia.functional.openai.ServerSentEvent
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.Assistants.*
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 Assistants {

    /**
    * Cancels a run that is `in_progress`.
    * 
     * @param threadId The ID of the thread to which this run belongs.
     * @param runId The ID of the run to cancel.
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return RunObject
    */
    suspend fun cancelRun(threadId: kotlin.String, runId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): RunObject


    /**
    * Create an assistant with a model and instructions.
    * 
     * @param createAssistantRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return AssistantObject
    */
    suspend fun createAssistant(createAssistantRequest: CreateAssistantRequest, configure: HttpRequestBuilder.() -> Unit = {}): AssistantObject


    /**
    * Create a message.
    * 
     * @param threadId The ID of the [thread](/docs/api-reference/threads) to create a message for.
     * @param createMessageRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return MessageObject
    */
    suspend fun createMessage(threadId: kotlin.String, createMessageRequest: CreateMessageRequest, configure: HttpRequestBuilder.() -> Unit = {}): MessageObject


    /**
    * Create a run.
    * 
     * @param threadId The ID of the thread to run.
     * @param createRunRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return RunObject
    */
    suspend fun createRun(threadId: kotlin.String, createRunRequest: CreateRunRequest, configure: HttpRequestBuilder.() -> Unit = {}): RunObject

    /**
    * Streaming variant: Create a run.
    * By default, the client is modified to timeout after 60 seconds. Which is overridable by the [configure].
    * 
     * @param threadId The ID of the thread to run.
     * @param createRunRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return [Flow]<[ServerSentEvent]>
    */
    fun createRunStream(threadId: kotlin.String, createRunRequest: CreateRunRequest, configure: HttpRequestBuilder.() -> Unit = {}): Flow

    /**
    * Create a thread.
    * 
     * @param createThreadRequest  (optional)
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return ThreadObject
    */
    suspend fun createThread(createThreadRequest: CreateThreadRequest? = null, configure: HttpRequestBuilder.() -> Unit = {}): ThreadObject


    /**
    * Create a thread and run it in one request.
    * 
     * @param createThreadAndRunRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return RunObject
    */
    suspend fun createThreadAndRun(createThreadAndRunRequest: CreateThreadAndRunRequest, configure: HttpRequestBuilder.() -> Unit = {}): RunObject

    /**
    * Streaming variant: Create a thread and run it in one request.
    * By default, the client is modified to timeout after 60 seconds. Which is overridable by the [configure].
    * 
     * @param createThreadAndRunRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return [Flow]<[ServerSentEvent]>
    */
    fun createThreadAndRunStream(createThreadAndRunRequest: CreateThreadAndRunRequest, configure: HttpRequestBuilder.() -> Unit = {}): Flow

    /**
    * Delete an assistant.
    * 
     * @param assistantId The ID of the assistant to delete.
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return DeleteAssistantResponse
    */
    suspend fun deleteAssistant(assistantId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): DeleteAssistantResponse


    /**
    * Deletes a message.
    * 
     * @param threadId The ID of the thread to which this message belongs.
     * @param messageId The ID of the message to delete.
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return DeleteMessageResponse
    */
    suspend fun deleteMessage(threadId: kotlin.String, messageId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): DeleteMessageResponse


    /**
    * Delete a thread.
    * 
     * @param threadId The ID of the thread to delete.
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return DeleteThreadResponse
    */
    suspend fun deleteThread(threadId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): DeleteThreadResponse


    /**
    * Retrieves an assistant.
    * 
     * @param assistantId The ID of the assistant to retrieve.
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return AssistantObject
    */
    suspend fun getAssistant(assistantId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): AssistantObject


    /**
    * Retrieve a message.
    * 
     * @param threadId The ID of the [thread](/docs/api-reference/threads) to which this message belongs.
     * @param messageId The ID of the message to retrieve.
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return MessageObject
    */
    suspend fun getMessage(threadId: kotlin.String, messageId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): MessageObject


    /**
    * Retrieves a run.
    * 
     * @param threadId The ID of the [thread](/docs/api-reference/threads) that was run.
     * @param runId The ID of the run to retrieve.
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return RunObject
    */
    suspend fun getRun(threadId: kotlin.String, runId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): RunObject


    /**
    * Retrieves a run step.
    * 
     * @param threadId The ID of the thread to which the run and run step belongs.
     * @param runId The ID of the run to which the run step belongs.
     * @param stepId The ID of the run step to retrieve.
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return RunStepObject
    */
    suspend fun getRunStep(threadId: kotlin.String, runId: kotlin.String, stepId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): RunStepObject


    /**
    * Retrieves a thread.
    * 
     * @param threadId The ID of the thread to retrieve.
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return ThreadObject
    */
    suspend fun getThread(threadId: kotlin.String, configure: HttpRequestBuilder.() -> Unit = {}): ThreadObject


                /**
                * enum for parameter order
                */
                @Serializable
                enum class OrderListAssistants(val value: kotlin.String) {
                    
                        @SerialName(value = "asc")
                        asc("asc"),
                    
                        @SerialName(value = "desc")
                        desc("desc")
                    
                }


    /**
    * Returns a list of assistants.
    * 
     * @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 order Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order.  (optional, default to desc)
     * @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 before A cursor for use in pagination. `before` 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 before=obj_foo in order to fetch the previous page of the list.  (optional)
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return ListAssistantsResponse
    */
    suspend fun listAssistants(limit: kotlin.Int? = 20, order: OrderListAssistants? = OrderListAssistants.desc, after: kotlin.String? = null, before: kotlin.String? = null, configure: HttpRequestBuilder.() -> Unit = {}): ListAssistantsResponse


                /**
                * enum for parameter order
                */
                @Serializable
                enum class OrderListMessages(val value: kotlin.String) {
                    
                        @SerialName(value = "asc")
                        asc("asc"),
                    
                        @SerialName(value = "desc")
                        desc("desc")
                    
                }


    /**
    * Returns a list of messages for a given thread.
    * 
     * @param threadId The ID of the [thread](/docs/api-reference/threads) the messages belong to.
     * @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 order Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order.  (optional, default to desc)
     * @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 before A cursor for use in pagination. `before` 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 before=obj_foo in order to fetch the previous page of the list.  (optional)
     * @param runId Filter messages by the run ID that generated them.  (optional)
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return ListMessagesResponse
    */
    suspend fun listMessages(threadId: kotlin.String, limit: kotlin.Int? = 20, order: OrderListMessages? = OrderListMessages.desc, after: kotlin.String? = null, before: kotlin.String? = null, runId: kotlin.String? = null, configure: HttpRequestBuilder.() -> Unit = {}): ListMessagesResponse


                /**
                * enum for parameter order
                */
                @Serializable
                enum class OrderListRunSteps(val value: kotlin.String) {
                    
                        @SerialName(value = "asc")
                        asc("asc"),
                    
                        @SerialName(value = "desc")
                        desc("desc")
                    
                }


    /**
    * Returns a list of run steps belonging to a run.
    * 
     * @param threadId The ID of the thread the run and run steps belong to.
     * @param runId The ID of the run the run steps belong to.
     * @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 order Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order.  (optional, default to desc)
     * @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 before A cursor for use in pagination. `before` 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 before=obj_foo in order to fetch the previous page of the list.  (optional)
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return ListRunStepsResponse
    */
    suspend fun listRunSteps(threadId: kotlin.String, runId: kotlin.String, limit: kotlin.Int? = 20, order: OrderListRunSteps? = OrderListRunSteps.desc, after: kotlin.String? = null, before: kotlin.String? = null, configure: HttpRequestBuilder.() -> Unit = {}): ListRunStepsResponse


                /**
                * enum for parameter order
                */
                @Serializable
                enum class OrderListRuns(val value: kotlin.String) {
                    
                        @SerialName(value = "asc")
                        asc("asc"),
                    
                        @SerialName(value = "desc")
                        desc("desc")
                    
                }


    /**
    * Returns a list of runs belonging to a thread.
    * 
     * @param threadId The ID of the thread the run belongs to.
     * @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 order Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order.  (optional, default to desc)
     * @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 before A cursor for use in pagination. `before` 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 before=obj_foo in order to fetch the previous page of the list.  (optional)
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return ListRunsResponse
    */
    suspend fun listRuns(threadId: kotlin.String, limit: kotlin.Int? = 20, order: OrderListRuns? = OrderListRuns.desc, after: kotlin.String? = null, before: kotlin.String? = null, configure: HttpRequestBuilder.() -> Unit = {}): ListRunsResponse


    /**
    * Modifies an assistant.
    * 
     * @param assistantId The ID of the assistant to modify.
     * @param modifyAssistantRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return AssistantObject
    */
    suspend fun modifyAssistant(assistantId: kotlin.String, modifyAssistantRequest: ModifyAssistantRequest, configure: HttpRequestBuilder.() -> Unit = {}): AssistantObject


    /**
    * Modifies a message.
    * 
     * @param threadId The ID of the thread to which this message belongs.
     * @param messageId The ID of the message to modify.
     * @param modifyMessageRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return MessageObject
    */
    suspend fun modifyMessage(threadId: kotlin.String, messageId: kotlin.String, modifyMessageRequest: ModifyMessageRequest, configure: HttpRequestBuilder.() -> Unit = {}): MessageObject


    /**
    * Modifies a run.
    * 
     * @param threadId The ID of the [thread](/docs/api-reference/threads) that was run.
     * @param runId The ID of the run to modify.
     * @param modifyRunRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return RunObject
    */
    suspend fun modifyRun(threadId: kotlin.String, runId: kotlin.String, modifyRunRequest: ModifyRunRequest, configure: HttpRequestBuilder.() -> Unit = {}): RunObject


    /**
    * Modifies a thread.
    * 
     * @param threadId The ID of the thread to modify. Only the `metadata` can be modified.
     * @param modifyThreadRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return ThreadObject
    */
    suspend fun modifyThread(threadId: kotlin.String, modifyThreadRequest: ModifyThreadRequest, configure: HttpRequestBuilder.() -> Unit = {}): ThreadObject


    /**
    * When a run has the `status: \"requires_action\"` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request. 
    * 
     * @param threadId The ID of the [thread](/docs/api-reference/threads) to which this run belongs.
     * @param runId The ID of the run that requires the tool output submission.
     * @param submitToolOutputsRunRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return RunObject
    */
    suspend fun submitToolOuputsToRun(threadId: kotlin.String, runId: kotlin.String, submitToolOutputsRunRequest: SubmitToolOutputsRunRequest, configure: HttpRequestBuilder.() -> Unit = {}): RunObject

    /**
    * Streaming variant: When a run has the `status: \"requires_action\"` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request. 
    * By default, the client is modified to timeout after 60 seconds. Which is overridable by the [configure].
    * 
     * @param threadId The ID of the [thread](/docs/api-reference/threads) to which this run belongs.
     * @param runId The ID of the run that requires the tool output submission.
     * @param submitToolOutputsRunRequest 
     * @param configure optional configuration for the request, allows overriding the default configuration.
    * @return [Flow]<[ServerSentEvent]>
    */
    fun submitToolOuputsToRunStream(threadId: kotlin.String, runId: kotlin.String, submitToolOutputsRunRequest: SubmitToolOutputsRunRequest, configure: HttpRequestBuilder.() -> Unit = {}): Flow
}

fun Assistants(client: HttpClient, config: Config): com.xebia.functional.openai.generated.api.Assistants = object : com.xebia.functional.openai.generated.api.Assistants {
    override suspend fun cancelRun(threadId: kotlin.String,runId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): RunObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/runs/{run_id}/cancel".replace("{" + "thread_id" + "}", "$threadId").replace("{" + "run_id" + "}", "$runId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun createAssistant(createAssistantRequest: CreateAssistantRequest, configure: HttpRequestBuilder.() -> Unit): AssistantObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("assistants") }
        setBody(createAssistantRequest
)
      }.serializeOrThrowWithResponseInfo()

    override suspend fun createMessage(threadId: kotlin.String,createMessageRequest: CreateMessageRequest, configure: HttpRequestBuilder.() -> Unit): MessageObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/messages".replace("{" + "thread_id" + "}", "$threadId")) }
        setBody(createMessageRequest
)
      }.serializeOrThrowWithResponseInfo()

    override suspend fun createRun(threadId: kotlin.String,createRunRequest: CreateRunRequest, configure: HttpRequestBuilder.() -> Unit): RunObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/runs".replace("{" + "thread_id" + "}", "$threadId")) }
        setBody(createRunRequest
)
      }.serializeOrThrowWithResponseInfo()

    override fun createRunStream(threadId: kotlin.String, createRunRequest: CreateRunRequest, configure: HttpRequestBuilder.() -> Unit): Flow = flow {
      client.prepareRequest {
        timeout {
          requestTimeoutMillis = 60.seconds.toLong(DurationUnit.MILLISECONDS)
          socketTimeoutMillis = 60.seconds.toLong(DurationUnit.MILLISECONDS)
        }
        configure()
        method = HttpMethod.Post
        accept(ContentType.Text.EventStream)
        header(HttpHeaders.CacheControl, "no-cache")
        header(HttpHeaders.Connection, "keep-alive")
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/runs".replace("{" + "thread_id" + "}", "$threadId")) }
        val element = Json.encodeToJsonElement(CreateRunRequest.serializer(), createRunRequest)
        val jsObject = JsonObject(element.jsonObject + Pair("stream", JsonPrimitive(true)))
        setBody(jsObject)
      }.execute { streamEvents(it, config.json, config.streamingPrefix, config.streamingDelimiter) }
    }
    override suspend fun createThread(createThreadRequest: CreateThreadRequest?, configure: HttpRequestBuilder.() -> Unit): ThreadObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("threads") }
        setBody(createThreadRequest
)
      }.serializeOrThrowWithResponseInfo()

    override suspend fun createThreadAndRun(createThreadAndRunRequest: CreateThreadAndRunRequest, configure: HttpRequestBuilder.() -> Unit): RunObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("threads/runs") }
        setBody(createThreadAndRunRequest
)
      }.serializeOrThrowWithResponseInfo()

    override fun createThreadAndRunStream(createThreadAndRunRequest: CreateThreadAndRunRequest, configure: HttpRequestBuilder.() -> Unit): Flow = flow {
      client.prepareRequest {
        timeout {
          requestTimeoutMillis = 60.seconds.toLong(DurationUnit.MILLISECONDS)
          socketTimeoutMillis = 60.seconds.toLong(DurationUnit.MILLISECONDS)
        }
        configure()
        method = HttpMethod.Post
        accept(ContentType.Text.EventStream)
        header(HttpHeaders.CacheControl, "no-cache")
        header(HttpHeaders.Connection, "keep-alive")
        contentType(ContentType.Application.Json)
        url { path("threads/runs") }
        val element = Json.encodeToJsonElement(CreateThreadAndRunRequest.serializer(), createThreadAndRunRequest)
        val jsObject = JsonObject(element.jsonObject + Pair("stream", JsonPrimitive(true)))
        setBody(jsObject)
      }.execute { streamEvents(it, config.json, config.streamingPrefix, config.streamingDelimiter) }
    }
    override suspend fun deleteAssistant(assistantId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): DeleteAssistantResponse =
      client.request {
        configure()
        method = HttpMethod.Delete
        contentType(ContentType.Application.Json)
        url { path("assistants/{assistant_id}".replace("{" + "assistant_id" + "}", "$assistantId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun deleteMessage(threadId: kotlin.String,messageId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): DeleteMessageResponse =
      client.request {
        configure()
        method = HttpMethod.Delete
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/messages/{message_id}".replace("{" + "thread_id" + "}", "$threadId").replace("{" + "message_id" + "}", "$messageId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun deleteThread(threadId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): DeleteThreadResponse =
      client.request {
        configure()
        method = HttpMethod.Delete
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}".replace("{" + "thread_id" + "}", "$threadId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun getAssistant(assistantId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): AssistantObject =
      client.request {
        configure()
        method = HttpMethod.Get
        contentType(ContentType.Application.Json)
        url { path("assistants/{assistant_id}".replace("{" + "assistant_id" + "}", "$assistantId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun getMessage(threadId: kotlin.String,messageId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): MessageObject =
      client.request {
        configure()
        method = HttpMethod.Get
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/messages/{message_id}".replace("{" + "thread_id" + "}", "$threadId").replace("{" + "message_id" + "}", "$messageId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun getRun(threadId: kotlin.String,runId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): RunObject =
      client.request {
        configure()
        method = HttpMethod.Get
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/runs/{run_id}".replace("{" + "thread_id" + "}", "$threadId").replace("{" + "run_id" + "}", "$runId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun getRunStep(threadId: kotlin.String,runId: kotlin.String,stepId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): RunStepObject =
      client.request {
        configure()
        method = HttpMethod.Get
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/runs/{run_id}/steps/{step_id}".replace("{" + "thread_id" + "}", "$threadId").replace("{" + "run_id" + "}", "$runId").replace("{" + "step_id" + "}", "$stepId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun getThread(threadId: kotlin.String, configure: HttpRequestBuilder.() -> Unit): ThreadObject =
      client.request {
        configure()
        method = HttpMethod.Get
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}".replace("{" + "thread_id" + "}", "$threadId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun listAssistants(limit: kotlin.Int?,order: OrderListAssistants?,after: kotlin.String?,before: kotlin.String?, configure: HttpRequestBuilder.() -> Unit): ListAssistantsResponse =
      client.request {
        configure()
        method = HttpMethod.Get
        contentType(ContentType.Application.Json)
            parameter("limit", limit)
            parameter("order", order)
            parameter("after", after)
            parameter("before", before)
        url { path("assistants") }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun listMessages(threadId: kotlin.String,limit: kotlin.Int?,order: OrderListMessages?,after: kotlin.String?,before: kotlin.String?,runId: kotlin.String?, configure: HttpRequestBuilder.() -> Unit): ListMessagesResponse =
      client.request {
        configure()
        method = HttpMethod.Get
        contentType(ContentType.Application.Json)
            parameter("limit", limit)
            parameter("order", order)
            parameter("after", after)
            parameter("before", before)
            parameter("run_id", runId)
        url { path("threads/{thread_id}/messages".replace("{" + "thread_id" + "}", "$threadId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun listRunSteps(threadId: kotlin.String,runId: kotlin.String,limit: kotlin.Int?,order: OrderListRunSteps?,after: kotlin.String?,before: kotlin.String?, configure: HttpRequestBuilder.() -> Unit): ListRunStepsResponse =
      client.request {
        configure()
        method = HttpMethod.Get
        contentType(ContentType.Application.Json)
            parameter("limit", limit)
            parameter("order", order)
            parameter("after", after)
            parameter("before", before)
        url { path("threads/{thread_id}/runs/{run_id}/steps".replace("{" + "thread_id" + "}", "$threadId").replace("{" + "run_id" + "}", "$runId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun listRuns(threadId: kotlin.String,limit: kotlin.Int?,order: OrderListRuns?,after: kotlin.String?,before: kotlin.String?, configure: HttpRequestBuilder.() -> Unit): ListRunsResponse =
      client.request {
        configure()
        method = HttpMethod.Get
        contentType(ContentType.Application.Json)
            parameter("limit", limit)
            parameter("order", order)
            parameter("after", after)
            parameter("before", before)
        url { path("threads/{thread_id}/runs".replace("{" + "thread_id" + "}", "$threadId")) }
        setBody(
                io.ktor.client.utils.EmptyContent
        )
      }.serializeOrThrowWithResponseInfo()

    override suspend fun modifyAssistant(assistantId: kotlin.String,modifyAssistantRequest: ModifyAssistantRequest, configure: HttpRequestBuilder.() -> Unit): AssistantObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("assistants/{assistant_id}".replace("{" + "assistant_id" + "}", "$assistantId")) }
        setBody(modifyAssistantRequest
)
      }.serializeOrThrowWithResponseInfo()

    override suspend fun modifyMessage(threadId: kotlin.String,messageId: kotlin.String,modifyMessageRequest: ModifyMessageRequest, configure: HttpRequestBuilder.() -> Unit): MessageObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/messages/{message_id}".replace("{" + "thread_id" + "}", "$threadId").replace("{" + "message_id" + "}", "$messageId")) }
        setBody(modifyMessageRequest
)
      }.serializeOrThrowWithResponseInfo()

    override suspend fun modifyRun(threadId: kotlin.String,runId: kotlin.String,modifyRunRequest: ModifyRunRequest, configure: HttpRequestBuilder.() -> Unit): RunObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/runs/{run_id}".replace("{" + "thread_id" + "}", "$threadId").replace("{" + "run_id" + "}", "$runId")) }
        setBody(modifyRunRequest
)
      }.serializeOrThrowWithResponseInfo()

    override suspend fun modifyThread(threadId: kotlin.String,modifyThreadRequest: ModifyThreadRequest, configure: HttpRequestBuilder.() -> Unit): ThreadObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}".replace("{" + "thread_id" + "}", "$threadId")) }
        setBody(modifyThreadRequest
)
      }.serializeOrThrowWithResponseInfo()

    override suspend fun submitToolOuputsToRun(threadId: kotlin.String,runId: kotlin.String,submitToolOutputsRunRequest: SubmitToolOutputsRunRequest, configure: HttpRequestBuilder.() -> Unit): RunObject =
      client.request {
        configure()
        method = HttpMethod.Post
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/runs/{run_id}/submit_tool_outputs".replace("{" + "thread_id" + "}", "$threadId").replace("{" + "run_id" + "}", "$runId")) }
        setBody(submitToolOutputsRunRequest
)
      }.serializeOrThrowWithResponseInfo()

    override fun submitToolOuputsToRunStream(threadId: kotlin.String, runId: kotlin.String, submitToolOutputsRunRequest: SubmitToolOutputsRunRequest, configure: HttpRequestBuilder.() -> Unit): Flow = flow {
      client.prepareRequest {
        timeout {
          requestTimeoutMillis = 60.seconds.toLong(DurationUnit.MILLISECONDS)
          socketTimeoutMillis = 60.seconds.toLong(DurationUnit.MILLISECONDS)
        }
        configure()
        method = HttpMethod.Post
        accept(ContentType.Text.EventStream)
        header(HttpHeaders.CacheControl, "no-cache")
        header(HttpHeaders.Connection, "keep-alive")
        contentType(ContentType.Application.Json)
        url { path("threads/{thread_id}/runs/{run_id}/submit_tool_outputs".replace("{" + "thread_id" + "}", "$threadId").replace("{" + "run_id" + "}", "$runId")) }
        val element = Json.encodeToJsonElement(SubmitToolOutputsRunRequest.serializer(), submitToolOutputsRunRequest)
        val jsObject = JsonObject(element.jsonObject + Pair("stream", JsonPrimitive(true)))
        setBody(jsObject)
      }.execute { streamEvents(it, config.json, config.streamingPrefix, config.streamingDelimiter) }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy