// Do not edit directly!
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
[id="extensions-langchain4j"]
= langChain4j
:linkattrs:
:cq-artifact-id: camel-quarkus-langchain4j
:cq-native-supported: true
:cq-status: Experimental
:cq-status-deprecation: Experimental
:cq-description: LangChain4j high level api usage with Camel Quarkus
:cq-deprecated: false
:cq-jvm-since: 3.16.0
:cq-native-since: 3.16.0

ifeval::[{doc-show-badges} == true]
[.badges]
[.badge-key]##JVM since##[.badge-supported]##3.16.0## [.badge-key]##Native since##[.badge-supported]##3.16.0##
endif::[]

LangChain4j high level api usage with Camel Quarkus

[id="extensions-langchain4j-maven-coordinates"]
== Maven coordinates

https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-langchain4j[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"]

Or add the coordinates to your existing project:

[source,xml]
----
<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-langchain4j</artifactId>
</dependency>
----
ifeval::[{doc-show-user-guide-link} == true]
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
endif::[]

[id="extensions-langchain4j-quarkus-langchain4j-bom"]
== 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:
[source,xml]
----
<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.

[id="extensions-langchain4j-additional-camel-quarkus-configuration"]
== Additional Camel Quarkus configuration

[id="extensions-langchain4j-configuration-using-camel-annotations-from-langchain4j-ai-service-method-parameters"]
=== 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 xref:manual::parameter-binding-annotations.adoc[manual].

[id="extensions-langchain4j-configuration-resolving-ai-services-by-interface"]
=== Resolving AI services by interface

With the `camel-quarkus-langchain4j` extension, the AI services are resolvable by interface when called from a `bean` statement.

For instance, let's define an AI service below:

```
@ApplicationScoped
@RegisterAiService
public interface MyAiService {

    @UserMessage("My Prompt")
    @Handler
    String chat(String question);
}
```

The AI service could then be invoked from a Camel route like this:

```
@Override
public void configure() {
  from("...")
    .bean(MyAiService.class);
}
```

[id="extensions-langchain4j-configuration-resolving-ai-services-by-bean-name"]
=== Resolving AI services by bean name

The AI services are also resolvable by bean name when called from a `bean` statement.

For instance, let's define an AI service below:

```
@ApplicationScoped
@Named("aiServiceResolvedByName")
@RegisterAiService
public interface AiServiceResolvedByName {

    @UserMessage("My prompt")
    @Handler
    String chatByName(String input);
}
```

The AI service could then be invoked from a Camel route as below:

```
@Override
public void configure() {
  from("...")
    .bean("aiServiceResolvedByName");
}
```

