openai-kotlin icon indicating copy to clipboard operation
openai-kotlin copied to clipboard

java.lang.NoClassDefFoundError: io/ktor/client/plugins/contentnegotiation/ContentNegotiation

Open saravr opened this issue 11 months ago • 6 comments

Description

Facing this class not found exception:

Exception in thread "main" java.lang.NoClassDefFoundError: io/ktor/client/plugins/contentnegotiation/ContentNegotiation at com.aallam.openai.client.internal.HttpClientKt$createHttpClient$configuration$1.invoke(HttpClient.kt:34) at com.aallam.openai.client.internal.HttpClientKt$createHttpClient$configuration$1.invoke(HttpClient.kt:24) at io.ktor.client.HttpClientKt.HttpClient(HttpClient.kt:42) at io.ktor.client.HttpClientJvmKt.HttpClient(HttpClientJvm.kt:23) at com.aallam.openai.client.internal.HttpClientKt.createHttpClient(HttpClient.kt:89) at com.aallam.openai.client.OpenAIKt.OpenAI(OpenAI.kt:60)

when I use both kotlin serialization (which uses server side ContentNegotiation) and OpenAI client whose HTTP client uses client side ContentNegotiation. I think that is what is causing this error.

    implementation("io.ktor:ktor-server-core:$kotlin_version")
    implementation("io.ktor:ktor-server-netty:$kotlin_version")
    implementation("io.ktor:ktor-server-host-common:$kotlin_version")
    implementation("ch.qos.logback:logback-classic:$logback_version")
    implementation("io.ktor:ktor-server-config-yaml")

    implementation("io.ktor:ktor-client-core:$ktor_version")
    implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
    implementation("io.ktor:ktor-client-serialization:$ktor_version") // For serialization support

    // kotlin serialization
    implementation("io.ktor:ktor-serialization:$ktor_version")
    implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
    implementation("io.ktor:ktor-server-content-negotiation:$ktor_version")

    // CORS, server call logging, koin, MongoDB, firebase .. removed for clarity

    // Open AI
    implementation("com.aallam.openai:openai-client:3.8.2")

There was another issue reported and closed, however, resolution pointed to Ktor 3+ which I am already on. Any idea what may I be missing?

Environment

  • openai-kotlin version: 3.8.2
  • Kotlin version: 2.0.21
  • OS: MacOS
  • Ktor version: 3.0.0 / 3.0.3

Additional Info

Add any other relevant context here.

saravr avatar Dec 20 '24 01:12 saravr

Experiencing the same issue with a similar setup as described above.

IntrinsiCrypto avatar Jan 10 '25 22:01 IntrinsiCrypto

The same issue

dzdenya avatar Jan 11 '25 20:01 dzdenya

the same issue

alexgallardo11 avatar Jan 20 '25 09:01 alexgallardo11

The solution is to use beta version - 4.0.0-beta01

dzdenya avatar Jan 20 '25 09:01 dzdenya

The solution is to use beta version - 4.0.0-beta01

thank you it worked

akardas16 avatar Jan 21 '25 11:01 akardas16

Same issue here

Petrulak avatar Feb 12 '25 12:02 Petrulak