Skip to content

Commit

Permalink
Update gen models (#559)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fedefernandez authored Nov 24, 2023
1 parent 3cd9754 commit 0db20cf
Show file tree
Hide file tree
Showing 57 changed files with 447 additions and 443 deletions.
8 changes: 7 additions & 1 deletion openai-client/client/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
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
7 changes: 0 additions & 7 deletions openai-client/client/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion openai-client/client/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.1
7.1.0
2 changes: 2 additions & 0 deletions openai-client/client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}

/**
Expand Down Expand Up @@ -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) }
Expand All @@ -183,24 +185,21 @@ open class ApiClient(private val baseUrl: String) {
}
}

private fun <T : Any?> RequestConfig<T>.updateForAuth(
authNames: kotlin.collections.List<String>
) {
fun <T : Any?> RequestConfig<T>.updateForAuth(authNames: kotlin.collections.List<String>) {
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<String>): URLBuilder =
apply {
encodedPath =
encodedPath.trimEnd('/') +
components.joinToString("/", prefix = "/") { it.encodeURLQueryComponent() }
}
fun URLBuilder.appendPath(components: kotlin.collections.List<String>): 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ interface BodyProvider<T : Any> {

class TypedBodyProvider<T : Any>(private val type: TypeInfo) : BodyProvider<T> {
@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 <V : Any> typedBody(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ 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<AssistantObjectToolsInner> = arrayListOf(),
val tools:
kotlin.collections.List<com.xebia.functional.openai.models.ext.assistant.AssistantTools> =
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")
@Required
val fileIds: kotlin.collections.List<kotlin.String> = 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?
) {

/**
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<AssistantObjectToolsInner>? = arrayListOf(),
val tools:
kotlin.collections.List<com.xebia.functional.openai.models.ext.assistant.AssistantTools>? =
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<kotlin.String>? = 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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data class CreateMessageRequest(
val fileIds: kotlin.collections.List<kotlin.String>? = 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
) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AssistantObjectToolsInner>? = null,
val tools:
kotlin.collections.List<com.xebia.functional.openai.models.ext.assistant.AssistantTools>? =
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
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ data class CreateThreadAndRunRequest(
val tools: kotlin.collections.List<CreateThreadAndRunRequestToolsInner>? = 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
)
Loading

0 comments on commit 0db20cf

Please sign in to comment.