Skip to content

Commit

Permalink
langchain4j: add support for AI service resolution by bean name #6866 (
Browse files Browse the repository at this point in the history
  • Loading branch information
aldettinger authored Jan 9, 2025
1 parent 7e2dcad commit ed40164
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
31 changes: 30 additions & 1 deletion docs/modules/ROOT/pages/reference/extensions/langchain4j.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ With the `camel-quarkus-langchain4j` extension, the AI services are resolvable b
For instance, let's define an AI service below:

```
@RegisterAiService
@ApplicationScoped
@RegisterAiService
public interface MyAiService {

@UserMessage("My Prompt")
Expand All @@ -111,3 +111,32 @@ public void configure() {
}
```

[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");
}
```

30 changes: 29 additions & 1 deletion extensions/langchain4j/runtime/src/main/doc/configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ With the `camel-quarkus-langchain4j` extension, the AI services are resolvable b
For instance, let's define an AI service below:

```
@RegisterAiService
@ApplicationScoped
@RegisterAiService
public interface MyAiService {

@UserMessage("My Prompt")
Expand All @@ -43,3 +43,31 @@ public void configure() {
.bean(MyAiService.class);
}
```

=== 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");
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -47,7 +46,6 @@ void aiServiceShouldBeResolvedByInterface() {
}

@Test
@Disabled("https://github.com/apache/camel-quarkus/issues/6866")
void aiServiceShouldBeResolvedByName() {
RestAssured.given()
.get("/langchain4j/ai-service-should-be-resolvable-by-name")
Expand Down

0 comments on commit ed40164

Please sign in to comment.