Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug with optimizers] #147

Closed
AndraxDev opened this issue Apr 1, 2023 · 2 comments · Fixed by #149
Closed

[Bug with optimizers] #147

AndraxDev opened this issue Apr 1, 2023 · 2 comments · Fixed by #149
Labels
enhancement New feature or request

Comments

@AndraxDev
Copy link
Contributor

Description

Mark the class as @serializable or provide the serializer explicitly exception occurs when optimizers and obfuscators are used.

Steps to Reproduce

  1. Compile this API with R8 or ProGuard optimizer
  2. Obfuscate the solution

Environment

  • openai-kotlin version: 3.2.0
  • Kotlin version: 1.7.21
  • OS: Windows 11

Additional Info

Code sample:

val completions: Flow<ChatCompletionChunk> = ai!!.chatCompletions(chatCompletionRequest)

Note

It works fine without optimizers

Stacktrace:

Process: org.teslasoft.assistant, PID: 766
b6.h: Serializer for class 'b' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
  at c4.h.I(Unknown Source:32)
  at kotlinx.coroutines.b0.Y(Unknown Source:25)
  at n7.o.k(Unknown Source:235)
  at n7.j.l(Unknown Source:31)
  at j5.a.h(Unknown Source:8)
  at kotlinx.coroutines.j0.run(Unknown Source:102)
  at android.os.Handler.handleCallback(Handler.java:942)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loopOnce(Looper.java:201)
  at android.os.Looper.loop(Looper.java:288)
  at android.app.ActivityThread.main(ActivityThread.java:7913)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
Suppressed: kotlinx.coroutines.h0: [r1{Cancelling}@117e083, Dispatchers.Main]
@AndraxDev AndraxDev changed the title [Brief Issue Description] [Bug with optimizers] Apr 1, 2023
@AndraxDev
Copy link
Contributor Author

Can't add "bug" label. Maybe I haven't permissions?

@aallam aallam added the enhancement New feature or request label Apr 2, 2023
@aallam
Copy link
Owner

aallam commented Apr 2, 2023

You can incorporate the following rules:

-keepattributes InnerClasses

-if @kotlinx.serialization.Serializable class
com.aallam.openai.api.**,
com.aallam.openai.client.internal.data.**

{
    static **$* *;
}
-keepnames class <1>$$serializer {
    static <1>$$serializer INSTANCE;
}

The upcoming release should include these rules directly within the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants