diff --git a/.github/workflows/setup-gradle.yml b/.github/workflows/setup-gradle.yml new file mode 100644 index 00000000..0b8a92bb --- /dev/null +++ b/.github/workflows/setup-gradle.yml @@ -0,0 +1,20 @@ +name: Build + +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 17 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Build with Gradle + run: ./gradlew build diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ad3263ce --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ + +.gradle/ +.idea/ +lib/build/ + +.DS_Store +local.properties diff --git a/README.md b/README.md index 40a96832..77a69929 100644 --- a/README.md +++ b/README.md @@ -32,22 +32,29 @@ I prefer to save a snapshot of the specification that was used for the generatio ## Generate Whole OpenAI API 1. `time openapi-generator generate -i openapi.yaml -g kotlin -o ./lib --skip-validate-spec --additional-properties=artifactId=openai-kotlin-client,artifactVersion=0.0.1,groupId=com.openai,packageName=com.openai` (< 5 seconds on MacBook Pro M4 Pro) -... -2. cd ./lib -3. `chmod +x ./gradlew` -4. `./gradlew build` -(< 20 seconds on MacBook Pro M4 Pro to successfully compile) +2. `cp lib/build.gradle .` +3. `mv lib/gradle* lib/settings.gradle .` +4. `echo -e "\ninclude(\":lib\")" >> settings.gradle` +5. Edit `build.gradle` to be a project file and `lib/build.gradle` to be a module file. +6. `chmod +x ./gradlew` +7. `./gradlew build` +(< 20 seconds on MacBook Pro M4 Pro to [eventually; see "Changes"] successfully compile from clean) All of this is also shown in the `openai-kotlin-client.sh` file. ## Changes At this point, the build will actually fail. -I had to make a few changes in order to get it to compile. +I had to make some manual changes in order to get it to compile successfully: 1. AudioApi.kt: 1. change `AudioResponseFormat? = json` to `AudioResponseFormat? = AudioResponseFormat.json` 2. change `timestampGranularities?.value` to `timestampGranularities` -2. replace a couple of `data class Foo() {}` with `class Foo` +2. remove `data` (`data class ...`->`class ...`) in: + 1. CreateAssistantRequestToolResourcesFileSearch.kt + 2. CreateThreadRequestToolResourcesFileSearch.kt + +This just got it to **COMPILE** successfully! + +I had to make further changes in order to get it to **RUN** successfully. -I had to make further changes in order to get it to run correctly. All of my changes can be seen at: https://github.com/swooby/openai-openapi-kotlin/pull/1/files diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..6b1823d8 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +org.gradle.daemon=false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..edd5a183 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,14 @@ +[versions] +kotlin = "2.0.21" +kotlintestRunnerJunit5 = "3.4.2" +squareupMoshiKotlin = "1.15.1" +squareupOkhttpBom = "4.12.0" + +[libraries] +kotlintest-runner-junit5 = { module = "io.kotlintest:kotlintest-runner-junit5", version.ref = "kotlintestRunnerJunit5" } +squareup-moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "squareupMoshiKotlin" } +squareup-okhttp3-bom = { module = "com.squareup.okhttp3:okhttp-bom", version.ref = "squareupOkhttpBom" } +squareup-okhttp3 = { module = "com.squareup.okhttp3:okhttp" } + +[plugins] +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/lib/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from lib/gradle/wrapper/gradle-wrapper.jar rename to gradle/wrapper/gradle-wrapper.jar diff --git a/lib/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties similarity index 74% rename from lib/gradle/wrapper/gradle-wrapper.properties rename to gradle/wrapper/gradle-wrapper.properties index e7646dea..6059a5fa 100644 --- a/lib/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ +#Sun Dec 15 17:37:56 PST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip -networkTimeout=10000 -validateDistributionUrl=true +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/lib/gradlew b/gradlew old mode 100644 new mode 100755 similarity index 100% rename from lib/gradlew rename to gradlew diff --git a/lib/gradlew.bat b/gradlew.bat similarity index 100% rename from lib/gradlew.bat rename to gradlew.bat diff --git a/lib/build.gradle b/lib/build.gradle deleted file mode 100644 index 01dbcc67..00000000 --- a/lib/build.gradle +++ /dev/null @@ -1,62 +0,0 @@ -group 'com.openai' -version '0.0.1' - -wrapper { - gradleVersion = '8.7' - distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" -} - -buildscript { - ext.kotlin_version = '1.9.23' - ext.spotless_version = "6.25.0" - - repositories { - maven { url "https://repo1.maven.org/maven2" } - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotless_version" - } -} - -apply plugin: 'kotlin' -apply plugin: 'maven-publish' -apply plugin: 'com.diffplug.spotless' - -repositories { - maven { url "https://repo1.maven.org/maven2" } -} - -// Use spotless plugin to automatically format code, remove unused import, etc -// To apply changes directly to the file, run `gradlew spotlessApply` -// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle -spotless { - // comment out below to run spotless as part of the `check` task - enforceCheck false - - format 'misc', { - // define the files (e.g. '*.gradle', '*.md') to apply `misc` to - target '.gitignore' - - // define the steps to apply to those files - trimTrailingWhitespace() - indentWithSpaces() // Takes an integer argument if you don't like 4 - endWithNewline() - } - kotlin { - ktfmt() - } -} - -test { - useJUnitPlatform() -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - implementation "com.squareup.moshi:moshi-kotlin:1.15.1" - implementation "com.squareup.moshi:moshi-adapters:1.15.1" - implementation "com.squareup.okhttp3:okhttp:4.12.0" - testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2" -} diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts new file mode 100644 index 00000000..ffeb7481 --- /dev/null +++ b/lib/build.gradle.kts @@ -0,0 +1,32 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask + +plugins { + alias(libs.plugins.kotlin.jvm) + // id("maven-publish") +} + +group = "com.openai" +version = "0.0.1" + +tasks.test { + useJUnitPlatform() +} + +tasks.named>("compileTestKotlin").configure { + compilerOptions { + suppressWarnings = true + } +} + +tasks.named>("compileKotlin").configure { + compilerOptions { + suppressWarnings = true + } +} + +dependencies { + implementation(libs.squareup.moshi.kotlin) + implementation(platform(libs.squareup.okhttp3.bom)) + implementation(libs.squareup.okhttp3) + testImplementation(libs.kotlintest.runner.junit5) +} diff --git a/lib/settings.gradle b/lib/settings.gradle deleted file mode 100644 index 7702be7e..00000000 --- a/lib/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'openai-kotlin-client' diff --git a/lib/src/main/kotlin/com/openai/apis/AudioApi.kt b/lib/src/main/kotlin/com/openai/apis/AudioApi.kt index f85ad030..c1aa5e29 100644 --- a/lib/src/main/kotlin/com/openai/apis/AudioApi.kt +++ b/lib/src/main/kotlin/com/openai/apis/AudioApi.kt @@ -157,7 +157,7 @@ class AudioApi(basePath: kotlin.String = defaultBasePath, client: Call.Factory = */ @Suppress("UNCHECKED_CAST") @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) - fun createTranscription(file: java.io.File, model: CreateTranscriptionRequestModel, language: kotlin.String? = null, prompt: kotlin.String? = null, responseFormat: AudioResponseFormat? = json, temperature: java.math.BigDecimal? = java.math.BigDecimal("0"), timestampGranularities: kotlin.collections.List? = null) : CreateTranscription200Response { + fun createTranscription(file: java.io.File, model: CreateTranscriptionRequestModel, language: kotlin.String? = null, prompt: kotlin.String? = null, responseFormat: AudioResponseFormat? = AudioResponseFormat.json, temperature: java.math.BigDecimal? = java.math.BigDecimal("0"), timestampGranularities: kotlin.collections.List? = null) : CreateTranscription200Response { val localVarResponse = createTranscriptionWithHttpInfo(file = file, model = model, language = language, prompt = prompt, responseFormat = responseFormat, temperature = temperature, timestampGranularities = timestampGranularities) return when (localVarResponse.responseType) { @@ -219,7 +219,7 @@ class AudioApi(basePath: kotlin.String = defaultBasePath, client: Call.Factory = "prompt" to PartConfig(body = prompt, headers = mutableMapOf()), "response_format" to PartConfig(body = responseFormat, headers = mutableMapOf()), "temperature" to PartConfig(body = temperature, headers = mutableMapOf()), - "timestamp_granularities[]" to PartConfig(body = timestampGranularities?.value, headers = mutableMapOf()),) + "timestamp_granularities[]" to PartConfig(body = timestampGranularities, headers = mutableMapOf()),) val localVariableQuery: MultiValueMap = mutableMapOf() val localVariableHeaders: MutableMap = mutableMapOf("Content-Type" to "multipart/form-data") localVariableHeaders["Accept"] = "application/json" @@ -251,7 +251,7 @@ class AudioApi(basePath: kotlin.String = defaultBasePath, client: Call.Factory = */ @Suppress("UNCHECKED_CAST") @Throws(IllegalStateException::class, IOException::class, UnsupportedOperationException::class, ClientException::class, ServerException::class) - fun createTranslation(file: java.io.File, model: CreateTranscriptionRequestModel, prompt: kotlin.String? = null, responseFormat: AudioResponseFormat? = json, temperature: java.math.BigDecimal? = java.math.BigDecimal("0")) : CreateTranslation200Response { + fun createTranslation(file: java.io.File, model: CreateTranscriptionRequestModel, prompt: kotlin.String? = null, responseFormat: AudioResponseFormat? = AudioResponseFormat.json, temperature: java.math.BigDecimal? = java.math.BigDecimal("0")) : CreateTranslation200Response { val localVarResponse = createTranslationWithHttpInfo(file = file, model = model, prompt = prompt, responseFormat = responseFormat, temperature = temperature) return when (localVarResponse.responseType) { diff --git a/lib/src/main/kotlin/com/openai/infrastructure/ApiClient.kt b/lib/src/main/kotlin/com/openai/infrastructure/ApiClient.kt index 32f15d7d..46c8f925 100644 --- a/lib/src/main/kotlin/com/openai/infrastructure/ApiClient.kt +++ b/lib/src/main/kotlin/com/openai/infrastructure/ApiClient.kt @@ -33,14 +33,16 @@ val EMPTY_REQUEST: RequestBody = ByteArray(0).toRequestBody() open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClient) { companion object { - protected const val ContentType: String = "Content-Type" - protected const val Accept: String = "Accept" - protected const val Authorization: String = "Authorization" - protected const val JsonMediaType: String = "application/json" - protected const val FormDataMediaType: String = "multipart/form-data" - protected const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" - protected const val XmlMediaType: String = "application/xml" - protected const val OctetMediaType: String = "application/octet-stream" + const val ContentType: String = "Content-Type" + const val Accept: String = "Accept" + const val Authorization: String = "Authorization" + const val JsonMediaType: String = "application/json" + const val SdpMediaType: String = "application/sdp" + const val TextPlainMediaType: String = "text/plain" + const val FormDataMediaType: String = "multipart/form-data" + const val FormUrlEncMediaType: String = "application/x-www-form-urlencoded" + const val XmlMediaType: String = "application/xml" + const val OctetMediaType: String = "application/octet-stream" val apiKey: MutableMap = mutableMapOf() val apiKeyPrefix: MutableMap = mutableMapOf() @@ -64,7 +66,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie * @param byteArray The given file * @return The guessed Content-Type */ - protected fun guessContentTypeFromByteArray(byteArray: ByteArray): String { + fun guessContentTypeFromByteArray(byteArray: ByteArray): String { val contentType = try { URLConnection.guessContentTypeFromStream(byteArray.inputStream()) } catch (io: IOException) { @@ -79,12 +81,12 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie * @param file The given file * @return The guessed Content-Type */ - protected fun guessContentTypeFromFile(file: File): String { + fun guessContentTypeFromFile(file: File): String { val contentType = URLConnection.guessContentTypeFromName(file.name) return contentType ?: "application/octet-stream" } - protected inline fun requestBody(content: T, mediaType: String?): RequestBody = + inline fun requestBody(content: T, mediaType: String?): RequestBody = when { content is ByteArray -> content.toRequestBody((mediaType ?: guessContentTypeFromByteArray(content)).toMediaTypeOrNull()) content is File -> content.asRequestBody((mediaType ?: guessContentTypeFromFile(content)).toMediaTypeOrNull()) @@ -126,18 +128,21 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (content == null) { EMPTY_REQUEST } else { - Serializer.moshi.adapter(T::class.java).toJson(content) + Serializer.serialize(content) .toRequestBody((mediaType ?: JsonMediaType).toMediaTypeOrNull()) } + mediaType.startsWith("application/") && mediaType.endsWith("sdp") -> + content?.toString()?.toByteArray()?.toRequestBody(mediaType.toMediaTypeOrNull()) + ?: EMPTY_REQUEST mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.") mediaType == OctetMediaType && content is ByteArray -> content.toRequestBody(OctetMediaType.toMediaTypeOrNull()) // TODO: this should be extended with other serializers - else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, byte body and File body.") + else -> throw UnsupportedOperationException("requestBody currently only supports JSON body, SDP body, byte body, and File body.") } @OptIn(ExperimentalStdlibApi::class) - protected inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { + inline fun responseBody(response: Response, mediaType: String? = JsonMediaType): T? { val body = response.body if(body == null) { return null @@ -201,14 +206,15 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie if (bodyContent.isEmpty()) { return null } - Serializer.moshi.adapter().fromJson(bodyContent) + Serializer.deserialize(bodyContent) } + mediaType.startsWith("text/") && mediaType.endsWith("plain") -> body.string() as T mediaType == OctetMediaType -> body.bytes() as? T - else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.") + else -> throw UnsupportedOperationException("responseBody currently only supports JSON body, byte body, and text body.") } } - protected fun updateAuthParams(requestConfig: RequestConfig) { + fun updateAuthParams(requestConfig: RequestConfig) { if (requestConfig.headers[Authorization].isNullOrEmpty()) { accessToken?.let { accessToken -> requestConfig.headers[Authorization] = "Bearer $accessToken" @@ -216,7 +222,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } - protected inline fun request(requestConfig: RequestConfig): ApiResponse { + inline fun request(requestConfig: RequestConfig): ApiResponse { val httpUrl = baseUrl.toHttpUrlOrNull() ?: throw IllegalStateException("baseUrl is invalid.") // take authMethod from operation @@ -302,7 +308,7 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie } } - protected fun parameterToString(value: Any?): String = when (value) { + fun parameterToString(value: Any?): String = when (value) { null -> "" is Array<*> -> toMultiValue(value, "csv").toString() is Iterable<*> -> toMultiValue(value, "csv").toString() diff --git a/lib/src/main/kotlin/com/openai/infrastructure/BigDecimalAdapter.kt b/lib/src/main/kotlin/com/openai/infrastructure/BigDecimalAdapter.kt index 20ed2835..a4232525 100644 --- a/lib/src/main/kotlin/com/openai/infrastructure/BigDecimalAdapter.kt +++ b/lib/src/main/kotlin/com/openai/infrastructure/BigDecimalAdapter.kt @@ -4,11 +4,50 @@ import com.squareup.moshi.FromJson import com.squareup.moshi.ToJson import java.math.BigDecimal +/** + * This Adapter was obviously added because... + * ``` + * Platform class java.math.BigDecimal requires explicit JsonAdapter to be registered + * ``` + * + * However, the original `fun toJson(value: BigDecimal): String` implementation + * returns a number as a string that gets serialized with quotes, + * which OpenAI complains about: + * ``` + * --> POST https://api.openai.com/v1/realtime/sessions + * Content-Length: 720 + * Content-Type: application/json + * Accept: application/json + * ... + * {...,"temperature":"0.800000011920928955078125"} + * --> END POST (720-byte body) + * <-- 400 https://api.openai.com/v1/realtime/sessions (470ms) + * ... + * { + * "error": { + * "message": "Invalid type for 'temperature': expected a decimal, but got a string instead.", + * "type": "invalid_request_error", + * "param": "temperature", + * "code": "invalid_type" + * } + * } + * <-- END HTTP (208-byte body) + * ``` + * + * Changing this to return Double causes OpenAI to stop complaining. + */ class BigDecimalAdapter { + /* @ToJson fun toJson(value: BigDecimal): String { return value.toPlainString() } + */ + + @ToJson + fun toJson(value: BigDecimal): Double { + return value.toDouble() + } @FromJson fun fromJson(value: String): BigDecimal { diff --git a/lib/src/main/kotlin/com/openai/infrastructure/BigIntegerAdapter.kt b/lib/src/main/kotlin/com/openai/infrastructure/BigIntegerAdapter.kt index 12dcf1cc..59a22c78 100644 --- a/lib/src/main/kotlin/com/openai/infrastructure/BigIntegerAdapter.kt +++ b/lib/src/main/kotlin/com/openai/infrastructure/BigIntegerAdapter.kt @@ -4,11 +4,50 @@ import com.squareup.moshi.FromJson import com.squareup.moshi.ToJson import java.math.BigInteger +/** + * This Adapter was obviously added because... + * ``` + * Platform class java.math.BigDecimal requires explicit JsonAdapter to be registered + * ``` + * + * However, the original `fun toJson(value: BigDecimal): String` implementation + * returns a number as a string that gets serialized with quotes, + * which OpenAI complains about: + * ``` + * --> POST https://api.openai.com/v1/realtime/sessions + * Content-Length: 720 + * Content-Type: application/json + * Accept: application/json + * ... + * {...,"temperature":"0.800000011920928955078125"} + * --> END POST (720-byte body) + * <-- 400 https://api.openai.com/v1/realtime/sessions (470ms) + * ... + * { + * "error": { + * "message": "Invalid type for 'temperature': expected a decimal, but got a string instead.", + * "type": "invalid_request_error", + * "param": "temperature", + * "code": "invalid_type" + * } + * } + * <-- END HTTP (208-byte body) + * ``` + * + * Changing this to return Int causes OpenAI to stop complaining. + */ class BigIntegerAdapter { + /* @ToJson fun toJson(value: BigInteger): String { return value.toString() } + */ + + @ToJson + fun toJson(value: BigInteger): Int { + return value.toInt() + } @FromJson fun fromJson(value: String): BigInteger { diff --git a/lib/src/main/kotlin/com/openai/infrastructure/Serializer.kt b/lib/src/main/kotlin/com/openai/infrastructure/Serializer.kt index e3df064c..2d2a2e65 100644 --- a/lib/src/main/kotlin/com/openai/infrastructure/Serializer.kt +++ b/lib/src/main/kotlin/com/openai/infrastructure/Serializer.kt @@ -1,17 +1,72 @@ package com.openai.infrastructure +import com.openai.models.RealtimeSessionMaxResponseOutputTokensAdapter +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonQualifier +import com.squareup.moshi.JsonReader +import com.squareup.moshi.JsonWriter import com.squareup.moshi.Moshi +import com.squareup.moshi.Types +import com.squareup.moshi.adapter import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory +import java.lang.reflect.Type + +// +//region SerializeNull https://stackoverflow.com/a/71877976/252308 +// + +@Retention(AnnotationRetention.RUNTIME) +@JsonQualifier +annotation class SerializeNull { + companion object { + class Factory : JsonAdapter.Factory { + override fun create(type: Type, annotations: MutableSet, moshi: Moshi): JsonAdapter<*>? { + val nextAnnotations = Types.nextAnnotations(annotations, SerializeNull::class.java) + return if (nextAnnotations == null) { + null + } else { + NullIfNullJsonAdapter(moshi.nextAdapter(this, type, nextAnnotations)) + } + } + } + + class NullIfNullJsonAdapter(private val delegate: JsonAdapter) : JsonAdapter() { + override fun fromJson(reader: JsonReader): T? { + return delegate.fromJson(reader) + } + + override fun toJson(writer: JsonWriter, value: T?) { + if (value == null) { + val serializeNulls: Boolean = writer.serializeNulls + writer.serializeNulls = true + try { + delegate.toJson(writer, value) + } finally { + writer.serializeNulls = serializeNulls + } + } else { + delegate.toJson(writer, value) + } + } + } + } +} + +// +//endregion +// object Serializer { @JvmStatic val moshiBuilder: Moshi.Builder = Moshi.Builder() + .add(SerializeNull.Companion.Factory()) .add(OffsetDateTimeAdapter()) .add(LocalDateTimeAdapter()) .add(LocalDateAdapter()) .add(UUIDAdapter()) .add(ByteArrayAdapter()) .add(URIAdapter()) + .add(RealtimeSessionMaxResponseOutputTokensAdapter()) .add(KotlinJsonAdapterFactory()) .add(BigDecimalAdapter()) .add(BigIntegerAdapter()) @@ -20,4 +75,14 @@ object Serializer { val moshi: Moshi by lazy { moshiBuilder.build() } + + @OptIn(ExperimentalStdlibApi::class) + inline fun deserialize(json: String?): T? { + return if (json.isNullOrBlank()) null else moshi.adapter().fromJson(json) + } + + @OptIn(ExperimentalStdlibApi::class) + inline fun serialize(obj: T): String { + return moshi.adapter().toJson(obj) + } } diff --git a/lib/src/main/kotlin/com/openai/models/CreateAssistantRequestToolResourcesFileSearch.kt b/lib/src/main/kotlin/com/openai/models/CreateAssistantRequestToolResourcesFileSearch.kt index b70216f2..c67ce8cd 100644 --- a/lib/src/main/kotlin/com/openai/models/CreateAssistantRequestToolResourcesFileSearch.kt +++ b/lib/src/main/kotlin/com/openai/models/CreateAssistantRequestToolResourcesFileSearch.kt @@ -26,7 +26,7 @@ import com.squareup.moshi.JsonClass */ -data class CreateAssistantRequestToolResourcesFileSearch ( +class CreateAssistantRequestToolResourcesFileSearch ( ) { diff --git a/lib/src/main/kotlin/com/openai/models/CreateThreadRequestToolResourcesFileSearch.kt b/lib/src/main/kotlin/com/openai/models/CreateThreadRequestToolResourcesFileSearch.kt index 2174abcd..e12f0671 100644 --- a/lib/src/main/kotlin/com/openai/models/CreateThreadRequestToolResourcesFileSearch.kt +++ b/lib/src/main/kotlin/com/openai/models/CreateThreadRequestToolResourcesFileSearch.kt @@ -26,7 +26,7 @@ import com.squareup.moshi.JsonClass */ -data class CreateThreadRequestToolResourcesFileSearch ( +class CreateThreadRequestToolResourcesFileSearch ( ) { diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemCreate.kt b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemCreate.kt index 0b65423c..53f815fc 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemCreate.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemCreate.kt @@ -34,7 +34,7 @@ data class RealtimeClientEventConversationItemCreate ( /* The event type, must be `conversation.item.create`. */ @Json(name = "type") - val type: RealtimeClientEventConversationItemCreate.Type, + val type: RealtimeClientEventConversationItemCreate.Type = RealtimeClientEventConversationItemCreate.Type.conversationPeriodItemPeriodCreate, @Json(name = "item") val item: RealtimeConversationItem, diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemDelete.kt b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemDelete.kt index ae4143d3..bdba1db5 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemDelete.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemDelete.kt @@ -32,7 +32,7 @@ data class RealtimeClientEventConversationItemDelete ( /* The event type, must be `conversation.item.delete`. */ @Json(name = "type") - val type: RealtimeClientEventConversationItemDelete.Type, + val type: RealtimeClientEventConversationItemDelete.Type = RealtimeClientEventConversationItemDelete.Type.conversationPeriodItemPeriodDelete, /* The ID of the item to delete. */ @Json(name = "item_id") diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemTruncate.kt b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemTruncate.kt index d2e00c64..83f674ee 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemTruncate.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventConversationItemTruncate.kt @@ -34,7 +34,7 @@ data class RealtimeClientEventConversationItemTruncate ( /* The event type, must be `conversation.item.truncate`. */ @Json(name = "type") - val type: RealtimeClientEventConversationItemTruncate.Type, + val type: RealtimeClientEventConversationItemTruncate.Type = RealtimeClientEventConversationItemTruncate.Type.conversationPeriodItemPeriodTruncate, /* The ID of the assistant message item to truncate. Only assistant message items can be truncated. */ @Json(name = "item_id") diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferAppend.kt b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferAppend.kt index 6176640c..0ae209f9 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferAppend.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferAppend.kt @@ -32,7 +32,7 @@ data class RealtimeClientEventInputAudioBufferAppend ( /* The event type, must be `input_audio_buffer.append`. */ @Json(name = "type") - val type: RealtimeClientEventInputAudioBufferAppend.Type, + val type: RealtimeClientEventInputAudioBufferAppend.Type = RealtimeClientEventInputAudioBufferAppend.Type.input_audio_bufferPeriodAppend, /* Base64-encoded audio bytes. This must be in the format specified by the `input_audio_format` field in the session configuration. */ @Json(name = "audio") diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferClear.kt b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferClear.kt index 1814a784..93b7367b 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferClear.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferClear.kt @@ -31,7 +31,7 @@ data class RealtimeClientEventInputAudioBufferClear ( /* The event type, must be `input_audio_buffer.clear`. */ @Json(name = "type") - val type: RealtimeClientEventInputAudioBufferClear.Type, + val type: RealtimeClientEventInputAudioBufferClear.Type = RealtimeClientEventInputAudioBufferClear.Type.input_audio_bufferPeriodClear, /* Optional client-generated ID used to identify this event. */ @Json(name = "event_id") diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferCommit.kt b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferCommit.kt index 2f354f50..28de3d18 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferCommit.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventInputAudioBufferCommit.kt @@ -31,7 +31,7 @@ data class RealtimeClientEventInputAudioBufferCommit ( /* The event type, must be `input_audio_buffer.commit`. */ @Json(name = "type") - val type: RealtimeClientEventInputAudioBufferCommit.Type, + val type: RealtimeClientEventInputAudioBufferCommit.Type = RealtimeClientEventInputAudioBufferCommit.Type.input_audio_bufferPeriodCommit, /* Optional client-generated ID used to identify this event. */ @Json(name = "event_id") diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventResponseCancel.kt b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventResponseCancel.kt index 6e915663..2851a3ee 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventResponseCancel.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventResponseCancel.kt @@ -32,7 +32,7 @@ data class RealtimeClientEventResponseCancel ( /* The event type, must be `response.cancel`. */ @Json(name = "type") - val type: RealtimeClientEventResponseCancel.Type, + val type: RealtimeClientEventResponseCancel.Type = RealtimeClientEventResponseCancel.Type.responsePeriodCancel, /* Optional client-generated ID used to identify this event. */ @Json(name = "event_id") diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventResponseCreate.kt b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventResponseCreate.kt index d68ab524..168bb0a1 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventResponseCreate.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventResponseCreate.kt @@ -33,7 +33,7 @@ data class RealtimeClientEventResponseCreate ( /* The event type, must be `response.create`. */ @Json(name = "type") - val type: RealtimeClientEventResponseCreate.Type, + val type: RealtimeClientEventResponseCreate.Type = RealtimeClientEventResponseCreate.Type.responsePeriodCreate, /* Optional client-generated ID used to identify this event. */ @Json(name = "event_id") diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventSessionUpdate.kt b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventSessionUpdate.kt index 5ee006d4..611cea33 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeClientEventSessionUpdate.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeClientEventSessionUpdate.kt @@ -33,7 +33,7 @@ data class RealtimeClientEventSessionUpdate ( /* The event type, must be `session.update`. */ @Json(name = "type") - val type: RealtimeClientEventSessionUpdate.Type, + val type: RealtimeClientEventSessionUpdate.Type = RealtimeClientEventSessionUpdate.Type.sessionPeriodUpdate, @Json(name = "session") val session: RealtimeSessionCreateRequest, diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeConversationItem.kt b/lib/src/main/kotlin/com/openai/models/RealtimeConversationItem.kt index f47bde3a..5310ecbd 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeConversationItem.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeConversationItem.kt @@ -15,8 +15,6 @@ package com.openai.models -import com.openai.models.RealtimeConversationItemContentInner - import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @@ -60,7 +58,7 @@ data class RealtimeConversationItem ( /* The content of the message, applicable for `message` items. - Message items of role `system` support only `input_text` content - Message items of role `user` support `input_text` and `input_audio` content - Message items of role `assistant` support `text` content. */ @Json(name = "content") - val content: kotlin.collections.List? = null, + val content: kotlin.collections.List? = null, /* The ID of the function call (for `function_call` and `function_call_output` items). If passed on a `function_call_output` item, the server will check that a `function_call` item with the same ID exists in the conversation history. */ @Json(name = "call_id") @@ -108,7 +106,8 @@ data class RealtimeConversationItem ( @JsonClass(generateAdapter = false) enum class Status(val value: kotlin.String) { @Json(name = "completed") completed("completed"), - @Json(name = "incomplete") incomplete("incomplete"); + @Json(name = "incomplete") incomplete("incomplete"), + @Json(name = "in_progress") inProgress("in_progress"); } /** * The role of the message sender (`user`, `assistant`, `system`), only applicable for `message` items. diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeConversationItemContentInner.kt b/lib/src/main/kotlin/com/openai/models/RealtimeConversationItemContent.kt similarity index 93% rename from lib/src/main/kotlin/com/openai/models/RealtimeConversationItemContentInner.kt rename to lib/src/main/kotlin/com/openai/models/RealtimeConversationItemContent.kt index e6c09b24..86d2d2c3 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeConversationItemContentInner.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeConversationItemContent.kt @@ -30,11 +30,11 @@ import com.squareup.moshi.JsonClass */ -data class RealtimeConversationItemContentInner ( +data class RealtimeConversationItemContent ( /* The content type (`input_text`, `input_audio`, `item_reference`, `text`). */ @Json(name = "type") - val type: RealtimeConversationItemContentInner.Type? = null, + val type: RealtimeConversationItemContent.Type? = null, /* The text content, used for `input_text` and `text` content types. */ @Json(name = "text") @@ -61,6 +61,7 @@ data class RealtimeConversationItemContentInner ( */ @JsonClass(generateAdapter = false) enum class Type(val value: kotlin.String) { + @Json(name = "audio") audio("audio"), @Json(name = "input_audio") input_audio("input_audio"), @Json(name = "input_text") input_text("input_text"), @Json(name = "item_reference") item_reference("item_reference"), diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeResponse.kt b/lib/src/main/kotlin/com/openai/models/RealtimeResponse.kt index 377ca172..b3aacf72 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeResponse.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeResponse.kt @@ -84,7 +84,8 @@ data class RealtimeResponse ( @Json(name = "completed") completed("completed"), @Json(name = "cancelled") cancelled("cancelled"), @Json(name = "failed") failed("failed"), - @Json(name = "incomplete") incomplete("incomplete"); + @Json(name = "incomplete") incomplete("incomplete"), + @Json(name = "in_progress") inProgress("in_progress"); } } diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParams.kt b/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParams.kt index 6a594f0f..cc198e6f 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParams.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParams.kt @@ -15,11 +15,6 @@ package com.openai.models -import com.openai.models.RealtimeConversationItem -import com.openai.models.RealtimeResponseCreateParamsConversation -import com.openai.models.RealtimeResponseCreateParamsMaxResponseOutputTokens -import com.openai.models.RealtimeResponseCreateParamsToolsInner - import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @@ -44,7 +39,7 @@ data class RealtimeResponseCreateParams ( /* The set of modalities the model can respond with. To disable audio, set this to [\"text\"]. */ @Json(name = "modalities") - val modalities: kotlin.collections.List? = null, + val modalities: kotlin.collections.List? = null, /* The default system instructions (i.e. system message) prepended to model calls. This field allows the client to guide the model on desired responses. The model can be instructed on response content and format, (e.g. \"be extremely succinct\", \"act friendly\", \"here are examples of good responses\") and on audio behavior (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The instructions are not guaranteed to be followed by the model, but they provide guidance to the model on the desired behavior. Note that the server sets default instructions which will be used if this field is not set and are visible in the `session.created` event at the start of the session. */ @Json(name = "instructions") @@ -52,15 +47,15 @@ data class RealtimeResponseCreateParams ( /* The voice the model uses to respond. Voice cannot be changed during the session once the model has responded with audio at least once. Current voice options are `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`. */ @Json(name = "voice") - val voice: RealtimeResponseCreateParams.Voice? = null, + val voice: RealtimeSessionVoice? = null, /* The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. */ @Json(name = "output_audio_format") - val outputAudioFormat: RealtimeResponseCreateParams.OutputAudioFormat? = null, + val outputAudioFormat: RealtimeSessionOutputAudioFormat? = null, /* Tools (functions) available to the model. */ @Json(name = "tools") - val tools: kotlin.collections.List? = null, + val tools: kotlin.collections.List? = null, /* How the model chooses tools. Options are `auto`, `none`, `required`, or specify a function, like `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}`. */ @Json(name = "tool_choice") @@ -71,7 +66,7 @@ data class RealtimeResponseCreateParams ( val temperature: java.math.BigDecimal? = null, @Json(name = "max_response_output_tokens") - val maxResponseOutputTokens: RealtimeResponseCreateParamsMaxResponseOutputTokens? = null, + val maxResponseOutputTokens: RealtimeSessionMaxResponseOutputTokens? = null, @Json(name = "conversation") val conversation: RealtimeResponseCreateParamsConversation? = null, @@ -85,44 +80,14 @@ data class RealtimeResponseCreateParams ( val input: kotlin.collections.List? = null ) { - - /** - * The set of modalities the model can respond with. To disable audio, set this to [\"text\"]. - * - * Values: text,audio - */ - @JsonClass(generateAdapter = false) - enum class Modalities(val value: kotlin.String) { - @Json(name = "text") text("text"), - @Json(name = "audio") audio("audio"); - } /** - * The voice the model uses to respond. Voice cannot be changed during the session once the model has responded with audio at least once. Current voice options are `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`. + * Controls which conversation the response is added to. Currently supports `auto` and `none`, with `auto` as the default value. The `auto` value means that the contents of the response will be added to the default conversation. Set this to `none` to create an out-of-band response which will not add items to default conversation. * - * Values: alloy,ash,ballad,coral,echo,sage,shimmer,verse */ @JsonClass(generateAdapter = false) - enum class Voice(val value: kotlin.String) { - @Json(name = "alloy") alloy("alloy"), - @Json(name = "ash") ash("ash"), - @Json(name = "ballad") ballad("ballad"), - @Json(name = "coral") coral("coral"), - @Json(name = "echo") echo("echo"), - @Json(name = "sage") sage("sage"), - @Json(name = "shimmer") shimmer("shimmer"), - @Json(name = "verse") verse("verse"); + enum class RealtimeResponseCreateParamsConversation { + auto, + none; } - /** - * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. - * - * Values: pcm16,g711_ulaw,g711_alaw - */ - @JsonClass(generateAdapter = false) - enum class OutputAudioFormat(val value: kotlin.String) { - @Json(name = "pcm16") pcm16("pcm16"), - @Json(name = "g711_ulaw") g711_ulaw("g711_ulaw"), - @Json(name = "g711_alaw") g711_alaw("g711_alaw"); - } - } diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParamsConversation.kt b/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParamsConversation.kt deleted file mode 100644 index 37524618..00000000 --- a/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParamsConversation.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.openai.models - - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -/** - * Controls which conversation the response is added to. Currently supports `auto` and `none`, with `auto` as the default value. The `auto` value means that the contents of the response will be added to the default conversation. Set this to `none` to create an out-of-band response which will not add items to default conversation. - * - */ - - -class RealtimeResponseCreateParamsConversation ( - -) { - - -} - diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParamsMaxResponseOutputTokens.kt b/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParamsMaxResponseOutputTokens.kt deleted file mode 100644 index 23e282c8..00000000 --- a/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParamsMaxResponseOutputTokens.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.openai.models - - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -/** - * Maximum number of output tokens for a single assistant response, inclusive of tool calls. Provide an integer between 1 and 4096 to limit output tokens, or `inf` for the maximum available tokens for a given model. Defaults to `inf`. - * - */ - - -class RealtimeResponseCreateParamsMaxResponseOutputTokens ( - -) { - - -} - diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeServerEventConversationItemCreated.kt b/lib/src/main/kotlin/com/openai/models/RealtimeServerEventConversationItemCreated.kt index 4bfa100f..36fb836d 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeServerEventConversationItemCreated.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeServerEventConversationItemCreated.kt @@ -42,7 +42,7 @@ data class RealtimeServerEventConversationItemCreated ( /* The ID of the preceding item in the Conversation context, allows the client to understand the order of the conversation. */ @Json(name = "previous_item_id") - val previousItemId: kotlin.String, + val previousItemId: kotlin.String? = null, @Json(name = "item") val item: RealtimeConversationItem diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeServerEventInputAudioBufferCommitted.kt b/lib/src/main/kotlin/com/openai/models/RealtimeServerEventInputAudioBufferCommitted.kt index bb5d44ca..c72cf1a8 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeServerEventInputAudioBufferCommitted.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeServerEventInputAudioBufferCommitted.kt @@ -41,7 +41,7 @@ data class RealtimeServerEventInputAudioBufferCommitted ( /* The ID of the preceding item after which the new item will be inserted. */ @Json(name = "previous_item_id") - val previousItemId: kotlin.String, + val previousItemId: kotlin.String? = null, /* The ID of the user message item that will be created. */ @Json(name = "item_id") diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSession.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSession.kt index 94938c63..66a38d1f 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeSession.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSession.kt @@ -15,14 +15,9 @@ package com.openai.models -import com.openai.models.RealtimeResponseCreateParamsMaxResponseOutputTokens -import com.openai.models.RealtimeResponseCreateParamsToolsInner -import com.openai.models.RealtimeSessionInputAudioTranscription -import com.openai.models.RealtimeSessionModel -import com.openai.models.RealtimeSessionTurnDetection +import com.openai.infrastructure.SerializeNull import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass /** * Realtime session object configuration. @@ -51,8 +46,9 @@ data class RealtimeSession ( /* The set of modalities the model can respond with. To disable audio, set this to [\"text\"]. */ @Json(name = "modalities") - val modalities: kotlin.collections.List? = null, + val modalities: kotlin.collections.List? = null, + /* The Realtime model used for this session. */ @Json(name = "model") val model: RealtimeSessionModel? = null, @@ -62,25 +58,27 @@ data class RealtimeSession ( /* The voice the model uses to respond. Voice cannot be changed during the session once the model has responded with audio at least once. Current voice options are `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`. */ @Json(name = "voice") - val voice: RealtimeSession.Voice? = null, + val voice: RealtimeSessionVoice? = null, /* The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. */ @Json(name = "input_audio_format") - val inputAudioFormat: RealtimeSession.InputAudioFormat? = null, + val inputAudioFormat: RealtimeSessionInputAudioFormat? = null, /* The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. */ @Json(name = "output_audio_format") - val outputAudioFormat: RealtimeSession.OutputAudioFormat? = null, + val outputAudioFormat: RealtimeSessionOutputAudioFormat? = null, + @SerializeNull @Json(name = "input_audio_transcription") val inputAudioTranscription: RealtimeSessionInputAudioTranscription? = null, + @SerializeNull @Json(name = "turn_detection") val turnDetection: RealtimeSessionTurnDetection? = null, /* Tools (functions) available to the model. */ @Json(name = "tools") - val tools: kotlin.collections.List? = null, + val tools: kotlin.collections.List? = null, /* How the model chooses tools. Options are `auto`, `none`, `required`, or specify a function. */ @Json(name = "tool_choice") @@ -91,58 +89,8 @@ data class RealtimeSession ( val temperature: java.math.BigDecimal? = null, @Json(name = "max_response_output_tokens") - val maxResponseOutputTokens: RealtimeResponseCreateParamsMaxResponseOutputTokens? = null + val maxResponseOutputTokens: RealtimeSessionMaxResponseOutputTokens? = null ) { - - /** - * The set of modalities the model can respond with. To disable audio, set this to [\"text\"]. - * - * Values: text,audio - */ - @JsonClass(generateAdapter = false) - enum class Modalities(val value: kotlin.String) { - @Json(name = "text") text("text"), - @Json(name = "audio") audio("audio"); - } - /** - * The voice the model uses to respond. Voice cannot be changed during the session once the model has responded with audio at least once. Current voice options are `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`. - * - * Values: alloy,ash,ballad,coral,echo,sage,shimmer,verse - */ - @JsonClass(generateAdapter = false) - enum class Voice(val value: kotlin.String) { - @Json(name = "alloy") alloy("alloy"), - @Json(name = "ash") ash("ash"), - @Json(name = "ballad") ballad("ballad"), - @Json(name = "coral") coral("coral"), - @Json(name = "echo") echo("echo"), - @Json(name = "sage") sage("sage"), - @Json(name = "shimmer") shimmer("shimmer"), - @Json(name = "verse") verse("verse"); - } - /** - * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. - * - * Values: pcm16,g711_ulaw,g711_alaw - */ - @JsonClass(generateAdapter = false) - enum class InputAudioFormat(val value: kotlin.String) { - @Json(name = "pcm16") pcm16("pcm16"), - @Json(name = "g711_ulaw") g711_ulaw("g711_ulaw"), - @Json(name = "g711_alaw") g711_alaw("g711_alaw"); - } - /** - * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. - * - * Values: pcm16,g711_ulaw,g711_alaw - */ - @JsonClass(generateAdapter = false) - enum class OutputAudioFormat(val value: kotlin.String) { - @Json(name = "pcm16") pcm16("pcm16"), - @Json(name = "g711_ulaw") g711_ulaw("g711_ulaw"), - @Json(name = "g711_alaw") g711_alaw("g711_alaw"); - } - } diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateRequest.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateRequest.kt index 2b9c8575..058a63f1 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateRequest.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateRequest.kt @@ -15,13 +15,9 @@ package com.openai.models -import com.openai.models.RealtimeResponseCreateParamsMaxResponseOutputTokens -import com.openai.models.RealtimeResponseCreateParamsToolsInner -import com.openai.models.RealtimeSessionCreateRequestTurnDetection -import com.openai.models.RealtimeSessionInputAudioTranscription +import com.openai.infrastructure.SerializeNull import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass /** * Realtime session object configuration. @@ -43,13 +39,13 @@ import com.squareup.moshi.JsonClass data class RealtimeSessionCreateRequest ( - /* The Realtime model used for this session. */ - @Json(name = "model") - val model: RealtimeSessionCreateRequest.Model, - /* The set of modalities the model can respond with. To disable audio, set this to [\"text\"]. */ @Json(name = "modalities") - val modalities: kotlin.collections.List? = null, + val modalities: kotlin.collections.List? = null, + + /* The Realtime model used for this session. */ + @Json(name = "model") + val model: RealtimeSessionModel, /* The default system instructions (i.e. system message) prepended to model calls. This field allows the client to guide the model on desired responses. The model can be instructed on response content and format, (e.g. \"be extremely succinct\", \"act friendly\", \"here are examples of good responses\") and on audio behavior (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The instructions are not guaranteed to be followed by the model, but they provide guidance to the model on the desired behavior. Note that the server sets default instructions which will be used if this field is not set and are visible in the `session.created` event at the start of the session. */ @Json(name = "instructions") @@ -57,25 +53,27 @@ data class RealtimeSessionCreateRequest ( /* The voice the model uses to respond. Voice cannot be changed during the session once the model has responded with audio at least once. Current voice options are `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`. */ @Json(name = "voice") - val voice: RealtimeSessionCreateRequest.Voice? = null, + val voice: RealtimeSessionVoice? = null, /* The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. */ @Json(name = "input_audio_format") - val inputAudioFormat: RealtimeSessionCreateRequest.InputAudioFormat? = null, + val inputAudioFormat: RealtimeSessionInputAudioFormat? = null, /* The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. */ @Json(name = "output_audio_format") - val outputAudioFormat: RealtimeSessionCreateRequest.OutputAudioFormat? = null, + val outputAudioFormat: RealtimeSessionOutputAudioFormat? = null, + @SerializeNull @Json(name = "input_audio_transcription") val inputAudioTranscription: RealtimeSessionInputAudioTranscription? = null, + @SerializeNull @Json(name = "turn_detection") - val turnDetection: RealtimeSessionCreateRequestTurnDetection? = null, + val turnDetection: RealtimeSessionTurnDetection? = null, /* Tools (functions) available to the model. */ @Json(name = "tools") - val tools: kotlin.collections.List? = null, + val tools: kotlin.collections.List? = null, /* How the model chooses tools. Options are `auto`, `none`, `required`, or specify a function. */ @Json(name = "tool_choice") @@ -86,71 +84,8 @@ data class RealtimeSessionCreateRequest ( val temperature: java.math.BigDecimal? = null, @Json(name = "max_response_output_tokens") - val maxResponseOutputTokens: RealtimeResponseCreateParamsMaxResponseOutputTokens? = null + val maxResponseOutputTokens: RealtimeSessionMaxResponseOutputTokens? = null ) { - - /** - * The Realtime model used for this session. - * - * Values: realtimeMinusPreview,realtimeMinusPreviewMinus2024Minus10Minus01,realtimeMinusPreviewMinus2024Minus12Minus17,miniMinusRealtimeMinusPreview,miniMinusRealtimeMinusPreviewMinus2024Minus12Minus17 - */ - @JsonClass(generateAdapter = false) - enum class Model(val value: kotlin.String) { - @Json(name = "gpt-4o-realtime-preview") realtimeMinusPreview("gpt-4o-realtime-preview"), - @Json(name = "gpt-4o-realtime-preview-2024-10-01") realtimeMinusPreviewMinus2024Minus10Minus01("gpt-4o-realtime-preview-2024-10-01"), - @Json(name = "gpt-4o-realtime-preview-2024-12-17") realtimeMinusPreviewMinus2024Minus12Minus17("gpt-4o-realtime-preview-2024-12-17"), - @Json(name = "gpt-4o-mini-realtime-preview") miniMinusRealtimeMinusPreview("gpt-4o-mini-realtime-preview"), - @Json(name = "gpt-4o-mini-realtime-preview-2024-12-17") miniMinusRealtimeMinusPreviewMinus2024Minus12Minus17("gpt-4o-mini-realtime-preview-2024-12-17"); - } - /** - * The set of modalities the model can respond with. To disable audio, set this to [\"text\"]. - * - * Values: text,audio - */ - @JsonClass(generateAdapter = false) - enum class Modalities(val value: kotlin.String) { - @Json(name = "text") text("text"), - @Json(name = "audio") audio("audio"); - } - /** - * The voice the model uses to respond. Voice cannot be changed during the session once the model has responded with audio at least once. Current voice options are `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`. - * - * Values: alloy,ash,ballad,coral,echo,sage,shimmer,verse - */ - @JsonClass(generateAdapter = false) - enum class Voice(val value: kotlin.String) { - @Json(name = "alloy") alloy("alloy"), - @Json(name = "ash") ash("ash"), - @Json(name = "ballad") ballad("ballad"), - @Json(name = "coral") coral("coral"), - @Json(name = "echo") echo("echo"), - @Json(name = "sage") sage("sage"), - @Json(name = "shimmer") shimmer("shimmer"), - @Json(name = "verse") verse("verse"); - } - /** - * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. - * - * Values: pcm16,g711_ulaw,g711_alaw - */ - @JsonClass(generateAdapter = false) - enum class InputAudioFormat(val value: kotlin.String) { - @Json(name = "pcm16") pcm16("pcm16"), - @Json(name = "g711_ulaw") g711_ulaw("g711_ulaw"), - @Json(name = "g711_alaw") g711_alaw("g711_alaw"); - } - /** - * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. - * - * Values: pcm16,g711_ulaw,g711_alaw - */ - @JsonClass(generateAdapter = false) - enum class OutputAudioFormat(val value: kotlin.String) { - @Json(name = "pcm16") pcm16("pcm16"), - @Json(name = "g711_ulaw") g711_ulaw("g711_ulaw"), - @Json(name = "g711_alaw") g711_alaw("g711_alaw"); - } - } diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateRequestTurnDetection.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateRequestTurnDetection.kt deleted file mode 100644 index 88332649..00000000 --- a/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateRequestTurnDetection.kt +++ /dev/null @@ -1,59 +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.openai.models - - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -/** - * Configuration for turn detection. Can be set to `null` to turn off. Server VAD means that the model will detect the start and end of speech based on audio volume and respond at the end of user speech. - * - * @param type Type of turn detection, only `server_vad` is currently supported. - * @param threshold Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher threshold will require louder audio to activate the model, and thus might perform better in noisy environments. - * @param prefixPaddingMs Amount of audio to include before the VAD detected speech (in milliseconds). Defaults to 300ms. - * @param silenceDurationMs Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms. With shorter values the model will respond more quickly, but may jump in on short pauses from the user. - * @param createResponse Whether or not to automatically generate a response when VAD is enabled. `true` by default. - */ - - -data class RealtimeSessionCreateRequestTurnDetection ( - - /* Type of turn detection, only `server_vad` is currently supported. */ - @Json(name = "type") - val type: kotlin.String? = null, - - /* Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher threshold will require louder audio to activate the model, and thus might perform better in noisy environments. */ - @Json(name = "threshold") - val threshold: java.math.BigDecimal? = null, - - /* Amount of audio to include before the VAD detected speech (in milliseconds). Defaults to 300ms. */ - @Json(name = "prefix_padding_ms") - val prefixPaddingMs: kotlin.Int? = null, - - /* Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms. With shorter values the model will respond more quickly, but may jump in on short pauses from the user. */ - @Json(name = "silence_duration_ms") - val silenceDurationMs: kotlin.Int? = null, - - /* Whether or not to automatically generate a response when VAD is enabled. `true` by default. */ - @Json(name = "create_response") - val createResponse: kotlin.Boolean? = true - -) { - - -} - diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateResponse.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateResponse.kt index d8f2fac0..72b3dda7 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateResponse.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateResponse.kt @@ -15,14 +15,9 @@ package com.openai.models -import com.openai.models.RealtimeResponseCreateParamsMaxResponseOutputTokens -import com.openai.models.RealtimeResponseCreateParamsToolsInner -import com.openai.models.RealtimeSessionCreateResponseClientSecret -import com.openai.models.RealtimeSessionCreateResponseTurnDetection -import com.openai.models.RealtimeSessionInputAudioTranscription +import com.openai.infrastructure.SerializeNull import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass /** * A new Realtime session configuration, with an ephermeral key. Default TTL for keys is one minute. @@ -49,7 +44,7 @@ data class RealtimeSessionCreateResponse ( /* The set of modalities the model can respond with. To disable audio, set this to [\"text\"]. */ @Json(name = "modalities") - val modalities: kotlin.collections.List? = null, + val modalities: kotlin.collections.List? = null, /* The default system instructions (i.e. system message) prepended to model calls. This field allows the client to guide the model on desired responses. The model can be instructed on response content and format, (e.g. \"be extremely succinct\", \"act friendly\", \"here are examples of good responses\") and on audio behavior (e.g. \"talk quickly\", \"inject emotion into your voice\", \"laugh frequently\"). The instructions are not guaranteed to be followed by the model, but they provide guidance to the model on the desired behavior. Note that the server sets default instructions which will be used if this field is not set and are visible in the `session.created` event at the start of the session. */ @Json(name = "instructions") @@ -57,25 +52,27 @@ data class RealtimeSessionCreateResponse ( /* The voice the model uses to respond. Voice cannot be changed during the session once the model has responded with audio at least once. Current voice options are `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`. */ @Json(name = "voice") - val voice: RealtimeSessionCreateResponse.Voice? = null, + val voice: RealtimeSessionVoice? = null, /* The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. */ @Json(name = "input_audio_format") - val inputAudioFormat: kotlin.String? = null, + val inputAudioFormat: RealtimeSessionInputAudioFormat? = null, /* The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. */ @Json(name = "output_audio_format") - val outputAudioFormat: kotlin.String? = null, + val outputAudioFormat: RealtimeSessionOutputAudioFormat? = null, + @SerializeNull @Json(name = "input_audio_transcription") val inputAudioTranscription: RealtimeSessionInputAudioTranscription? = null, + @SerializeNull @Json(name = "turn_detection") - val turnDetection: RealtimeSessionCreateResponseTurnDetection? = null, + val turnDetection: RealtimeSessionTurnDetection? = null, /* Tools (functions) available to the model. */ @Json(name = "tools") - val tools: kotlin.collections.List? = null, + val tools: kotlin.collections.List? = null, /* How the model chooses tools. Options are `auto`, `none`, `required`, or specify a function. */ @Json(name = "tool_choice") @@ -86,36 +83,7 @@ data class RealtimeSessionCreateResponse ( val temperature: java.math.BigDecimal? = null, @Json(name = "max_response_output_tokens") - val maxResponseOutputTokens: RealtimeResponseCreateParamsMaxResponseOutputTokens? = null + val maxResponseOutputTokens: RealtimeSessionMaxResponseOutputTokens? = null ) { - - /** - * The set of modalities the model can respond with. To disable audio, set this to [\"text\"]. - * - * Values: text,audio - */ - @JsonClass(generateAdapter = false) - enum class Modalities(val value: kotlin.String) { - @Json(name = "text") text("text"), - @Json(name = "audio") audio("audio"); - } - /** - * The voice the model uses to respond. Voice cannot be changed during the session once the model has responded with audio at least once. Current voice options are `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`. - * - * Values: alloy,ash,ballad,coral,echo,sage,shimmer,verse - */ - @JsonClass(generateAdapter = false) - enum class Voice(val value: kotlin.String) { - @Json(name = "alloy") alloy("alloy"), - @Json(name = "ash") ash("ash"), - @Json(name = "ballad") ballad("ballad"), - @Json(name = "coral") coral("coral"), - @Json(name = "echo") echo("echo"), - @Json(name = "sage") sage("sage"), - @Json(name = "shimmer") shimmer("shimmer"), - @Json(name = "verse") verse("verse"); - } - } - diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateResponseTurnDetection.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateResponseTurnDetection.kt deleted file mode 100644 index 8f636961..00000000 --- a/lib/src/main/kotlin/com/openai/models/RealtimeSessionCreateResponseTurnDetection.kt +++ /dev/null @@ -1,54 +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.openai.models - - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -/** - * Configuration for turn detection. Can be set to `null` to turn off. Server VAD means that the model will detect the start and end of speech based on audio volume and respond at the end of user speech. - * - * @param type Type of turn detection, only `server_vad` is currently supported. - * @param threshold Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher threshold will require louder audio to activate the model, and thus might perform better in noisy environments. - * @param prefixPaddingMs Amount of audio to include before the VAD detected speech (in milliseconds). Defaults to 300ms. - * @param silenceDurationMs Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms. With shorter values the model will respond more quickly, but may jump in on short pauses from the user. - */ - - -data class RealtimeSessionCreateResponseTurnDetection ( - - /* Type of turn detection, only `server_vad` is currently supported. */ - @Json(name = "type") - val type: kotlin.String? = null, - - /* Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher threshold will require louder audio to activate the model, and thus might perform better in noisy environments. */ - @Json(name = "threshold") - val threshold: java.math.BigDecimal? = null, - - /* Amount of audio to include before the VAD detected speech (in milliseconds). Defaults to 300ms. */ - @Json(name = "prefix_padding_ms") - val prefixPaddingMs: kotlin.Int? = null, - - /* Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms. With shorter values the model will respond more quickly, but may jump in on short pauses from the user. */ - @Json(name = "silence_duration_ms") - val silenceDurationMs: kotlin.Int? = null - -) { - - -} - diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionInputAudioFormat.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionInputAudioFormat.kt new file mode 100644 index 00000000..ae92c31f --- /dev/null +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionInputAudioFormat.kt @@ -0,0 +1,17 @@ +@file:Suppress("EnumEntryName") + +package com.openai.models + +import com.squareup.moshi.JsonClass + +/** + * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. + * + * Values: pcm16,g711_ulaw,g711_alaw + */ +@JsonClass(generateAdapter = false) +enum class RealtimeSessionInputAudioFormat { + pcm16, + g711_ulaw, + g711_alaw +} diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionInputAudioTranscription.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionInputAudioTranscription.kt index 3c1fdd98..d177e8c2 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeSessionInputAudioTranscription.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionInputAudioTranscription.kt @@ -30,9 +30,18 @@ data class RealtimeSessionInputAudioTranscription ( /* The model to use for transcription, `whisper-1` is the only currently supported model. */ @Json(name = "model") - val model: kotlin.String? = null + val model: Model? = null ) { + /** + * The model to use for transcription, `whisper-1` is the only currently supported model. + * + * Values: whisper-1 + */ + @JsonClass(generateAdapter = false) + enum class Model { + `whisper-1` + } } diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionMaxResponseOutputTokens.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionMaxResponseOutputTokens.kt new file mode 100644 index 00000000..3ba09917 --- /dev/null +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionMaxResponseOutputTokens.kt @@ -0,0 +1,76 @@ +/** + * + * 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.openai.models + +import com.squareup.moshi.FromJson +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.JsonDataException +import com.squareup.moshi.JsonReader +import com.squareup.moshi.JsonWriter +import com.squareup.moshi.ToJson + +/** + * Maximum number of output tokens for a single assistant response, inclusive of tool calls. Provide an integer between 1 and 4096 to limit output tokens, or `inf` for the maximum available tokens for a given model. Defaults to `inf`. + * + */ +open class RealtimeSessionMaxResponseOutputTokens { + data class Numeric(val value: Int) : RealtimeSessionMaxResponseOutputTokens() + data object Inf : RealtimeSessionMaxResponseOutputTokens() +} + +class RealtimeSessionMaxResponseOutputTokensAdapter : JsonAdapter() { + @FromJson + override fun fromJson(reader: JsonReader): RealtimeSessionMaxResponseOutputTokens? { + return when (reader.peek()) { + JsonReader.Token.NUMBER -> { + RealtimeSessionMaxResponseOutputTokens.Numeric(reader.nextInt()) + } + JsonReader.Token.STRING -> { + val value = reader.nextString() + if (value == "inf") { + RealtimeSessionMaxResponseOutputTokens.Inf + } else { + // If the server only ever gives "inf" or numbers, + // you might consider throwing or returning null for an unrecognized string. + throw JsonDataException("Unknown string for max_response_output_tokens: $value") + } + } + JsonReader.Token.NULL -> { + // The server might omit or return null + reader.nextNull() + null + } + else -> { + // Some unexpected type + throw JsonDataException( + "Expected NUMBER or STRING for max_response_output_tokens but was ${reader.peek()}" + ) + } + } + } + + @ToJson + override fun toJson(writer: JsonWriter, value: RealtimeSessionMaxResponseOutputTokens?) { + if (value == null) { + writer.nullValue() + return + } + when (value) { + is RealtimeSessionMaxResponseOutputTokens.Numeric -> writer.value(value.value) + is RealtimeSessionMaxResponseOutputTokens.Inf -> writer.value("inf") + } + } +} diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionModalities.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionModalities.kt new file mode 100644 index 00000000..fa8b13a5 --- /dev/null +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionModalities.kt @@ -0,0 +1,16 @@ +@file:Suppress("EnumEntryName") + +package com.openai.models + +import com.squareup.moshi.JsonClass + +/** + * The set of modalities the model can respond with. To disable audio, set this to [\"text\"]. + * + * Values: text,audio + */ +@JsonClass(generateAdapter = false) +enum class RealtimeSessionModalities { + text, + audio, +} diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionModel.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionModel.kt index 56f6684c..ba45a918 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeSessionModel.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionModel.kt @@ -10,25 +10,26 @@ "ArrayInDataClass", "EnumEntryName", "RemoveRedundantQualifierName", - "UnusedImport" + "UnusedImport", + "unused", ) package com.openai.models - -import com.squareup.moshi.Json import com.squareup.moshi.JsonClass /** * The Realtime model used for this session. * + * https://platform.openai.com/docs/models#gpt-4o-realtime + * + * Values: gpt-4o-realtime-preview, gpt-4o-realtime-preview-2024-10-01, gpt-4o-realtime-preview-2024-12-17, gpt-4o-mini-realtime-preview, gpt-4o-mini-realtime-preview-2024-12-17 */ - - -class RealtimeSessionModel ( - -) { - - +@JsonClass(generateAdapter = false) +enum class RealtimeSessionModel { + `gpt-4o-realtime-preview`, + `gpt-4o-realtime-preview-2024-10-01`, + `gpt-4o-realtime-preview-2024-12-17`, + `gpt-4o-mini-realtime-preview`, + `gpt-4o-mini-realtime-preview-2024-12-17`, } - diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionOutputAudioFormat.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionOutputAudioFormat.kt new file mode 100644 index 00000000..2ae96bcf --- /dev/null +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionOutputAudioFormat.kt @@ -0,0 +1,17 @@ +@file:Suppress("EnumEntryName") + +package com.openai.models + +import com.squareup.moshi.JsonClass + +/** + * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`. + * + * Values: pcm16,g711_ulaw,g711_alaw + */ +@JsonClass(generateAdapter = false) +enum class RealtimeSessionOutputAudioFormat { + pcm16, + g711_ulaw, + g711_alaw +} diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParamsToolsInner.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionTools.kt similarity index 92% rename from lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParamsToolsInner.kt rename to lib/src/main/kotlin/com/openai/models/RealtimeSessionTools.kt index 8642141f..bd89cac5 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeResponseCreateParamsToolsInner.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionTools.kt @@ -29,11 +29,11 @@ import com.squareup.moshi.JsonClass */ -data class RealtimeResponseCreateParamsToolsInner ( +data class RealtimeSessionTools ( /* The type of the tool, i.e. `function`. */ @Json(name = "type") - val type: RealtimeResponseCreateParamsToolsInner.Type? = null, + val type: RealtimeSessionTools.Type? = null, /* The name of the function. */ @Json(name = "name") diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionTurnDetection.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionTurnDetection.kt index 4995a199..8f254189 100644 --- a/lib/src/main/kotlin/com/openai/models/RealtimeSessionTurnDetection.kt +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionTurnDetection.kt @@ -10,7 +10,8 @@ "ArrayInDataClass", "EnumEntryName", "RemoveRedundantQualifierName", - "UnusedImport" + "UnusedImport", + "unused", ) package com.openai.models @@ -26,6 +27,7 @@ import com.squareup.moshi.JsonClass * @param threshold Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher threshold will require louder audio to activate the model, and thus might perform better in noisy environments. * @param prefixPaddingMs Amount of audio to include before the VAD detected speech (in milliseconds). Defaults to 300ms. * @param silenceDurationMs Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms. With shorter values the model will respond more quickly, but may jump in on short pauses from the user. + * @param createResponse Whether or not to automatically generate a response when VAD is enabled. `true` by default. */ @@ -45,18 +47,21 @@ data class RealtimeSessionTurnDetection ( /* Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms. With shorter values the model will respond more quickly, but may jump in on short pauses from the user. */ @Json(name = "silence_duration_ms") - val silenceDurationMs: kotlin.Int? = null + val silenceDurationMs: kotlin.Int? = null, -) { + /* Whether or not to automatically generate a response when VAD is enabled. `true` by default. */ + @Json(name = "create_response") + val createResponse: kotlin.Boolean? = true +) { /** - * Type of turn detection, only `server_vad` is currently supported. + * Type of turn detection, only `server_vad` is currently supported. * * Values: server_vad */ @JsonClass(generateAdapter = false) - enum class Type(val value: kotlin.String) { - @Json(name = "server_vad") server_vad("server_vad"); + enum class Type { + server_vad } } diff --git a/lib/src/main/kotlin/com/openai/models/RealtimeSessionVoice.kt b/lib/src/main/kotlin/com/openai/models/RealtimeSessionVoice.kt new file mode 100644 index 00000000..468e4277 --- /dev/null +++ b/lib/src/main/kotlin/com/openai/models/RealtimeSessionVoice.kt @@ -0,0 +1,20 @@ +package com.openai.models + +import com.squareup.moshi.JsonClass + +/** + * The voice the model uses to respond. Voice cannot be changed during the session once the model has responded with audio at least once. Current voice options are `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`. + * + * Values: alloy,ash,ballad,coral,echo,sage,shimmer,verse + */ +@JsonClass(generateAdapter = false) +enum class RealtimeSessionVoice { + alloy, + ash, + ballad, + coral, + echo, + sage, + shimmer, + verse, +} diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeConversationItemContentInnerTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeConversationItemContentTest.kt similarity index 89% rename from lib/src/test/kotlin/com/openai/models/RealtimeConversationItemContentInnerTest.kt rename to lib/src/test/kotlin/com/openai/models/RealtimeConversationItemContentTest.kt index f3e24c01..fd83d87b 100644 --- a/lib/src/test/kotlin/com/openai/models/RealtimeConversationItemContentInnerTest.kt +++ b/lib/src/test/kotlin/com/openai/models/RealtimeConversationItemContentTest.kt @@ -18,12 +18,10 @@ package com.openai.models import io.kotlintest.shouldBe import io.kotlintest.specs.ShouldSpec -import com.openai.models.RealtimeConversationItemContentInner - -class RealtimeConversationItemContentInnerTest : ShouldSpec() { +class RealtimeConversationItemContentTest : ShouldSpec() { init { - // uncomment below to create an instance of RealtimeConversationItemContentInner - //val modelInstance = RealtimeConversationItemContentInner() + // uncomment below to create an instance of RealtimeConversationItemContent + //val modelInstance = RealtimeConversationItemContent() // to test the property `type` - The content type (`input_text`, `input_audio`, `item_reference`, `text`). should("test type") { diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeConversationItemTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeConversationItemTest.kt index e54d0df5..30506680 100644 --- a/lib/src/test/kotlin/com/openai/models/RealtimeConversationItemTest.kt +++ b/lib/src/test/kotlin/com/openai/models/RealtimeConversationItemTest.kt @@ -18,9 +18,6 @@ package com.openai.models import io.kotlintest.shouldBe import io.kotlintest.specs.ShouldSpec -import com.openai.models.RealtimeConversationItem -import com.openai.models.RealtimeConversationItemContentInner - class RealtimeConversationItemTest : ShouldSpec() { init { // uncomment below to create an instance of RealtimeConversationItem diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsMaxResponseOutputTokensTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsMaxResponseOutputTokensTest.kt deleted file mode 100644 index f84673d3..00000000 --- a/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsMaxResponseOutputTokensTest.kt +++ /dev/null @@ -1,29 +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.openai.models - -import io.kotlintest.shouldBe -import io.kotlintest.specs.ShouldSpec - -import com.openai.models.RealtimeResponseCreateParamsMaxResponseOutputTokens - -class RealtimeResponseCreateParamsMaxResponseOutputTokensTest : ShouldSpec() { - init { - // uncomment below to create an instance of RealtimeResponseCreateParamsMaxResponseOutputTokens - //val modelInstance = RealtimeResponseCreateParamsMaxResponseOutputTokens() - - } -} diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsTest.kt index d0d167ee..d90c2c30 100644 --- a/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsTest.kt +++ b/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsTest.kt @@ -18,12 +18,6 @@ package com.openai.models import io.kotlintest.shouldBe import io.kotlintest.specs.ShouldSpec -import com.openai.models.RealtimeResponseCreateParams -import com.openai.models.RealtimeConversationItem -import com.openai.models.RealtimeResponseCreateParamsConversation -import com.openai.models.RealtimeResponseCreateParamsMaxResponseOutputTokens -import com.openai.models.RealtimeResponseCreateParamsToolsInner - class RealtimeResponseCreateParamsTest : ShouldSpec() { init { // uncomment below to create an instance of RealtimeResponseCreateParams diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateRequestTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateRequestTest.kt index 41eaaa82..3bc0f06e 100644 --- a/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateRequestTest.kt +++ b/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateRequestTest.kt @@ -18,12 +18,6 @@ package com.openai.models import io.kotlintest.shouldBe import io.kotlintest.specs.ShouldSpec -import com.openai.models.RealtimeSessionCreateRequest -import com.openai.models.RealtimeResponseCreateParamsMaxResponseOutputTokens -import com.openai.models.RealtimeResponseCreateParamsToolsInner -import com.openai.models.RealtimeSessionCreateRequestTurnDetection -import com.openai.models.RealtimeSessionInputAudioTranscription - class RealtimeSessionCreateRequestTest : ShouldSpec() { init { // uncomment below to create an instance of RealtimeSessionCreateRequest diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateRequestTurnDetectionTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateRequestTurnDetectionTest.kt index a8bf66a0..2ad3e614 100644 --- a/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateRequestTurnDetectionTest.kt +++ b/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateRequestTurnDetectionTest.kt @@ -18,7 +18,7 @@ package com.openai.models import io.kotlintest.shouldBe import io.kotlintest.specs.ShouldSpec -import com.openai.models.RealtimeSessionCreateRequestTurnDetection +import com.openai.models.RealtimeSessionTurnDetection class RealtimeSessionCreateRequestTurnDetectionTest : ShouldSpec() { init { diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateResponseTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateResponseTest.kt index b492939c..873bee44 100644 --- a/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateResponseTest.kt +++ b/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateResponseTest.kt @@ -18,13 +18,6 @@ package com.openai.models import io.kotlintest.shouldBe import io.kotlintest.specs.ShouldSpec -import com.openai.models.RealtimeSessionCreateResponse -import com.openai.models.RealtimeResponseCreateParamsMaxResponseOutputTokens -import com.openai.models.RealtimeResponseCreateParamsToolsInner -import com.openai.models.RealtimeSessionCreateResponseClientSecret -import com.openai.models.RealtimeSessionCreateResponseTurnDetection -import com.openai.models.RealtimeSessionInputAudioTranscription - class RealtimeSessionCreateResponseTest : ShouldSpec() { init { // uncomment below to create an instance of RealtimeSessionCreateResponse diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateResponseTurnDetectionTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateResponseTurnDetectionTest.kt index 029ad3ea..15a18ad2 100644 --- a/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateResponseTurnDetectionTest.kt +++ b/lib/src/test/kotlin/com/openai/models/RealtimeSessionCreateResponseTurnDetectionTest.kt @@ -18,7 +18,7 @@ package com.openai.models import io.kotlintest.shouldBe import io.kotlintest.specs.ShouldSpec -import com.openai.models.RealtimeSessionCreateResponseTurnDetection +import com.openai.models.RealtimeSessionTurnDetection class RealtimeSessionCreateResponseTurnDetectionTest : ShouldSpec() { init { diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsConversationTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeSessionMaxResponseOutputTokensTest.kt similarity index 56% rename from lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsConversationTest.kt rename to lib/src/test/kotlin/com/openai/models/RealtimeSessionMaxResponseOutputTokensTest.kt index a404b2e3..8ab04b6b 100644 --- a/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsConversationTest.kt +++ b/lib/src/test/kotlin/com/openai/models/RealtimeSessionMaxResponseOutputTokensTest.kt @@ -18,12 +18,10 @@ package com.openai.models import io.kotlintest.shouldBe import io.kotlintest.specs.ShouldSpec -import com.openai.models.RealtimeResponseCreateParamsConversation - -class RealtimeResponseCreateParamsConversationTest : ShouldSpec() { +class RealtimeSessionMaxResponseOutputTokensTest : ShouldSpec() { init { - // uncomment below to create an instance of RealtimeResponseCreateParamsConversation - //val modelInstance = RealtimeResponseCreateParamsConversation() + // uncomment below to create an instance of RealtimeSessionMaxResponseOutputTokens + //val modelInstance = RealtimeSessionMaxResponseOutputTokens() } } diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeSessionTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeSessionTest.kt index c6f5bc28..3cf3e139 100644 --- a/lib/src/test/kotlin/com/openai/models/RealtimeSessionTest.kt +++ b/lib/src/test/kotlin/com/openai/models/RealtimeSessionTest.kt @@ -18,13 +18,6 @@ package com.openai.models import io.kotlintest.shouldBe import io.kotlintest.specs.ShouldSpec -import com.openai.models.RealtimeSession -import com.openai.models.RealtimeResponseCreateParamsMaxResponseOutputTokens -import com.openai.models.RealtimeResponseCreateParamsToolsInner -import com.openai.models.RealtimeSessionInputAudioTranscription -import com.openai.models.RealtimeSessionModel -import com.openai.models.RealtimeSessionTurnDetection - class RealtimeSessionTest : ShouldSpec() { init { // uncomment below to create an instance of RealtimeSession diff --git a/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsToolsInnerTest.kt b/lib/src/test/kotlin/com/openai/models/RealtimeSessionToolsTest.kt similarity index 90% rename from lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsToolsInnerTest.kt rename to lib/src/test/kotlin/com/openai/models/RealtimeSessionToolsTest.kt index 7328a64b..d8b647b1 100644 --- a/lib/src/test/kotlin/com/openai/models/RealtimeResponseCreateParamsToolsInnerTest.kt +++ b/lib/src/test/kotlin/com/openai/models/RealtimeSessionToolsTest.kt @@ -15,12 +15,9 @@ package com.openai.models -import io.kotlintest.shouldBe import io.kotlintest.specs.ShouldSpec -import com.openai.models.RealtimeResponseCreateParamsToolsInner - -class RealtimeResponseCreateParamsToolsInnerTest : ShouldSpec() { +class RealtimeSessionToolsTest : ShouldSpec() { init { // uncomment below to create an instance of RealtimeResponseCreateParamsToolsInner //val modelInstance = RealtimeResponseCreateParamsToolsInner() diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..0067103d --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,15 @@ +pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + mavenCentral() + } +} + +rootProject.name = "openai-kotlin-client" +include("lib")