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

langchain4j: add support for AI service resolution by bean name #6866 #6899

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading