From 0db20cf0c61a718d3c85ef6c3d49d5e5925ec145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fede=20Fern=C3=A1ndez?= <720923+fedefernandez@users.noreply.github.com> Date: Fri, 24 Nov 2023 15:19:17 +0100 Subject: [PATCH] Update gen models (#559) * Updates ApiClient * Resources and config * Extension models * Updates metadata objects to JsonObject * Updates openai api version * Fixes AssistantTool model * Adds a way of make fields nullables --- .../client/.openapi-generator-ignore | 8 +- openai-client/client/.openapi-generator/FILES | 7 -- .../client/.openapi-generator/VERSION | 2 +- openai-client/client/build.gradle.kts | 2 + .../openai/infrastructure/ApiClient.kt | 23 +++-- .../openai/infrastructure/HttpResponse.kt | 7 +- .../openai/models/AssistantObject.kt | 6 +- .../models/AssistantObjectToolsInner.kt | 36 -------- .../openai/models/AssistantToolsCode.kt | 30 ------- .../openai/models/AssistantToolsFunction.kt | 34 -------- .../models/AssistantToolsFunctionFunction.kt | 31 ------- .../openai/models/AssistantToolsRetrieval.kt | 30 ------- .../openai/models/CreateAssistantRequest.kt | 6 +- .../CreateChatCompletionRequestModel.kt | 3 +- .../openai/models/CreateMessageRequest.kt | 2 +- .../openai/models/CreateRunRequest.kt | 6 +- .../models/CreateThreadAndRunRequest.kt | 2 +- .../openai/models/CreateThreadRequest.kt | 2 +- .../models/ListAssistantFilesResponse.kt | 4 +- .../openai/models/ListAssistantsResponse.kt | 4 +- .../openai/models/ListMessageFilesResponse.kt | 4 +- .../openai/models/ListMessagesResponse.kt | 4 +- .../openai/models/ListRunStepsResponse.kt | 4 +- .../openai/models/ListRunsResponse.kt | 4 +- .../openai/models/ListThreadsResponse.kt | 4 +- .../functional/openai/models/MessageObject.kt | 2 +- .../models/MessageObjectContentInner.kt | 4 +- .../openai/models/ModifyAssistantRequest.kt | 6 +- .../openai/models/ModifyMessageRequest.kt | 2 +- .../openai/models/ModifyRunRequest.kt | 2 +- .../openai/models/ModifyThreadRequest.kt | 2 +- .../functional/openai/models/RunObject.kt | 10 ++- .../RunStepDetailsMessageCreationObject.kt | 38 -------- ...lsCodeObjectCodeInterpreterOutputsInner.kt | 6 +- ...pDetailsToolCallsFunctionObjectFunction.kt | 2 +- .../models/RunStepDetailsToolCallsObject.kt | 41 --------- ...tepDetailsToolCallsObjectToolCallsInner.kt | 8 +- .../RunStepDetailsToolCallsRetrievalObject.kt | 2 +- .../functional/openai/models/RunStepObject.kt | 8 +- .../openai/models/RunStepObjectStepDetails.kt | 46 ---------- .../functional/openai/models/ThreadObject.kt | 2 +- .../models/ext/assistant/AssistantTools.kt | 46 ++++++++++ .../ext/assistant/RunStepObjectStepDetails.kt | 68 +++++++++++++++ .../ext/chat/ChatCompletionRequestMessage.kt | 43 +++++---- ...ChatCompletionRequestUserMessageContent.kt | 31 +++---- ...ompletionRequestUserMessageContentImage.kt | 2 +- ...CompletionRequestUserMessageContentText.kt | 2 +- .../create/CreateChatCompletionRequestStop.kt | 15 +++- .../ext/chat/stream/ChatCompletionsStream.kt | 87 +++++++++++-------- .../create/CreateEmbeddingRequestInput.kt | 14 ++- .../client/src/jvmMain/resources/logback.xml | 15 ++++ openai-client/generator/build.gradle.kts | 4 +- .../infrastructure/ApiClient.kt.mustache | 12 +-- .../infrastructure/HttpResponse.kt.mustache | 54 ++++++++++++ .../generator/config/openai-api-commit | 2 +- .../generator/config/openai-config.json | 15 +++- .../openai/generator/KMMGeneratorConfig.java | 34 +++++++- 57 files changed, 447 insertions(+), 443 deletions(-) delete mode 100644 openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantObjectToolsInner.kt delete mode 100644 openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsCode.kt delete mode 100644 openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunction.kt delete mode 100644 openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunctionFunction.kt delete mode 100644 openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsRetrieval.kt delete mode 100644 openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsMessageCreationObject.kt delete mode 100644 openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObject.kt delete mode 100644 openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObjectStepDetails.kt create mode 100644 openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/assistant/AssistantTools.kt create mode 100644 openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/assistant/RunStepObjectStepDetails.kt create mode 100644 openai-client/client/src/jvmMain/resources/logback.xml create mode 100644 openai-client/generator/config/libraries/multiplatform/infrastructure/HttpResponse.kt.mustache diff --git a/openai-client/client/.openapi-generator-ignore b/openai-client/client/.openapi-generator-ignore index 1c3c7442d..c6a069146 100644 --- a/openai-client/client/.openapi-generator-ignore +++ b/openai-client/client/.openapi-generator-ignore @@ -33,6 +33,10 @@ docs/** src/*Test/** # Unused models +src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsCode.kt +src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunction.kt +src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsRetrieval.kt +src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunctionFunction.kt src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionRequestMessage.kt src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionRequestSystemMessage.kt src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionRequestUserMessage.kt @@ -44,4 +48,6 @@ src/commonMain/kotlin/com/xebia/functional/openai/models/CreateChatCompletionFun src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionRequestMessageContentPart.kt src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionRequestMessageContentPartText.kt src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionRequestMessageContentPartImage.kt -src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionRequestMessageContentPartImageImageUrl.kt \ No newline at end of file +src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionRequestMessageContentPartImageImageUrl.kt +src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsMessageCreationObject.kt +src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObject.kt \ No newline at end of file diff --git a/openai-client/client/.openapi-generator/FILES b/openai-client/client/.openapi-generator/FILES index 1069164fa..bb0510213 100644 --- a/openai-client/client/.openapi-generator/FILES +++ b/openai-client/client/.openapi-generator/FILES @@ -27,10 +27,6 @@ src/commonMain/kotlin/com/xebia/functional/openai/infrastructure/RequestConfig.k src/commonMain/kotlin/com/xebia/functional/openai/infrastructure/RequestMethod.kt src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantFileObject.kt src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantObject.kt -src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantObjectToolsInner.kt -src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsCode.kt -src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunction.kt -src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsRetrieval.kt src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionFunctionCallOption.kt src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionFunctions.kt src/commonMain/kotlin/com/xebia/functional/openai/models/ChatCompletionMessageToolCall.kt @@ -149,7 +145,6 @@ src/commonMain/kotlin/com/xebia/functional/openai/models/RunObject.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunObjectLastError.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunObjectRequiredAction.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunObjectRequiredActionSubmitToolOutputs.kt -src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsMessageCreationObject.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsMessageCreationObjectMessageCreation.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsCodeObject.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsCodeObjectCodeInterpreter.kt @@ -159,12 +154,10 @@ src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCalls src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsCodeOutputLogsObject.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsFunctionObject.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsFunctionObjectFunction.kt -src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObject.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObjectToolCallsInner.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsRetrievalObject.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObject.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObjectLastError.kt -src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObjectStepDetails.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunToolCallObject.kt src/commonMain/kotlin/com/xebia/functional/openai/models/RunToolCallObjectFunction.kt src/commonMain/kotlin/com/xebia/functional/openai/models/SubmitToolOutputsRunRequest.kt diff --git a/openai-client/client/.openapi-generator/VERSION b/openai-client/client/.openapi-generator/VERSION index 73a86b197..3769235d3 100644 --- a/openai-client/client/.openapi-generator/VERSION +++ b/openai-client/client/.openapi-generator/VERSION @@ -1 +1 @@ -7.0.1 \ No newline at end of file +7.1.0 \ No newline at end of file diff --git a/openai-client/client/build.gradle.kts b/openai-client/client/build.gradle.kts index b0d341003..529c4491a 100644 --- a/openai-client/client/build.gradle.kts +++ b/openai-client/client/build.gradle.kts @@ -62,8 +62,10 @@ kotlin { } val commonMain by getting { dependencies { + api(projects.xefTokenizer) implementation(libs.ktor.client.content.negotiation) implementation(libs.ktor.client.serialization) + implementation(libs.ktor.client.logging) implementation(libs.klogging) } } diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/infrastructure/ApiClient.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/infrastructure/ApiClient.kt index 6cd882af5..ace3874c4 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/infrastructure/ApiClient.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/infrastructure/ApiClient.kt @@ -17,7 +17,7 @@ import io.ktor.serialization.kotlinx.json.json import kotlin.Unit import kotlinx.serialization.json.Json -open class ApiClient(private val baseUrl: String) { +open class ApiClient(val baseUrl: String) { lateinit var client: HttpClient @@ -52,7 +52,7 @@ open class ApiClient(private val baseUrl: String) { prettyPrint = true isLenient = true } - protected val UNSAFE_HEADERS = listOf(HttpHeaders.ContentType) + val UNSAFE_HEADERS = listOf(HttpHeaders.ContentType) } /** @@ -165,12 +165,14 @@ open class ApiClient(private val baseUrl: String) { return client.request { this.url { + contentType(ContentType.Application.Json) this.takeFrom(URLBuilder(baseUrl)) appendPath(requestConfig.path.trimStart('/').split('/')) requestConfig.query.forEach { query -> query.value.forEach { value -> parameter(query.key, value) } } } + this.header("OpenAI-Beta", "assistants=v1") this.method = requestConfig.method.httpMethod headers .filter { header -> !UNSAFE_HEADERS.contains(header.key) } @@ -183,9 +185,7 @@ open class ApiClient(private val baseUrl: String) { } } - private fun RequestConfig.updateForAuth( - authNames: kotlin.collections.List - ) { + fun RequestConfig.updateForAuth(authNames: kotlin.collections.List) { for (authName in authNames) { val auth = authentications?.get(authName) ?: throw Exception("Authentication undefined: $authName") @@ -193,14 +193,13 @@ open class ApiClient(private val baseUrl: String) { } } - private fun URLBuilder.appendPath(components: kotlin.collections.List): URLBuilder = - apply { - encodedPath = - encodedPath.trimEnd('/') + - components.joinToString("/", prefix = "/") { it.encodeURLQueryComponent() } - } + fun URLBuilder.appendPath(components: kotlin.collections.List): URLBuilder = apply { + encodedPath = + encodedPath.trimEnd('/') + + components.joinToString("/", prefix = "/") { it.encodeURLQueryComponent() } + } - private val RequestMethod.httpMethod: HttpMethod + val RequestMethod.httpMethod: HttpMethod get() = when (this) { RequestMethod.DELETE -> HttpMethod.Delete diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/infrastructure/HttpResponse.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/infrastructure/HttpResponse.kt index 44e9b4d11..b4451a8b3 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/infrastructure/HttpResponse.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/infrastructure/HttpResponse.kt @@ -37,8 +37,11 @@ interface BodyProvider { class TypedBodyProvider(private val type: TypeInfo) : BodyProvider { @Suppress("UNCHECKED_CAST") - override suspend fun body(response: io.ktor.client.statement.HttpResponse): T = - response.call.body(type) as T + override suspend fun body(response: io.ktor.client.statement.HttpResponse): T { + if (!response.status.isSuccess()) + error("${response.status.value}:${response.status.description}") + return response.call.body(type) as T + } @Suppress("UNCHECKED_CAST") override suspend fun typedBody( diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantObject.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantObject.kt index 494a74b71..967b4ec3f 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantObject.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantObject.kt @@ -59,7 +59,9 @@ data class AssistantObject( /* A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `retrieval`, or `function`. */ @SerialName(value = "tools") @Required - val tools: kotlin.collections.List = arrayListOf(), + val tools: + kotlin.collections.List = + arrayListOf(), /* A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order. */ @SerialName(value = "file_ids") @@ -67,7 +69,7 @@ data class AssistantObject( val fileIds: kotlin.collections.List = arrayListOf(), /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") @Required val metadata: kotlin.String? + @SerialName(value = "metadata") @Required val metadata: kotlinx.serialization.json.JsonObject? ) { /** diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantObjectToolsInner.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantObjectToolsInner.kt deleted file mode 100644 index 281ba3d98..000000000 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantObjectToolsInner.kt +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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.models - -import kotlinx.serialization.* -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.* - -/** - * @param type The type of tool being defined: `code_interpreter` - * @param function - */ -@Serializable -data class AssistantObjectToolsInner( - - /* The type of tool being defined: `code_interpreter` */ - @SerialName(value = "type") @Required val type: AssistantObjectToolsInner.Type, - @SerialName(value = "function") @Required val function: FunctionObject -) { - - /** - * The type of tool being defined: `code_interpreter` - * - * Values: code_interpreter,retrieval,function - */ - @Serializable - enum class Type(val value: kotlin.String) { - @SerialName(value = "code_interpreter") code_interpreter("code_interpreter"), - @SerialName(value = "retrieval") retrieval("retrieval"), - @SerialName(value = "function") function("function") - } -} diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsCode.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsCode.kt deleted file mode 100644 index d51afb23f..000000000 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsCode.kt +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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.models - -import kotlinx.serialization.* -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.* - -/** @param type The type of tool being defined: `code_interpreter` */ -@Serializable -data class AssistantToolsCode( - - /* The type of tool being defined: `code_interpreter` */ - @SerialName(value = "type") @Required val type: AssistantToolsCode.Type -) { - - /** - * The type of tool being defined: `code_interpreter` - * - * Values: code_interpreter - */ - @Serializable - enum class Type(val value: kotlin.String) { - @SerialName(value = "code_interpreter") code_interpreter("code_interpreter") - } -} diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunction.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunction.kt deleted file mode 100644 index a6700ca48..000000000 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunction.kt +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.models - -import kotlinx.serialization.* -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.* - -/** - * @param type The type of tool being defined: `function` - * @param function - */ -@Serializable -data class AssistantToolsFunction( - - /* The type of tool being defined: `function` */ - @SerialName(value = "type") @Required val type: AssistantToolsFunction.Type, - @SerialName(value = "function") @Required val function: FunctionObject -) { - - /** - * The type of tool being defined: `function` - * - * Values: function - */ - @Serializable - enum class Type(val value: kotlin.String) { - @SerialName(value = "function") function("function") - } -} diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunctionFunction.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunctionFunction.kt deleted file mode 100644 index b8092dc16..000000000 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsFunctionFunction.kt +++ /dev/null @@ -1,31 +0,0 @@ -/** - * 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.models - -import kotlinx.serialization.* -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.* - -/** - * The function definition. - * - * @param description A description of what the function does, used by the model to choose when and - * how to call the function. - * @param name The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores - * and dashes, with a maximum length of 64. - * @param parameters - */ -@Serializable -data class AssistantToolsFunctionFunction( - - /* A description of what the function does, used by the model to choose when and how to call the function. */ - @SerialName(value = "description") @Required val description: kotlin.String, - - /* The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. */ - @SerialName(value = "name") @Required val name: kotlin.String, - @SerialName(value = "parameters") @Required val parameters: kotlinx.serialization.json.JsonObject -) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsRetrieval.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsRetrieval.kt deleted file mode 100644 index e4fbd038a..000000000 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/AssistantToolsRetrieval.kt +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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.models - -import kotlinx.serialization.* -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.* - -/** @param type The type of tool being defined: `retrieval` */ -@Serializable -data class AssistantToolsRetrieval( - - /* The type of tool being defined: `retrieval` */ - @SerialName(value = "type") @Required val type: AssistantToolsRetrieval.Type -) { - - /** - * The type of tool being defined: `retrieval` - * - * Values: retrieval - */ - @Serializable - enum class Type(val value: kotlin.String) { - @SerialName(value = "retrieval") retrieval("retrieval") - } -} diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateAssistantRequest.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateAssistantRequest.kt index 6e5b2dfe9..1b37bb29a 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateAssistantRequest.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateAssistantRequest.kt @@ -40,12 +40,14 @@ data class CreateAssistantRequest( /* A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `retrieval`, or `function`. */ @SerialName(value = "tools") - val tools: kotlin.collections.List? = arrayListOf(), + val tools: + kotlin.collections.List? = + arrayListOf(), /* A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order. */ @SerialName(value = "file_ids") val fileIds: kotlin.collections.List? = arrayListOf(), /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") val metadata: kotlin.String? = null + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateChatCompletionRequestModel.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateChatCompletionRequestModel.kt index 141b2e945..f7dfb7e4c 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateChatCompletionRequestModel.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateChatCompletionRequestModel.kt @@ -14,7 +14,7 @@ import kotlinx.serialization.* * which models work with the Chat API. * * Values: - * gpt_4_1106_preview,gpt_4_vision_preview,gpt_4,gpt_4_0314,gpt_4_0613,gpt_4_32k,gpt_4_32k_0314,gpt_4_32k_0613,gpt_3_5_turbo,gpt_3_5_turbo_16k,gpt_3_5_turbo_0301,gpt_3_5_turbo_0613,gpt_3_5_turbo_16k_0613 + * gpt_4_1106_preview,gpt_4_vision_preview,gpt_4,gpt_4_0314,gpt_4_0613,gpt_4_32k,gpt_4_32k_0314,gpt_4_32k_0613,gpt_3_5_turbo_1106,gpt_3_5_turbo,gpt_3_5_turbo_16k,gpt_3_5_turbo_0301,gpt_3_5_turbo_0613,gpt_3_5_turbo_16k_0613 */ @Serializable enum class CreateChatCompletionRequestModel(val value: kotlin.String) { @@ -27,6 +27,7 @@ enum class CreateChatCompletionRequestModel(val value: kotlin.String) { @SerialName(value = "gpt-4-32k") gpt_4_32k("gpt-4-32k"), @SerialName(value = "gpt-4-32k-0314") gpt_4_32k_0314("gpt-4-32k-0314"), @SerialName(value = "gpt-4-32k-0613") gpt_4_32k_0613("gpt-4-32k-0613"), + @SerialName(value = "gpt-3.5-turbo-1106") gpt_3_5_turbo_1106("gpt-3.5-turbo-1106"), @SerialName(value = "gpt-3.5-turbo") gpt_3_5_turbo("gpt-3.5-turbo"), @SerialName(value = "gpt-3.5-turbo-16k") gpt_3_5_turbo_16k("gpt-3.5-turbo-16k"), @SerialName(value = "gpt-3.5-turbo-0301") gpt_3_5_turbo_0301("gpt-3.5-turbo-0301"), diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateMessageRequest.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateMessageRequest.kt index af7637a51..e5ab7a8f0 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateMessageRequest.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateMessageRequest.kt @@ -35,7 +35,7 @@ data class CreateMessageRequest( val fileIds: kotlin.collections.List? = arrayListOf(), /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") val metadata: kotlin.String? = null + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) { /** diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateRunRequest.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateRunRequest.kt index 12717d3d2..9a8e88d94 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateRunRequest.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateRunRequest.kt @@ -38,8 +38,10 @@ data class CreateRunRequest( /* Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis. */ @SerialName(value = "tools") - val tools: kotlin.collections.List? = null, + val tools: + kotlin.collections.List? = + null, /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") val metadata: kotlin.String? = null + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateThreadAndRunRequest.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateThreadAndRunRequest.kt index dbf519677..d75cd95aa 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateThreadAndRunRequest.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateThreadAndRunRequest.kt @@ -43,5 +43,5 @@ data class CreateThreadAndRunRequest( val tools: kotlin.collections.List? = null, /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") val metadata: kotlin.String? = null + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateThreadRequest.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateThreadRequest.kt index 3459ea697..4ba73c435 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateThreadRequest.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/CreateThreadRequest.kt @@ -24,5 +24,5 @@ data class CreateThreadRequest( val messages: kotlin.collections.List? = null, /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") val metadata: kotlin.String? = null + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListAssistantFilesResponse.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListAssistantFilesResponse.kt index 23f89e7c1..24024cf8f 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListAssistantFilesResponse.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListAssistantFilesResponse.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* data class ListAssistantFilesResponse( @SerialName(value = "object") @Required val `object`: kotlin.String, @SerialName(value = "data") @Required val `data`: kotlin.collections.List, - @SerialName(value = "first_id") @Required val firstId: kotlin.String, - @SerialName(value = "last_id") @Required val lastId: kotlin.String, + @SerialName(value = "first_id") val firstId: kotlin.String? = null, + @SerialName(value = "last_id") val lastId: kotlin.String? = null, @SerialName(value = "has_more") @Required val hasMore: kotlin.Boolean ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListAssistantsResponse.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListAssistantsResponse.kt index c4e0d93cc..bb8b8fe94 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListAssistantsResponse.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListAssistantsResponse.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* data class ListAssistantsResponse( @SerialName(value = "object") @Required val `object`: kotlin.String, @SerialName(value = "data") @Required val `data`: kotlin.collections.List, - @SerialName(value = "first_id") @Required val firstId: kotlin.String, - @SerialName(value = "last_id") @Required val lastId: kotlin.String, + @SerialName(value = "first_id") val firstId: kotlin.String? = null, + @SerialName(value = "last_id") val lastId: kotlin.String? = null, @SerialName(value = "has_more") @Required val hasMore: kotlin.Boolean ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListMessageFilesResponse.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListMessageFilesResponse.kt index 5a4965db9..78c129bfe 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListMessageFilesResponse.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListMessageFilesResponse.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* data class ListMessageFilesResponse( @SerialName(value = "object") @Required val `object`: kotlin.String, @SerialName(value = "data") @Required val `data`: kotlin.collections.List, - @SerialName(value = "first_id") @Required val firstId: kotlin.String, - @SerialName(value = "last_id") @Required val lastId: kotlin.String, + @SerialName(value = "first_id") val firstId: kotlin.String? = null, + @SerialName(value = "last_id") val lastId: kotlin.String? = null, @SerialName(value = "has_more") @Required val hasMore: kotlin.Boolean ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListMessagesResponse.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListMessagesResponse.kt index 49fbcaf3e..df55887e5 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListMessagesResponse.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListMessagesResponse.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* data class ListMessagesResponse( @SerialName(value = "object") @Required val `object`: kotlin.String, @SerialName(value = "data") @Required val `data`: kotlin.collections.List, - @SerialName(value = "first_id") @Required val firstId: kotlin.String, - @SerialName(value = "last_id") @Required val lastId: kotlin.String, + @SerialName(value = "first_id") val firstId: kotlin.String? = null, + @SerialName(value = "last_id") val lastId: kotlin.String? = null, @SerialName(value = "has_more") @Required val hasMore: kotlin.Boolean ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListRunStepsResponse.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListRunStepsResponse.kt index 38a3cac89..681da2fb8 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListRunStepsResponse.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListRunStepsResponse.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* data class ListRunStepsResponse( @SerialName(value = "object") @Required val `object`: kotlin.String, @SerialName(value = "data") @Required val `data`: kotlin.collections.List, - @SerialName(value = "first_id") @Required val firstId: kotlin.String, - @SerialName(value = "last_id") @Required val lastId: kotlin.String, + @SerialName(value = "first_id") val firstId: kotlin.String? = null, + @SerialName(value = "last_id") val lastId: kotlin.String? = null, @SerialName(value = "has_more") @Required val hasMore: kotlin.Boolean ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListRunsResponse.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListRunsResponse.kt index e21d10d4a..e1c7e4d5a 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListRunsResponse.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListRunsResponse.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* data class ListRunsResponse( @SerialName(value = "object") @Required val `object`: kotlin.String, @SerialName(value = "data") @Required val `data`: kotlin.collections.List, - @SerialName(value = "first_id") @Required val firstId: kotlin.String, - @SerialName(value = "last_id") @Required val lastId: kotlin.String, + @SerialName(value = "first_id") val firstId: kotlin.String? = null, + @SerialName(value = "last_id") val lastId: kotlin.String? = null, @SerialName(value = "has_more") @Required val hasMore: kotlin.Boolean ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListThreadsResponse.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListThreadsResponse.kt index be70e4d30..19568998b 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListThreadsResponse.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ListThreadsResponse.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* data class ListThreadsResponse( @SerialName(value = "object") @Required val `object`: kotlin.String, @SerialName(value = "data") @Required val `data`: kotlin.collections.List, - @SerialName(value = "first_id") @Required val firstId: kotlin.String, - @SerialName(value = "last_id") @Required val lastId: kotlin.String, + @SerialName(value = "first_id") val firstId: kotlin.String? = null, + @SerialName(value = "last_id") val lastId: kotlin.String? = null, @SerialName(value = "has_more") @Required val hasMore: kotlin.Boolean ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/MessageObject.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/MessageObject.kt index 227b3883f..0eba8ab6f 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/MessageObject.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/MessageObject.kt @@ -65,7 +65,7 @@ data class MessageObject( val fileIds: kotlin.collections.List = arrayListOf(), /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") @Required val metadata: kotlin.String? + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) { /** diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/MessageObjectContentInner.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/MessageObjectContentInner.kt index 55368a588..b508fd095 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/MessageObjectContentInner.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/MessageObjectContentInner.kt @@ -20,8 +20,8 @@ data class MessageObjectContentInner( /* Always `image_file`. */ @SerialName(value = "type") @Required val type: MessageObjectContentInner.Type, - @SerialName(value = "image_file") @Required val imageFile: MessageContentImageFileObjectImageFile, - @SerialName(value = "text") @Required val text: MessageContentTextObjectText + @SerialName(value = "image_file") val imageFile: MessageContentImageFileObjectImageFile? = null, + @SerialName(value = "text") val text: MessageContentTextObjectText? = null ) { /** diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyAssistantRequest.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyAssistantRequest.kt index 6ac4376ae..3d1482f38 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyAssistantRequest.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyAssistantRequest.kt @@ -41,12 +41,14 @@ data class ModifyAssistantRequest( /* A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `retrieval`, or `function`. */ @SerialName(value = "tools") - val tools: kotlin.collections.List? = arrayListOf(), + val tools: + kotlin.collections.List? = + arrayListOf(), /* A list of [File](/docs/api-reference/files) IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order. If a file was previosuly attached to the list but does not show up in the list, it will be deleted from the assistant. */ @SerialName(value = "file_ids") val fileIds: kotlin.collections.List? = arrayListOf(), /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") val metadata: kotlin.String? = null + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyMessageRequest.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyMessageRequest.kt index 7cff6d2f4..589bc47ab 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyMessageRequest.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyMessageRequest.kt @@ -19,5 +19,5 @@ import kotlinx.serialization.encoding.* data class ModifyMessageRequest( /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") val metadata: kotlin.String? = null + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyRunRequest.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyRunRequest.kt index 6bc728f3b..6d4ea9fda 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyRunRequest.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyRunRequest.kt @@ -19,5 +19,5 @@ import kotlinx.serialization.encoding.* data class ModifyRunRequest( /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") val metadata: kotlin.String? = null + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyThreadRequest.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyThreadRequest.kt index f4d37bce9..d8fdd5f3a 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyThreadRequest.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ModifyThreadRequest.kt @@ -19,5 +19,5 @@ import kotlinx.serialization.encoding.* data class ModifyThreadRequest( /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") val metadata: kotlin.String? = null + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunObject.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunObject.kt index 3ed561ea9..e74e3cc4d 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunObject.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunObject.kt @@ -60,11 +60,11 @@ data class RunObject( /* The status of the run, which can be either `queued`, `in_progress`, `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`, or `expired`. */ @SerialName(value = "status") @Required val status: RunObject.Status, - @SerialName(value = "required_action") @Required val requiredAction: RunObjectRequiredAction?, + @SerialName(value = "required_action") val requiredAction: RunObjectRequiredAction? = null, @SerialName(value = "last_error") @Required val lastError: RunObjectLastError?, /* The Unix timestamp (in seconds) for when the run will expire. */ - @SerialName(value = "expires_at") @Required val expiresAt: kotlin.Int, + @SerialName(value = "expires_at") val expiresAt: kotlin.Int? = null, /* The Unix timestamp (in seconds) for when the run was started. */ @SerialName(value = "started_at") @Required val startedAt: kotlin.Int?, @@ -87,7 +87,9 @@ data class RunObject( /* The list of tools that the [assistant](/docs/api-reference/assistants) used for this run. */ @SerialName(value = "tools") @Required - val tools: kotlin.collections.List = arrayListOf(), + val tools: + kotlin.collections.List = + arrayListOf(), /* The list of [File](/docs/api-reference/files) IDs the [assistant](/docs/api-reference/assistants) used for this run. */ @SerialName(value = "file_ids") @@ -95,7 +97,7 @@ data class RunObject( val fileIds: kotlin.collections.List = arrayListOf(), /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") @Required val metadata: kotlin.String? + @SerialName(value = "metadata") @Required val metadata: kotlinx.serialization.json.JsonObject? ) { /** diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsMessageCreationObject.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsMessageCreationObject.kt deleted file mode 100644 index 5c97b560f..000000000 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsMessageCreationObject.kt +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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.models - -import kotlinx.serialization.* -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.* - -/** - * Details of the message creation by the run step. - * - * @param type Always `message_creation``. - * @param messageCreation - */ -@Serializable -data class RunStepDetailsMessageCreationObject( - - /* Always `message_creation``. */ - @SerialName(value = "type") @Required val type: RunStepDetailsMessageCreationObject.Type, - @SerialName(value = "message_creation") - @Required - val messageCreation: RunStepDetailsMessageCreationObjectMessageCreation -) { - - /** - * Always `message_creation``. - * - * Values: message_creation - */ - @Serializable - enum class Type(val value: kotlin.String) { - @SerialName(value = "message_creation") message_creation("message_creation") - } -} diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputsInner.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputsInner.kt index 25cc5e8e9..ffd885fad 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputsInner.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputsInner.kt @@ -24,10 +24,8 @@ data class RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputsInner( val type: RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputsInner.Type, /* The text output from the Code Interpreter tool call. */ - @SerialName(value = "logs") @Required val logs: kotlin.String, - @SerialName(value = "image") - @Required - val image: RunStepDetailsToolCallsCodeOutputImageObjectImage + @SerialName(value = "logs") val logs: kotlin.String? = null, + @SerialName(value = "image") val image: RunStepDetailsToolCallsCodeOutputImageObjectImage? = null ) { /** diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsFunctionObjectFunction.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsFunctionObjectFunction.kt index 9e4262adf..0f151456a 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsFunctionObjectFunction.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsFunctionObjectFunction.kt @@ -28,5 +28,5 @@ data class RunStepDetailsToolCallsFunctionObjectFunction( @SerialName(value = "arguments") @Required val arguments: kotlin.String, /* The output of the function. This will be `null` if the outputs have not been [submitted](/docs/api-reference/runs/submitToolOutputs) yet. */ - @SerialName(value = "output") @Required val output: kotlin.String? + @SerialName(value = "output") val output: kotlin.String? = null ) diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObject.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObject.kt deleted file mode 100644 index 81b162192..000000000 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObject.kt +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 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.models - -import kotlinx.serialization.* -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.* - -/** - * Details of the tool call. - * - * @param type Always `tool_calls`. - * @param toolCalls An array of tool calls the run step was involved in. These can be associated - * with one of three types of tools: `code_interpreter`, `retrieval`, or `function`. - */ -@Serializable -data class RunStepDetailsToolCallsObject( - - /* Always `tool_calls`. */ - @SerialName(value = "type") @Required val type: RunStepDetailsToolCallsObject.Type, - - /* An array of tool calls the run step was involved in. These can be associated with one of three types of tools: `code_interpreter`, `retrieval`, or `function`. */ - @SerialName(value = "tool_calls") - @Required - val toolCalls: kotlin.collections.List -) { - - /** - * Always `tool_calls`. - * - * Values: tool_calls - */ - @Serializable - enum class Type(val value: kotlin.String) { - @SerialName(value = "tool_calls") tool_calls("tool_calls") - } -} diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObjectToolCallsInner.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObjectToolCallsInner.kt index 889718714..7803b8b20 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObjectToolCallsInner.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsObjectToolCallsInner.kt @@ -27,14 +27,12 @@ data class RunStepDetailsToolCallsObjectToolCallsInner( /* The type of tool call. This is always going to be `code_interpreter` for this type of tool call. */ @SerialName(value = "type") @Required val type: RunStepDetailsToolCallsObjectToolCallsInner.Type, @SerialName(value = "code_interpreter") - @Required - val codeInterpreter: RunStepDetailsToolCallsCodeObjectCodeInterpreter, + val codeInterpreter: RunStepDetailsToolCallsCodeObjectCodeInterpreter? = null, /* For now, this is always going to be an empty object. */ - @SerialName(value = "retrieval") @Required val retrieval: kotlin.String, + @SerialName(value = "retrieval") val retrieval: kotlinx.serialization.json.JsonObject? = null, @SerialName(value = "function") - @Required - val function: RunStepDetailsToolCallsFunctionObjectFunction + val function: RunStepDetailsToolCallsFunctionObjectFunction? = null ) { /** diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsRetrievalObject.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsRetrievalObject.kt index 99f49491c..9109d6d31 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsRetrievalObject.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepDetailsToolCallsRetrievalObject.kt @@ -26,7 +26,7 @@ data class RunStepDetailsToolCallsRetrievalObject( @SerialName(value = "type") @Required val type: RunStepDetailsToolCallsRetrievalObject.Type, /* For now, this is always going to be an empty object. */ - @SerialName(value = "retrieval") @Required val retrieval: kotlin.String + @SerialName(value = "retrieval") val retrieval: kotlinx.serialization.json.JsonObject? = null ) { /** diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObject.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObject.kt index b2fee36fa..7a3a06fac 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObject.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObject.kt @@ -60,11 +60,13 @@ data class RunStepObject( /* The status of the run step, which can be either `in_progress`, `cancelled`, `failed`, `completed`, or `expired`. */ @SerialName(value = "status") @Required val status: RunStepObject.Status, - @SerialName(value = "step_details") @Required val stepDetails: RunStepObjectStepDetails, + @SerialName(value = "step_details") + @Required + val stepDetails: com.xebia.functional.openai.models.ext.assistant.RunStepObjectStepDetails, @SerialName(value = "last_error") @Required val lastError: RunStepObjectLastError?, /* The Unix timestamp (in seconds) for when the run step expired. A step is considered expired if the parent run is expired. */ - @SerialName(value = "expired_at") @Required val expiredAt: kotlin.Int?, + @SerialName(value = "expired_at") val expiredAt: kotlin.Int? = null, /* The Unix timestamp (in seconds) for when the run step was cancelled. */ @SerialName(value = "cancelled_at") @Required val cancelledAt: kotlin.Int?, @@ -76,7 +78,7 @@ data class RunStepObject( @SerialName(value = "completed_at") @Required val completedAt: kotlin.Int?, /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") @Required val metadata: kotlin.String? + @SerialName(value = "metadata") val metadata: kotlinx.serialization.json.JsonObject? = null ) { /** diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObjectStepDetails.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObjectStepDetails.kt deleted file mode 100644 index ccfe8309d..000000000 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/RunStepObjectStepDetails.kt +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.models - -import kotlinx.serialization.* -import kotlinx.serialization.descriptors.* -import kotlinx.serialization.encoding.* - -/** - * The details of the run step. - * - * @param type Always `message_creation``. - * @param messageCreation - * @param toolCalls An array of tool calls the run step was involved in. These can be associated - * with one of three types of tools: `code_interpreter`, `retrieval`, or `function`. - */ -@Serializable -data class RunStepObjectStepDetails( - - /* Always `message_creation``. */ - @SerialName(value = "type") @Required val type: RunStepObjectStepDetails.Type, - @SerialName(value = "message_creation") - @Required - val messageCreation: RunStepDetailsMessageCreationObjectMessageCreation, - - /* An array of tool calls the run step was involved in. These can be associated with one of three types of tools: `code_interpreter`, `retrieval`, or `function`. */ - @SerialName(value = "tool_calls") - @Required - val toolCalls: kotlin.collections.List -) { - - /** - * Always `message_creation``. - * - * Values: message_creation,tool_calls - */ - @Serializable - enum class Type(val value: kotlin.String) { - @SerialName(value = "message_creation") message_creation("message_creation"), - @SerialName(value = "tool_calls") tool_calls("tool_calls") - } -} diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ThreadObject.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ThreadObject.kt index b45b23191..321c1a422 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ThreadObject.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ThreadObject.kt @@ -33,7 +33,7 @@ data class ThreadObject( @SerialName(value = "created_at") @Required val createdAt: kotlin.Int, /* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */ - @SerialName(value = "metadata") @Required val metadata: kotlin.String? + @SerialName(value = "metadata") @Required val metadata: kotlinx.serialization.json.JsonObject? ) { /** diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/assistant/AssistantTools.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/assistant/AssistantTools.kt new file mode 100644 index 000000000..febd55328 --- /dev/null +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/assistant/AssistantTools.kt @@ -0,0 +1,46 @@ +package com.xebia.functional.openai.models.ext.assistant + +import com.xebia.functional.openai.models.FunctionObject +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.* + +@Serializable(with = AssistantTools.MyTypeSerializer::class) +sealed interface AssistantTools { + + object MyTypeSerializer : + JsonContentPolymorphicSerializer(AssistantTools::class) { + override fun selectDeserializer(element: JsonElement): DeserializationStrategy = + when (element.jsonObject["type"]?.jsonPrimitive?.contentOrNull) { + AssistantToolsCode.Type.code_interpreter.value -> AssistantToolsCode.serializer() + AssistantToolsRetrieval.Type.retrieval.value -> AssistantToolsRetrieval.serializer() + else -> AssistantToolsFunction.serializer() + } + } +} + +@Serializable +data class AssistantToolsCode(val type: Type = Type.code_interpreter) : AssistantTools { + @Serializable + enum class Type(val value: String) { + @SerialName(value = "code_interpreter") code_interpreter("code_interpreter") + } +} + +@Serializable +data class AssistantToolsRetrieval(val type: Type = Type.retrieval) : AssistantTools { + @Serializable + enum class Type(val value: String) { + @SerialName(value = "retrieval") retrieval("retrieval") + } +} + +@Serializable +data class AssistantToolsFunction(val type: Type = Type.function, val function: FunctionObject) : + AssistantTools { + @Serializable + enum class Type(val value: String) { + @SerialName(value = "function") function("function") + } +} diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/assistant/RunStepObjectStepDetails.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/assistant/RunStepObjectStepDetails.kt new file mode 100644 index 000000000..c14eca707 --- /dev/null +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/assistant/RunStepObjectStepDetails.kt @@ -0,0 +1,68 @@ +package com.xebia.functional.openai.models.ext.assistant + +import com.xebia.functional.openai.models.RunStepDetailsMessageCreationObjectMessageCreation +import com.xebia.functional.openai.models.RunStepDetailsToolCallsObjectToolCallsInner +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.Required +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.* + +@Serializable(with = RunStepObjectStepDetails.MyTypeSerializer::class) +sealed interface RunStepObjectStepDetails { + + object MyTypeSerializer : + JsonContentPolymorphicSerializer(RunStepObjectStepDetails::class) { + override fun selectDeserializer( + element: JsonElement + ): DeserializationStrategy = + when (element.jsonObject["type"]?.jsonPrimitive?.contentOrNull) { + RunStepDetailsMessageCreationObject.Type.message_creation.value -> + RunStepDetailsMessageCreationObject.serializer() + else -> RunStepDetailsToolCallsObject.serializer() + } + } +} + +@Serializable +data class RunStepDetailsMessageCreationObject( + @SerialName(value = "message_creation") + @Required + val messageCreation: RunStepDetailsMessageCreationObjectMessageCreation, + /* Always `message_creation``. */ + @SerialName(value = "type") @Required val type: Type = Type.message_creation +) : RunStepObjectStepDetails { + + /** + * Always `message_creation``. + * + * Values: message_creation + */ + @Serializable + enum class Type(val value: String) { + @SerialName(value = "message_creation") message_creation("message_creation") + } +} + +@Serializable +data class RunStepDetailsToolCallsObject( + + /* An array of tool calls the run step was involved in. These can be associated with one of three types of tools: `code_interpreter`, `retrieval`, or `function`. */ + @SerialName(value = "tool_calls") + @Required + val toolCalls: List, + + /* Always `tool_calls`. */ + @SerialName(value = "type") @Required val type: Type = Type.tool_calls +) : RunStepObjectStepDetails { + + /** + * Always `tool_calls`. + * + * Values: tool_calls + */ + @Serializable + enum class Type(val value: String) { + @SerialName(value = "tool_calls") tool_calls("tool_calls") + } +} diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestMessage.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestMessage.kt index ac599e0c5..9735812b1 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestMessage.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestMessage.kt @@ -3,29 +3,28 @@ package com.xebia.functional.openai.models.ext.chat import com.xebia.functional.openai.models.ChatCompletionMessageToolCall import com.xebia.functional.openai.models.ChatCompletionRequestAssistantMessageFunctionCall import com.xebia.functional.openai.models.ChatCompletionRole +import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.Required import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonContentPolymorphicSerializer +import kotlinx.serialization.json.JsonElement -@Serializable +@Serializable(with = ChatCompletionRequestMessage.MyTypeSerializer::class) sealed interface ChatCompletionRequestMessage { - fun contentAsString(): String? = + fun contentAsString(): String = when (this) { - is ChatCompletionRequestAssistantMessage -> content - is ChatCompletionRequestFunctionMessage -> content - is ChatCompletionRequestSystemMessage -> content - is ChatCompletionRequestToolMessage -> content + is ChatCompletionRequestAssistantMessage -> content ?: "" + is ChatCompletionRequestFunctionMessage -> content ?: "" + is ChatCompletionRequestSystemMessage -> content ?: "" + is ChatCompletionRequestToolMessage -> content ?: "" is ChatCompletionRequestUserMessage -> - when (content) { - is ChatCompletionRequestUserMessageContent.ChatCompletionRequestUserMessageContentImageArray -> - // TODO - Image array to String? - null - is ChatCompletionRequestUserMessageContent.ChatCompletionRequestUserMessageContentTextArray -> - // TODO - String array to String? - null - is ChatCompletionRequestUserMessageContent.TextContent -> content.s - null -> null + content.joinToString { content -> + when (content) { + is ChatCompletionRequestUserMessageContentText -> content.text + is ChatCompletionRequestUserMessageContentImage -> content.imageUrl.url ?: "" + } } } @@ -71,7 +70,9 @@ sealed interface ChatCompletionRequestMessage { */ @Serializable data class ChatCompletionRequestUserMessage( - @SerialName(value = "content") @Required val content: ChatCompletionRequestUserMessageContent?, + @SerialName(value = "content") + @Required + val content: List, /* The role of the messages author, in this case `user`. */ @SerialName(value = "role") @Required val role: Role = Role.user @@ -187,4 +188,14 @@ sealed interface ChatCompletionRequestMessage { val asRole: ChatCompletionRole = ChatCompletionRole.function } } + + object MyTypeSerializer : + JsonContentPolymorphicSerializer( + ChatCompletionRequestMessage::class + ) { + override fun selectDeserializer( + element: JsonElement + ): DeserializationStrategy = + ChatCompletionRequestSystemMessage.serializer() + } } diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContent.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContent.kt index c103d9b20..2e6cfe555 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContent.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContent.kt @@ -1,23 +1,20 @@ package com.xebia.functional.openai.models.ext.chat -import kotlin.jvm.JvmInline +import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonContentPolymorphicSerializer +import kotlinx.serialization.json.JsonElement -@Serializable -sealed interface ChatCompletionRequestUserMessageContent { - @Serializable - @JvmInline - value class TextContent(val s: String) : ChatCompletionRequestUserMessageContent +@Serializable(with = ChatCompletionRequestUserMessageContent.MyTypeSerializer::class) +sealed class ChatCompletionRequestUserMessageContent { - @Serializable - @JvmInline - value class ChatCompletionRequestUserMessageContentTextArray( - val array: List - ) : ChatCompletionRequestUserMessageContent - - @Serializable - @JvmInline - value class ChatCompletionRequestUserMessageContentImageArray( - val array: List - ) : ChatCompletionRequestUserMessageContent + object MyTypeSerializer : + JsonContentPolymorphicSerializer( + ChatCompletionRequestUserMessageContent::class + ) { + override fun selectDeserializer( + element: JsonElement + ): DeserializationStrategy = + ChatCompletionRequestUserMessageContentText.serializer() + } } diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContentImage.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContentImage.kt index dc98128a5..aff90d7c9 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContentImage.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContentImage.kt @@ -10,7 +10,7 @@ data class ChatCompletionRequestUserMessageContentImage( @SerialName(value = "image_url") @Required val imageUrl: ChatCompletionRequestUserMessageContentImageUrl -) { +) : ChatCompletionRequestUserMessageContent() { @Serializable enum class Type(val value: String) { @SerialName(value = "image_url") imageUrl("image_url") diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContentText.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContentText.kt index 55a8814d3..dcec417d8 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContentText.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestUserMessageContentText.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable data class ChatCompletionRequestUserMessageContentText( @SerialName(value = "type") @Required val type: Type, @SerialName(value = "text") @Required val text: String -) { +) : ChatCompletionRequestUserMessageContent() { @Serializable enum class Type(val value: String) { @SerialName(value = "text") text("text") diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/create/CreateChatCompletionRequestStop.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/create/CreateChatCompletionRequestStop.kt index 81b7f7cba..838d924f6 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/create/CreateChatCompletionRequestStop.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/create/CreateChatCompletionRequestStop.kt @@ -1,13 +1,26 @@ package com.xebia.functional.openai.models.ext.chat.create import kotlin.jvm.JvmInline +import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonContentPolymorphicSerializer +import kotlinx.serialization.json.JsonElement -@Serializable +@Serializable(with = CreateChatCompletionRequestStop.MyTypeSerializer::class) sealed interface CreateChatCompletionRequestStop { @Serializable @JvmInline value class StringValue(val s: String) : CreateChatCompletionRequestStop @Serializable @JvmInline value class ArrayValue(val array: List) : CreateChatCompletionRequestStop + + object MyTypeSerializer : + JsonContentPolymorphicSerializer( + CreateChatCompletionRequestStop::class + ) { + override fun selectDeserializer( + element: JsonElement + ): DeserializationStrategy = + CreateChatCompletionRequestStop.StringValue.serializer() + } } diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/stream/ChatCompletionsStream.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/stream/ChatCompletionsStream.kt index 0b76212c9..52163642e 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/stream/ChatCompletionsStream.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/chat/stream/ChatCompletionsStream.kt @@ -1,9 +1,11 @@ package com.xebia.functional.openai.models.ext.chat.stream import com.xebia.functional.openai.apis.ChatApi +import com.xebia.functional.openai.infrastructure.ApiClient +import com.xebia.functional.openai.infrastructure.RequestConfig +import com.xebia.functional.openai.infrastructure.RequestMethod import com.xebia.functional.openai.models.CreateChatCompletionRequest import com.xebia.functional.openai.models.CreateChatCompletionStreamResponse -import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.request.* import io.ktor.client.statement.* @@ -12,29 +14,63 @@ import io.ktor.utils.io.* import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.FlowCollector import kotlinx.coroutines.flow.flow -import kotlinx.serialization.json.* fun ChatApi.createChatCompletionStream( request: CreateChatCompletionRequest ): Flow { - val builder = - HttpRequestBuilder().apply { - method = HttpMethod.Post - url(path = "/chat/completions") - setBody(streamingRequestAsJson(request)) + val localVariableAuthNames = listOf("ApiKeyAuth") + + val localVariableBody = request + + val localVariableQuery = mutableMapOf>() + val localVariableHeaders = mutableMapOf() + + val localVariableConfig = + RequestConfig( + RequestMethod.POST, + "/chat/completions", + query = localVariableQuery, + headers = localVariableHeaders, + requiresAuthentication = true, + ) + return flow { + val response = requestStreaming(localVariableConfig, localVariableBody, localVariableAuthNames) + emitDataEvents(response) + } +} + +private suspend fun ChatApi.requestStreaming( + requestConfig: RequestConfig, + body: Any? = null, + authNames: kotlin.collections.List +): HttpResponse { + requestConfig.updateForAuth(authNames) + val headers = requestConfig.headers + + return client.request { + this.url { contentType(ContentType.Application.Json) accept(ContentType.Text.EventStream) - headers { - append(HttpHeaders.CacheControl, "no-cache") - append(HttpHeaders.Connection, "keep-alive") + this.takeFrom(URLBuilder(baseUrl)) + appendPath(requestConfig.path.trimStart('/').split('/')) + requestConfig.query.forEach { query -> + query.value.forEach { value -> parameter(query.key, value) } } } - return flow { client.execute(builder) { response -> emitDataEvents(response) } } -} + this.method = requestConfig.method.httpMethod + headers + .filter { header -> !ApiClient.UNSAFE_HEADERS.contains(header.key) } + .forEach { header -> this.header(header.key, header.value) } -private val json = Json { - isLenient = true - ignoreUnknownKeys = true + header(HttpHeaders.CacheControl, "no-cache") + header(HttpHeaders.Connection, "keep-alive") + + if ( + requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH) + ) { + this.setBody(body) + } + } } private const val PREFIX = "data:" @@ -47,27 +83,10 @@ private suspend inline fun FlowCollector.emitDataEvents(response: val value: T = when { line.startsWith(END) -> break - line.startsWith(PREFIX) -> json.decodeFromString(line.removePrefix(PREFIX)) + line.startsWith(PREFIX) -> + ApiClient.JSON_DEFAULT.decodeFromString(line.removePrefix(PREFIX)) else -> continue } emit(value) } } - -private suspend fun HttpClient.execute( - builder: HttpRequestBuilder, - block: suspend (response: HttpResponse) -> T -) { - try { - HttpStatement(builder = builder, client = this).execute(block) - } catch (e: Exception) { - throw e // TODO handle exception - } -} - -private inline fun streamingRequestAsJson(serializable: T): JsonElement { - val enableStream = "stream" to JsonPrimitive(true) - val json = json.encodeToJsonElement(serializable) - val map = json.jsonObject.toMutableMap().also { it += enableStream } - return JsonObject(map) -} diff --git a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/embedding/create/CreateEmbeddingRequestInput.kt b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/embedding/create/CreateEmbeddingRequestInput.kt index c5c581999..1a391bc76 100644 --- a/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/embedding/create/CreateEmbeddingRequestInput.kt +++ b/openai-client/client/src/commonMain/kotlin/com/xebia/functional/openai/models/ext/embedding/create/CreateEmbeddingRequestInput.kt @@ -1,9 +1,12 @@ package com.xebia.functional.openai.models.ext.embedding.create import kotlin.jvm.JvmInline +import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonContentPolymorphicSerializer +import kotlinx.serialization.json.JsonElement -@Serializable +@Serializable(with = CreateEmbeddingRequestInput.MyTypeSerializer::class) sealed interface CreateEmbeddingRequestInput { @Serializable @JvmInline value class StringValue(val v: String) : CreateEmbeddingRequestInput @@ -19,4 +22,13 @@ sealed interface CreateEmbeddingRequestInput { @Serializable @JvmInline value class IntArrayArrayValue(val v: List>) : CreateEmbeddingRequestInput + + object MyTypeSerializer : + JsonContentPolymorphicSerializer( + CreateEmbeddingRequestInput::class + ) { + override fun selectDeserializer( + element: JsonElement + ): DeserializationStrategy = StringValue.serializer() + } } diff --git a/openai-client/client/src/jvmMain/resources/logback.xml b/openai-client/client/src/jvmMain/resources/logback.xml new file mode 100644 index 000000000..55e3ecdc9 --- /dev/null +++ b/openai-client/client/src/jvmMain/resources/logback.xml @@ -0,0 +1,15 @@ + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%kvp- %msg%n + + + + + + + + diff --git a/openai-client/generator/build.gradle.kts b/openai-client/generator/build.gradle.kts index 68e0782da..fa8c1279d 100644 --- a/openai-client/generator/build.gradle.kts +++ b/openai-client/generator/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } dependencies { - implementation("org.openapitools:openapi-generator-cli:7.0.1") + implementation("org.openapitools:openapi-generator-cli:7.1.0") } tasks.test { @@ -35,4 +35,4 @@ task("openaiClientGenerate", JavaExec::class) { "config/openai-config.json", ) classpath = sourceSets["main"].runtimeClasspath -}.finalizedBy(":xef-openai-client:spotlessApply") \ No newline at end of file +}.finalizedBy(":xef-openai-client:spotlessApply") diff --git a/openai-client/generator/config/libraries/multiplatform/infrastructure/ApiClient.kt.mustache b/openai-client/generator/config/libraries/multiplatform/infrastructure/ApiClient.kt.mustache index 4b89dd1c9..6dd47d0c8 100644 --- a/openai-client/generator/config/libraries/multiplatform/infrastructure/ApiClient.kt.mustache +++ b/openai-client/generator/config/libraries/multiplatform/infrastructure/ApiClient.kt.mustache @@ -19,7 +19,7 @@ import kotlinx.serialization.json.Json import {{packageName}}.auth.* {{#nonPublicApi}}internal {{/nonPublicApi}}open class ApiClient( - private val baseUrl: String + val baseUrl: String ) { lateinit var client: HttpClient @@ -67,7 +67,7 @@ import {{packageName}}.auth.* prettyPrint = true isLenient = true } - protected val UNSAFE_HEADERS = listOf(HttpHeaders.ContentType) + val UNSAFE_HEADERS = listOf(HttpHeaders.ContentType) } /** @@ -154,6 +154,7 @@ import {{packageName}}.auth.* return client.request { this.url { + contentType(ContentType.Application.Json) this.takeFrom(URLBuilder(baseUrl)) appendPath(requestConfig.path.trimStart('/').split('/')) requestConfig.query.forEach { query -> @@ -162,6 +163,7 @@ import {{packageName}}.auth.* } } } + this.header("OpenAI-Beta", "assistants=v1") this.method = requestConfig.method.httpMethod headers.filter { header -> !UNSAFE_HEADERS.contains(header.key) }.forEach { header -> this.header(header.key, header.value) } if (requestConfig.method in listOf(RequestMethod.PUT, RequestMethod.POST, RequestMethod.PATCH)) { @@ -170,18 +172,18 @@ import {{packageName}}.auth.* } } - private fun RequestConfig.updateForAuth(authNames: kotlin.collections.List) { + fun RequestConfig.updateForAuth(authNames: kotlin.collections.List) { for (authName in authNames) { val auth = authentications?.get(authName) ?: throw Exception("Authentication undefined: $authName") auth.apply(query, headers) } } - private fun URLBuilder.appendPath(components: kotlin.collections.List): URLBuilder = apply { + fun URLBuilder.appendPath(components: kotlin.collections.List): URLBuilder = apply { encodedPath = encodedPath.trimEnd('/') + components.joinToString("/", prefix = "/") { it.encodeURLQueryComponent() } } - private val RequestMethod.httpMethod: HttpMethod + val RequestMethod.httpMethod: HttpMethod get() = when (this) { RequestMethod.DELETE -> HttpMethod.Delete RequestMethod.GET -> HttpMethod.Get diff --git a/openai-client/generator/config/libraries/multiplatform/infrastructure/HttpResponse.kt.mustache b/openai-client/generator/config/libraries/multiplatform/infrastructure/HttpResponse.kt.mustache new file mode 100644 index 000000000..0c5c87149 --- /dev/null +++ b/openai-client/generator/config/libraries/multiplatform/infrastructure/HttpResponse.kt.mustache @@ -0,0 +1,54 @@ +package {{packageName}}.infrastructure + +import io.ktor.http.Headers +import io.ktor.http.isSuccess +import io.ktor.util.reflect.TypeInfo +import io.ktor.util.reflect.typeInfo + +{{#nonPublicApi}}internal {{/nonPublicApi}}open class HttpResponse(val response: io.ktor.client.statement.HttpResponse, val provider: BodyProvider) { + val status: Int = response.status.value + val success: Boolean = response.status.isSuccess() + val headers: Map> = response.headers.mapEntries() + suspend fun body(): T = provider.body(response) + suspend fun typedBody(type: TypeInfo): V = provider.typedBody(response, type) + + {{#nonPublicApi}}internal {{/nonPublicApi}}companion object { + private fun Headers.mapEntries(): Map> { + val result = mutableMapOf>() + entries().forEach { result[it.key] = it.value } + return result + } + } +} + +{{#nonPublicApi}}internal {{/nonPublicApi}}interface BodyProvider { + suspend fun body(response: io.ktor.client.statement.HttpResponse): T + suspend fun typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V +} + +{{#nonPublicApi}}internal {{/nonPublicApi}}class TypedBodyProvider(private val type: TypeInfo) : BodyProvider { + @Suppress("UNCHECKED_CAST") + override suspend fun body(response: io.ktor.client.statement.HttpResponse): T { + if (!response.status.isSuccess()) + error("${response.status.value}:${response.status.description}") + return response.call.body(type) as T + } + + @Suppress("UNCHECKED_CAST") + override suspend fun typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V = + response.call.body(type) as V +} + +{{#nonPublicApi}}internal {{/nonPublicApi}}class MappedBodyProvider(private val provider: BodyProvider, private val block: S.() -> T) : BodyProvider { + override suspend fun body(response: io.ktor.client.statement.HttpResponse): T = + block(provider.body(response)) + + override suspend fun typedBody(response: io.ktor.client.statement.HttpResponse, type: TypeInfo): V = + provider.typedBody(response, type) +} + +{{#nonPublicApi}}internal {{/nonPublicApi}}inline fun io.ktor.client.statement.HttpResponse.wrap(): HttpResponse = + HttpResponse(this, TypedBodyProvider(typeInfo())) + +{{#nonPublicApi}}internal {{/nonPublicApi}}fun HttpResponse.map(block: T.() -> V): HttpResponse = + HttpResponse(response, MappedBodyProvider(provider, block)) diff --git a/openai-client/generator/config/openai-api-commit b/openai-client/generator/config/openai-api-commit index 1360b8ffa..024053509 100644 --- a/openai-client/generator/config/openai-api-commit +++ b/openai-client/generator/config/openai-api-commit @@ -1 +1 @@ -5c1857ea865e74e45e3b12064e0cc2396ef64be1 \ No newline at end of file +a7a0b63d1fac3acac9a223d57da1219c8a97c01e \ No newline at end of file diff --git a/openai-client/generator/config/openai-config.json b/openai-client/generator/config/openai-config.json index 7dc5e5b7d..fceb11c92 100644 --- a/openai-client/generator/config/openai-config.json +++ b/openai-client/generator/config/openai-config.json @@ -6,7 +6,14 @@ "packageName": "com.xebia.functional.openai", "removeEnumValuePrefix": false }, + "typeMappings": { + "object": "JsonObject" + }, + "importMappings": { + "JsonObject": "kotlinx.serialization.json.JsonObject" + }, "schemaMappings": { + "AssistantObject_tools_inner": "com.xebia.functional.openai.models.ext.assistant.AssistantTools", "FunctionParameters": "kotlinx.serialization.json.JsonObject", "ChatCompletionRequestMessage": "com.xebia.functional.openai.models.ext.chat.ChatCompletionRequestMessage", "ChatCompletionRequestUserMessage_content": "com.xebia.functional.openai.models.ext.chat.ChatCompletionRequestUserMessageContent", @@ -20,7 +27,8 @@ "CreateFineTuningJobRequest_hyperparameters_n_epochs": "com.xebia.functional.openai.models.ext.finetune.job.create.CreateFineTuningJobRequestHyperparametersNEpochs", "CreateModerationRequest_input": "com.xebia.functional.openai.models.ext.moderation.create.CreateModerationRequestInput", "FineTuningJobRequest_hyperparameters_n_epochs": "com.xebia.functional.openai.models.ext.finetune.job.FineTuningJobRequestHyperparametersNEpochs", - "FineTuningJob_hyperparameters_n_epochs": "com.xebia.functional.openai.models.ext.finetune.job.FineTuningJobHyperparametersNEpochs" + "FineTuningJob_hyperparameters_n_epochs": "com.xebia.functional.openai.models.ext.finetune.job.FineTuningJobHyperparametersNEpochs", + "RunStepObject_step_details": "com.xebia.functional.openai.models.ext.assistant.RunStepObjectStepDetails" }, "templateDir": "config", "files": { @@ -32,6 +40,11 @@ "folder": "src/commonMain/kotlin/com/xebia/functional/openai/infrastructure", "destinationFilename": "ApiClient.kt", "templateType": "SupportingFiles" + }, + "infrastructure/HttpResponse.kt.mustache": { + "folder": "src/commonMain/kotlin/com/xebia/functional/openai/infrastructure", + "destinationFilename": "HttpResponse.kt", + "templateType": "SupportingFiles" } } } diff --git a/openai-client/generator/src/main/java/ai/xef/openai/generator/KMMGeneratorConfig.java b/openai-client/generator/src/main/java/ai/xef/openai/generator/KMMGeneratorConfig.java index 8ec6a09dd..424c70ed2 100644 --- a/openai-client/generator/src/main/java/ai/xef/openai/generator/KMMGeneratorConfig.java +++ b/openai-client/generator/src/main/java/ai/xef/openai/generator/KMMGeneratorConfig.java @@ -7,17 +7,38 @@ import org.openapitools.codegen.model.ModelMap; import org.openapitools.codegen.model.ModelsMap; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; +import java.util.*; +import static java.util.Map.entry; public class KMMGeneratorConfig extends KotlinClientCodegen { + private final Map> nonRequiredFields = new LinkedHashMap<>(); + public KMMGeneratorConfig() { super(); specialCharReplacements.put("-", "_"); specialCharReplacements.put(".", "_"); enumPropertyNaming = CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.snake_case; + nonRequiredFields.putAll( + Map.ofEntries( + entry("ListAssistantFilesResponse", List.of("firstId", "lastId")), + entry("ListAssistantsResponse", List.of("firstId", "lastId")), + entry("ListMessageFilesResponse", List.of("firstId", "lastId")), + entry("ListMessagesResponse", List.of("firstId", "lastId")), + entry("ListRunsResponse", List.of("firstId", "lastId")), + entry("ListRunStepsResponse", List.of("firstId", "lastId")), + entry("ListThreadsResponse", List.of("firstId", "lastId")), + entry("MessageObject", List.of("metadata")), + entry("MessageObjectContentInner", List.of("imageFile", "text")), + entry("RunObject", List.of("expiresAt", "requiredAction")), + entry("RunStepDetailsToolCallsCodeObjectCodeInterpreterOutputsInner", List.of("logs", "image")), + entry("RunStepDetailsToolCallsFunctionObjectFunction", List.of("output")), + entry("RunStepDetailsToolCallsObjectToolCallsInner", List.of("codeInterpreter", "retrieval", "function")), + entry("RunStepDetailsToolCallsRetrievalObject", List.of("retrieval")), + entry("RunStepObject", List.of("expiredAt", "metadata")), + entry("RunStepObjectStepDetails", List.of("messageCreation", "toolCalls")) + ) + ); } private Optional readEnumModel(List all) { @@ -56,6 +77,13 @@ public ModelsMap postProcessModels(ModelsMap objs) { .findFirst() .filter(p -> !p.dataType.equals("kotlin.String")) .ifPresent(p -> p.dataType = String.format("ai.xef.openai.OpenAIModel<%s>", p.dataType)); + } else if (nonRequiredFields.containsKey(cm.classname)) { + List fields = nonRequiredFields.getOrDefault(cm.classname, Collections.emptyList()); + cm + .allVars + .stream() + .filter(p -> fields.contains(p.name)) + .forEach(p -> p.setRequired(false)); } } return super.postProcessModels(objs);