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

Error when creating an OpenAI object #248

Open
notAnElephant opened this issue Nov 1, 2023 · 3 comments
Open

Error when creating an OpenAI object #248

notAnElephant opened this issue Nov 1, 2023 · 3 comments
Labels
awaiting-details Signifies the issue/PR is pending additional information or clarification for further action.

Comments

@notAnElephant
Copy link

notAnElephant commented Nov 1, 2023

Description

The following line always fails, despite being provided the dependencies in build.gradle.kts

val openAI = OpenAI("my-api-key")

Steps to Reproduce

  1. Create a new Jetbrains plugin using their plugin template
  2. Add the dependencies the following way:
    dependencies { implementation(platform("com.aallam.openai:openai-client-bom:3.5.0")) implementation("com.aallam.openai:openai-client") implementation("io.ktor:ktor-client-okhttp") }
  3. Try creating an OpenAI object with a valid api key

Environment

  • openai-kotlin version: 3.5.0
  • Kotlin version: 1.9.10 (but tried with lower versions)
  • OS: win 11

Additional Info

The error message and call stack:

java.util.ServiceConfigurationError: io.ktor.client.HttpClientEngineContainer: io.ktor.client.engine.cio.CIOEngineContainer not a subtype at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:593) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1244) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273) at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309) at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393) at kotlin.collections.CollectionsKt___CollectionsKt.toCollection(_Collections.kt:1295) at kotlin.collections.CollectionsKt___CollectionsKt.toMutableList(_Collections.kt:1328) at kotlin.collections.CollectionsKt___CollectionsKt.toList(_Collections.kt:1319) at io.ktor.client.HttpClientJvmKt.<clinit>(HttpClientJvm.kt:39) at com.aallam.openai.client.internal.HttpClientKt.createHttpClient(HttpClient.kt:24) at com.aallam.openai.client.OpenAIKt.OpenAI(OpenAI.kt:61) at com.aallam.openai.client.OpenAIKt.OpenAI(OpenAI.kt:41) at com.aallam.openai.client.OpenAIKt.OpenAI$default(OpenAI.kt:31) at myplugin.MyClass.actionPerformed(XYAction.kt:39)

It is a jetbrains IDE plugin, if that matters.

@aallam
Copy link
Owner

aallam commented Nov 1, 2023

Something is wrong; you are using ktor-client-okhttp as a dependency, but the error is about the CIO engine!

@aallam aallam added the awaiting-details Signifies the issue/PR is pending additional information or clarification for further action. label Nov 26, 2023
@voqaldev
Copy link
Contributor

voqaldev commented Nov 27, 2023

I had an issue like this in my JetBrains plugin. I switched to io.ktor:ktor-client-java-jvm and build OpenAI with:

OpenAI(
    OpenAIConfig(
        token = "token",
        engine = JavaHttpEngine(JavaHttpConfig())
    )
)

@notAnElephant
Copy link
Author

notAnElephant commented Dec 3, 2023

Thanks! Where can I exactly find JavaHttpEngine and JavaHttpConfig? What should I include?

Edit: it worked when using implementation instead of runtime, now I get another error regarding loader constraint violation: when resolving method 'org.slf4j.ILoggerFactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-details Signifies the issue/PR is pending additional information or clarification for further action.
Projects
None yet
Development

No branches or pull requests

3 participants