Serializer for class 'ChatCompletionRequest' is not found. #192
Replies: 7 comments
-
Hello @CazimirRoman, applying the Kotlin serialization plugin (discussion) to your project should fix the issue. However, could you please share your Gradle configuration for the release build, so that I can reproduce it? thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi Mouaad, Thank you for your quick response. Here is my gradle file: `plugins { android {
} dependencies {
// implementation(Google.firebaseAds)
}` I managed a quick workaround by keeping everything from your library :D But then i get a huge APK size.
|
Beta Was this translation helpful? Give feedback.
-
Thank you, @CazimirRoman, for sharing! I have a quick question: did adding kotlin("plugin.serialization") to your plugins in Gradle help resolve the issue? Meanwhile, I will run some tests and get back to you :) |
Beta Was this translation helpful? Give feedback.
-
I am trying that now. should I also add the pro guard rules or are these changes mutually exclusive? |
Beta Was this translation helpful? Give feedback.
-
Even with the serializer dependencies i still get: Caused by: kotlinx.serialization.SerializationException: Serializer for class 'ChatCompletionRequest' is not found. What currently works is just to keep everything in the com.aallam.openai.api.chat package: -keep class com.aallam.openai.api.chat.* { *; } |
Beta Was this translation helpful? Give feedback.
-
I solved it. Step:
Refer to |
Beta Was this translation helpful? Give feedback.
-
I am still having issues using 3.2.1 version. Serializer plugin and dependency has been added. None of the described solutions here worked. The narrowest thing that helps is:
When adding those wildcards at the end of the class, i can see a few extra notifications in the proguard logs:
Hope that helps. |
Beta Was this translation helpful? Give feedback.
-
Description
When building a release version for my Android app with R8 i get the error: "Serializer for class 'ChatCompletionRequest' is not found."
Steps to Reproduce
com.aallam.openai.api.exception.OpenAIHttpException: Serializer for class 'ChatCompletionRequest' is not found. Mark the class as @Serializable or provide the serializer explicitly. at com.aallam.openai.client.internal.http.HttpTransport.handleException(HttpTransport.kt:46) at com.aallam.openai.client.internal.http.HttpTransport.perform(HttpTransport.kt:25) at com.aallam.openai.client.internal.http.HttpTransport$perform$1.invokeSuspend(HttpTransport.kt:0) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81) at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41) at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8757) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@a692934, androidx.compose.runtime.BroadcastFrameClock@b8c935d, StandaloneCoroutine{Cancelling}@6af44d2, AndroidUiDispatcher@c0479a3] Caused by: kotlinx.serialization.SerializationException: Serializer for class 'ChatCompletionRequest' is not found. Mark the class as @Serializable or provide the serializer explicitly. at kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered(Platform.common.kt:91) at kotlinx.serialization.SerializersKt__SerializersKt.serializer(Serializers.kt:149) at kotlinx.serialization.SerializersKt.serializer(Unknown Source:1) at io.ktor.serialization.kotlinx.SerializerLookupKt.guessSerializer(SerializerLookup.kt:44) at io.ktor.serialization.kotlinx.KotlinxSerializationBase.serialize$ktor_serialization_kotlinx(KotlinxSerializationBase.kt:34) at io.ktor.serialization.kotlinx.KotlinxSerializationConverter.serializeNullable(KotlinxSerializationConverter.kt:54) at io.ktor.client.plugins.contentnegotiation.ContentNegotiation.convertRequest$ktor_client_content_negotiation(ContentNegotiation.kt:156) at io.ktor.client.plugins.contentnegotiation.ContentNegotiation$Plugin$install$1.invokeSuspend(ContentNegotiation.kt:202) at io.ktor.client.plugins.contentnegotiation.ContentNegotiation$Plugin$install$1.invoke(ContentNegotiation.kt:0) at io.ktor.client.plugins.contentnegotiation.ContentNegotiation$Plugin$install$1.invoke(ContentNegotiation.kt:0) at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120) at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78) at io.ktor.util.pipeline.SuspendFunctionGun.proceedWith(SuspendFunctionGun.kt:88) at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invokeSuspend(HttpCallValidator.kt:130) at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invoke(HttpCallValidator.kt:0) at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invoke(HttpCallValidator.kt:0) at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120) at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78) at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invokeSuspend(HttpRequestLifecycle.kt:38) at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invoke(HttpRequestLifecycle.kt:0) 2023-04-04 10:41:06.532 21048-21048 AndroidRuntime com.carosoftware.cortex E at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invoke(HttpRequestLifecycle.kt:0) at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120) at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78) at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:98) at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77) at io.ktor.client.HttpClient.execute$ktor_client_core(HttpClient.kt:191) at io.ktor.client.statement.HttpStatement.executeUnsafe(HttpStatement.kt:108) at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:47) at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:62) at com.aallam.openai.client.internal.api.ChatApi$chatCompletion$2.invokeSuspend(ChatApi.kt:22) at com.aallam.openai.client.internal.api.ChatApi$chatCompletion$2.invoke(ChatApi.kt:0) at com.aallam.openai.client.internal.api.ChatApi$chatCompletion$2.invoke(ChatApi.kt:0) at com.aallam.openai.client.internal.http.HttpTransport.perform(HttpTransport.kt:22) at com.aallam.openai.client.internal.api.ChatApi.chatCompletion(ChatApi.kt:34) at com.aallam.openai.client.internal.OpenAIApi.chatCompletion(OpenAIApi.kt:0)
Environment
Additional Info
Tried adding the proguard rules in the proguard-rules.pro file like mentioned in the README:
`-keepattributes InnerClasses
-if @kotlinx.serialization.Serializable class
com.aallam.openai.api.**
{
static *$ *;
}
-keepnames class <1>$$serializer {
static <1>$$serializer INSTANCE;
}`
Beta Was this translation helpful? Give feedback.
All reactions