langChain4j

JVM since3.16.0 Native since3.16.0

LangChain4j high level api usage with Camel Quarkus

Maven coordinates

Or add the coordinates to your existing project:

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-langchain4j</artifactId>
</dependency>

Check the User guide for more information about writing Camel Quarkus applications.

Ensure Quarkus LangChain4j dependencies version alignment with the Bom

In order to ensure alignment across all Quarkus and LangChain4j related dependencies, it is recommended to import the Quarkus LangChain4j bom as below:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.quarkiverse.langchain4j</groupId>
      <artifactId>quarkus-langchain4j-bom</artifactId>
      <version>${insert your version here}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
  ...
</dependencyManagement>

Note that the import order is paramount when using maven dependencyManagement. As such, one might need to import the quarkus-langchain4j-bom before other related Camel and Quarkus boms.

Additional Camel Quarkus configuration

Using camel annotations from LangChain4j AI service method parameters

The camel-quarkus-langchain4j extension make it possible to use camel parameter binding annotations with LangChain4j AI services.

Let’s see an example below:

@RegisterAiService
@ApplicationScoped
public interface CustomAiService {

    @UserMessage("An LLM prompt that can use the method parameter {myHeaderInjectedIntoPrompt}.")
    @Handler
    String invokeLlm(@Header("myHeaderName") String myHeaderInjectedIntoPrompt);
}

You can find more details about Camel Parameter Binding annotations in the manual.