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: java.lang.NoSuchMethodException with native compilation and ClientRequestFilter for Ollama #722

Closed
philippart-s opened this issue Jul 4, 2024 · 8 comments · Fixed by #725
Labels
bug Something isn't working

Comments

@philippart-s
Copy link
Contributor

Hi,
I followed the documentation to add a request filter to handle authentication for the Ollama models.

Everything work fine when I run the program in the standard JAva mode but I'v got an java.lang.NoSuchMethodException when I use the native application built with quarkus build --native.

I took the same code as mentionned in the documentation:

@Provider
public class OllamaClientAuthHeaderFilter implements ClientRequestFilter {

    @Override
    public void filter(ClientRequestContext requestContext) {
        requestContext.getHeaders().add("Authorization", "Bearer " + System.getenv("OVH_OLLAMA_API_KEY"));
    }
}

The stacktrace:

jakarta.enterprise.inject.CreationException: Error creating synthetic bean [FwyQP9Of9oZwwZhlQz1A4k1Ak7I]: java.lang.RuntimeException: java.lang.NoSuchMethodException: fr.wilda.picocli.sdk.ai.OllamaClientAuthHeaderFilter.<init>()
        at dev.langchain4j.model.chat.StreamingChatLanguageModel_FwyQP9Of9oZwwZhlQz1A4k1Ak7I_Synthetic_Bean.doCreate(Unknown Source)
        at dev.langchain4j.model.chat.StreamingChatLanguageModel_FwyQP9Of9oZwwZhlQz1A4k1Ak7I_Synthetic_Bean.create(Unknown Source)
        at dev.langchain4j.model.chat.StreamingChatLanguageModel_FwyQP9Of9oZwwZhlQz1A4k1Ak7I_Synthetic_Bean.create(Unknown Source)
        at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:119)
        at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:38)
        at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:35)
        at io.quarkus.arc.generator.Default_jakarta_enterprise_context_ApplicationScoped_ContextInstances.c10(Unknown Source)
        at io.quarkus.arc.generator.Default_jakarta_enterprise_context_ApplicationScoped_ContextInstances.computeIfAbsent(Unknown Source)
        at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:35)
        at io.quarkus.arc.impl.ClientProxies.getApplicationScopedDelegate(ClientProxies.java:21)
        at dev.langchain4j.model.chat.StreamingChatLanguageModel_FwyQP9Of9oZwwZhlQz1A4k1Ak7I_Synthetic_ClientProxy.arc$delegate(Unknown Source)
        at dev.langchain4j.model.chat.StreamingChatLanguageModel_FwyQP9Of9oZwwZhlQz1A4k1Ak7I_Synthetic_ClientProxy.generate(Unknown Source)
        at dev.langchain4j.service.AiServiceTokenStream$AiServiceOnStart.start(AiServiceTokenStream.java:90)
        at io.quarkiverse.langchain4j.runtime.aiservice.AiServiceMethodImplementationSupport$2.accept(AiServiceMethodImplementationSupport.java:172)
        at io.quarkiverse.langchain4j.runtime.aiservice.AiServiceMethodImplementationSupport$2.accept(AiServiceMethodImplementationSupport.java:160)
        at io.smallrye.context.impl.wrappers.SlowContextualConsumer.accept(SlowContextualConsumer.java:21)
        at io.smallrye.mutiny.operators.multi.builders.EmitterBasedMulti.subscribe(EmitterBasedMulti.java:67)
        at io.smallrye.mutiny.operators.AbstractMulti.subscribe(AbstractMulti.java:60)
        at io.smallrye.mutiny.helpers.BlockingIterable.lambda$stream$1(BlockingIterable.java:59)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:604)
        at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base@21.0.2/java.lang.Thread.runWith(Thread.java:1596)
        at java.base@21.0.2/java.lang.Thread.run(Thread.java:1583)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:833)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: fr.wilda.picocli.sdk.ai.OllamaClientAuthHeaderFilter.<init>()
        at org.jboss.resteasy.reactive.common.jaxrs.ConfigurationImpl.register(ConfigurationImpl.java:211)
        at org.jboss.resteasy.reactive.client.impl.ClientBuilderImpl.register(ClientBuilderImpl.java:351)
        at io.quarkus.rest.client.reactive.runtime.RestClientBuilderImpl.register(RestClientBuilderImpl.java:242)
        at io.quarkus.rest.client.reactive.runtime.RestClientBuilderImpl.build(RestClientBuilderImpl.java:352)
        at io.quarkus.rest.client.reactive.runtime.QuarkusRestClientBuilderImpl.build(QuarkusRestClientBuilderImpl.java:260)
        at io.quarkiverse.langchain4j.ollama.OllamaClient.<init>(OllamaClient.java:29)
        at io.quarkiverse.langchain4j.ollama.OllamaStreamingChatLanguageModel.<init>(OllamaStreamingChatLanguageModel.java:28)
        at io.quarkiverse.langchain4j.ollama.OllamaStreamingChatLanguageModel$Builder.build(OllamaStreamingChatLanguageModel.java:147)
        at io.quarkiverse.langchain4j.ollama.runtime.OllamaRecorder$5.get(OllamaRecorder.java:151)
        at io.quarkiverse.langchain4j.ollama.runtime.OllamaRecorder$5.get(OllamaRecorder.java:148)
        at io.quarkus.arc.runtime.ArcRecorder$4.apply(ArcRecorder.java:129)
        at io.quarkus.arc.runtime.ArcRecorder$4.apply(ArcRecorder.java:126)
        at dev.langchain4j.model.chat.StreamingChatLanguageModel_FwyQP9Of9oZwwZhlQz1A4k1Ak7I_Synthetic_Bean.createSynthetic(Unknown Source)
        ... 30 more
