quarkiverse / quarkus-langchain4j

Quarkus Langchain4j extension
https://docs.quarkiverse.io/quarkus-langchain4j/dev/index.html
Apache License 2.0
146 stars 88 forks source link

ClassNotFoundException with langchain4j 0.17 and Quarkus 3.13.3 #820

Closed jonathanvila closed 2 months ago

jonathanvila commented 2 months ago

Describe the bug

After executing quarkus:dev on a new empty project directly downloaded from code.quarkus.io with langchain4j I receive a ClassNotFoundException

2024-08-21 16:27:39,108 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.NoClassDefFoundError: dev/langchain4j/service/output/ServiceOutputParser
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:534)
        at java.base/java.lang.Class.forName(Class.java:513)
        at io.quarkus.deployment.util.ServiceUtil.classesNamedIn(ServiceUtil.java:29)
        at io.quarkus.deployment.ExtensionLoader.loadStepsFrom(ExtensionLoader.java:160)
        at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:106)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:331)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:254)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:58)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:91)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:430)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:57)
        at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:138)
        at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:93)
        at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:131)
        at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)
Caused by: java.lang.ClassNotFoundException: dev.langchain4j.service.output.ServiceOutputParser
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
        at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:561)
        at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:509)
        ... 16 more

Expected behavior

to start the dev mode normally

Actual behavior

It shows the exception in the output

How to Reproduce?

  1. go to code.quarkus.io
  2. generate a project with langchain4j, ollama, rest, camel-langchain4j
  3. download and unzip
  4. mvn quarkus:dev

Output of uname -a or ver

Darwin MAC-L0153 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:04 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6020 arm64

Output of java -version

openjdk version "21.0.2" 2024-01-16 LTS OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode)

Quarkus version or git rev

3.13.3

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.4 (dfbb324ad4a7c8fb0bf182e6d91b0ae20e3d2dd9) Maven home: /Users/jonathan.vila/.sdkman/candidates/maven/current Java version: 21.0.2, vendor: Eclipse Adoptium, runtime: /Users/jonathan.vila/.sdkman/candidates/java/21.0.2-tem Default locale: en_GB, platform encoding: UTF-8 OS name: "mac os x", version: "14.6.1", arch: "aarch64", family: "mac"

Additional information

Changing it manually to Langchain4j and ollama to 0.16 fixes the issue

geoand commented 2 months ago

Thanks for reporting.

I'll take a look when I get back next week

geoand commented 2 months ago

I don't see camel-langchain4j in code.quarkus.io. What is the exact dependency to use?

jmartisk commented 2 months ago

I don't see camel-langchain4j in code.quarkus.io. What is the exact dependency to use?

I think this may be the source of the problem, Camel has its own langchain4j component, but it's not using Quarkus at all (it's not a Quarkus extension), and most likely depends on a different langchain4j version than the Quarkus version that is used, hence the compatibility problem

jonathanvila commented 2 months ago
    <dependency>
        <groupId>org.apache.camel.quarkus</groupId>
        <artifactId>camel-quarkus-langchain4j-chat</artifactId>
    </dependency>

[image: Screenshot 2024-08-26 at 09.06.46.png]

On Mon, Aug 26, 2024 at 8:00 AM Georgios Andrianakis < @.***> wrote:

I don't see camel-langchain4j in code.quarkus.io. What is the exact dependency to use?

— Reply to this email directly, view it on GitHub https://github.com/quarkiverse/quarkus-langchain4j/issues/820#issuecomment-2309384556, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOALERPA4NRKDYZ4G46CG3ZTK76RAVCNFSM6AAAAABM6EFNTWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBZGM4DINJVGY . You are receiving this because you authored the thread.Message ID: @.***>

geoand commented 2 months ago

Thanks.

The problem is exactly what @jmartisk described and there is nothing we can do on our side.

gsmet commented 2 months ago

@jamesnetherton @ppalaga maybe worth experimenting having a Camel Quarkus extension for the LangChain4j Camel component.

Also, I wonder if having a BOM for Quarkus LangChain4j would make sense? Similar to what was done here: https://github.com/quarkiverse/quarkus-amazon-services/blob/main/bom/pom.xml .

Note that we don't have a mechanism in the tooling to contribute the BOM automatically unfortunately.

geoand commented 2 months ago

Also, I wonder if having a BOM for Quarkus LangChain4j would make sense?

We already have one :)

jamesnetherton commented 2 months ago

maybe worth experimenting having a Camel Quarkus extension for the LangChain4j Camel component.

camel-quarkus-langchain4j-chat is a Quarkus extension.

depends on a different langchain4j version than the Quarkus version

They should be in sync. If you want to see which versions we align to, they're here:

https://github.com/apache/camel-quarkus/blob/3.13.x/pom.xml#L59

https://github.com/apache/camel-quarkus/blob/3.13.x/pom.xml#L138

There was a note added to the extension docs recently

https://camel.apache.org/camel-quarkus/next/reference/extensions/langchain4j-chat.html#extensions-langchain4j-chat-quarkus-langchain4j-bom

All of the camel-langchain4j bits are currently labelled as experimental, so there's plenty of room to improve things in this area.