Caused by: java.lang.NoSuchMethodException: fr.wilda.picocli.sdk.ai.OllamaClientAuthHeaderFilter.<init>()
        at java.base@21.0.2/java.lang.Class.checkMethod(DynamicHub.java:1075)
        at java.base@21.0.2/java.lang.Class.getConstructor0(DynamicHub.java:1238)
        at java.base@21.0.2/java.lang.Class.getDeclaredConstructor(DynamicHub.java:2930)
        at org.jboss.resteasy.reactive.common.jaxrs.ConfigurationImpl.register(ConfigurationImpl.java:209)
        ... 42 more

Do you any idea what I'm doing wrong?

@geoand
Copy link
Collaborator

geoand commented Jul 4, 2024

Hi,

You can get over this with @RegisterForReflection on OllamaClientAuthHeaderFilter, but this is likely a Quarkus bug (which I'll have a look at soon)

@philippart-s
Copy link
Contributor Author

yes I've just test with @RegisterProvider on AI Service interface and it's fix also the issue.

Do you want a PR in the Ollama's documentation to mention this?

@geoand
Copy link
Collaborator

geoand commented Jul 4, 2024

Sure thing! Just mention that this won't be necessary in the near future

@philippart-s
Copy link
Contributor Author

@geoand PR created 😉 : #725

@geoand
Copy link
Collaborator

geoand commented Jul 5, 2024

Interestingly enough I was not able to reproduce the problem.

What version of Quarkus and Quarkus LangChain4j were you using?

@philippart-s
Copy link
Contributor Author

philippart-s commented Jul 5, 2024

Quarkus: 3.11.0
Quarkus-langchain4j: 0.15.1

Do you want I do a test with the last versions of Quarkus and Quarkus LangChain4j?

@geoand
Copy link
Collaborator

geoand commented Jul 5, 2024

Now I see what's happening....

This is definitely a bug in Quarkus

geoand added a commit to geoand/quarkus that referenced this issue Jul 5, 2024
When the server part of Quarkus REST is not included, prior to
this change, user's @Provider classes were not registered
for reflection

Relates to: quarkiverse/quarkus-langchain4j#722
@geoand
Copy link
Collaborator

geoand commented Jul 5, 2024

quarkusio/quarkus#41707 is the fix

gsmet pushed a commit to gsmet/quarkus that referenced this issue Jul 9, 2024
When the server part of Quarkus REST is not included, prior to
this change, user's @Provider classes were not registered
for reflection

Relates to: quarkiverse/quarkus-langchain4j#722

(cherry picked from commit 2a567df)
holly-cummins pushed a commit to holly-cummins/quarkus that referenced this issue Jul 31, 2024
When the server part of Quarkus REST is not included, prior to
this change, user's @Provider classes were not registered
for reflection

Relates to: quarkiverse/quarkus-langchain4j#722
gsmet pushed a commit to gsmet/quarkus that referenced this issue Aug 14, 2024
When the server part of Quarkus REST is not included, prior to
this change, user's @Provider classes were not registered
for reflection

Relates to: quarkiverse/quarkus-langchain4j#722

(cherry picked from commit 2a567df)
danielsoro pushed a commit to danielsoro/quarkus that referenced this issue Sep 20, 2024
When the server part of Quarkus REST is not included, prior to
this change, user's @Provider classes were not registered
for reflection

Relates to: quarkiverse/quarkus-langchain4j#722
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants