Skip to content

Commit 4fd4160

Browse files
Enable the Fault Tolerance Interceptor.
1 parent 13135c7 commit 4fd4160

File tree

17 files changed

+345
-152
lines changed

17 files changed

+345
-152
lines changed

examples/helidon-car-booking/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
<properties>
1414
<mainClass>io.helidon.Main</mainClass>
15-
<dev.langchain4j.version>0.34.0</dev.langchain4j.version>
1615
</properties>
1716

1817
<dependencyManagement>

examples/liberty-car-booking/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ To package the application in JVM mode run: `mvn package`.
3939

4040
## Configuration
4141

42-
All configuration is centralized in `microprofile-config.properties`(found is `resources\META-INF` folder) and can be redefined using environment variables.
42+
All configuration is centralized in `microprofile-config.properties` (found is `resources\META-INF` folder) and can be redefined using environment variables.
4343

4444
## Running the application
4545

examples/liberty-car-booking/pom.xml

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<microprofile-api.version>6.1</microprofile-api.version>
2525
<compiler-plugin.version>3.13.0</compiler-plugin.version>
2626
<war-plugin.version>3.4.0</war-plugin.version>
27-
<dev.langchain4j.version>0.34.0</dev.langchain4j.version>
2827

2928
<!-- We need only javac to use the release parameter. OpenLiberty doesn't depend on maven-compiler-plugin.' -->
3029
<maven.compiler.source combine.self="override" />
@@ -36,7 +35,6 @@
3635

3736
<dependencyManagement>
3837
<dependencies>
39-
<!-- https://mvnrepository.com/artifact/jakarta.platform/jakarta.jakartaee-api -->
4038
<dependency>
4139
<groupId>jakarta.platform</groupId>
4240
<artifactId>jakarta.jakartaee-api</artifactId>
@@ -51,46 +49,24 @@
5149
<type>pom</type>
5250
<scope>provided</scope>
5351
</dependency>
54-
55-
<!--
56-
<dependency>
57-
<groupId>io.smallrye.llm.liberty-bundle</groupId>
58-
<artifactId>smallrye-llm-langchain4j-features-bom</artifactId>
59-
<version>1.0.0-SNAPSHOT</version>
60-
<type>pom</type>
61-
</dependency>
62-
-->
63-
<!--
64-
<dependency>
65-
<groupId>io.smallrye.llm</groupId>
66-
<artifactId>smallrye-llm-langchain4j-buildcompatible-extension</artifactId>
67-
<version>1.0.0-SNAPSHOT</version>
68-
</dependency>
69-
-->
70-
<!-- https://mvnrepository.com/artifact/ai.djl.huggingface/tokenizers -->
71-
<dependency>
72-
<groupId>ai.djl.huggingface</groupId>
73-
<artifactId>tokenizers</artifactId>
74-
<version>0.30.0</version>
75-
</dependency>
76-
</dependencies>
77-
</dependencyManagement>
52+
<<<<<<< HEAD
7853

79-
<dependencies>
80-
<!-- https://mvnrepository.com/artifact/jakarta.platform/jakarta.jakartaee-api -->
81-
<!--
82-
<dependency>
83-
<groupId>jakarta.platform</groupId>
84-
<artifactId>jakarta.jakartaee-api</artifactId>
85-
<scope>provided</scope>
86-
</dependency>
87-
-->
88-
89-
<dependency>
90-
<groupId>org.eclipse.microprofile</groupId>
91-
<artifactId>microprofile</artifactId>
92-
<type>pom</type>
93-
</dependency>
54+
=======
55+
56+
>>>>>>> dcf66ac (Enable the Fault Tolerance Interceptor.)
57+
<dependency>
58+
<groupId>ai.djl.huggingface</groupId>
59+
<artifactId>tokenizers</artifactId>
60+
<version>0.30.0</version>
61+
</dependency>
62+
</dependencies>
63+
</dependencyManagement>
64+
<dependencies>
65+
<dependency>
66+
<groupId>org.eclipse.microprofile</groupId>
67+
<artifactId>microprofile</artifactId>
68+
<type>pom</type>
69+
</dependency>
9470

9571
<dependency>
9672
<groupId>io.smallrye.llm</groupId>
@@ -102,27 +78,9 @@
10278
<artifactId>smallrye-llm-langchain4j-portable-extension</artifactId>
10379
</dependency>
10480

105-
<!--
106-
<dependency>
107-
<groupId>io.smallrye.llm</groupId>
108-
<artifactId>smallrye-llm-langchain4j-buildcompatible-extension</artifactId>
109-
</dependency>
110-
-->
111-
112-
<!--
113-
<dependency>
114-
<groupId>io.smallrye.llm.liberty-bundle</groupId>
115-
<artifactId>smallrye-llm-langchain4j-feature</artifactId>
116-
<version>1.0.0-SNAPSHOT</version>
117-
<type>pom</type>
118-
<scope>provided</scope>
119-
</dependency>
120-
-->
121-
12281
<dependency>
12382
<groupId>org.projectlombok</groupId>
12483
<artifactId>lombok</artifactId>
125-
<scope>provided</scope>
12684
</dependency>
12785

12886
<!-- langchain4j dependencies -->
@@ -136,7 +94,6 @@
13694
<artifactId>langchain4j-hugging-face</artifactId>
13795
</dependency>
13896

139-
<!-- https://mvnrepository.com/artifact/dev.langchain4j/langchain4j-azure-open-ai -->
14097
<dependency>
14198
<groupId>dev.langchain4j</groupId>
14299
<artifactId>langchain4j-azure-open-ai</artifactId>
@@ -152,7 +109,6 @@
152109
<artifactId>langchain4j-embeddings-all-minilm-l6-v2</artifactId>
153110
</dependency>
154111

155-
<!-- https://mvnrepository.com/artifact/ai.djl.huggingface/tokenizers -->
156112
<dependency>
157113
<groupId>ai.djl.huggingface</groupId>
158114
<artifactId>tokenizers</artifactId>
@@ -162,15 +118,13 @@
162118
<dependency>
163119
<groupId>org.slf4j</groupId>
164120
<artifactId>slf4j-jdk14</artifactId>
165-
<scope>runtime</scope>
166121
</dependency>
167122
</dependencies>
168123

169124
<build>
170125
<finalName>${project.artifactId}</finalName>
171126
<pluginManagement>
172127
<plugins>
173-
<!-- https://mvnrepository.com/artifact/io.openliberty.tools/liberty-maven-plugin -->
174128
<plugin>
175129
<groupId>io.openliberty.tools</groupId>
176130
<artifactId>liberty-maven-plugin</artifactId>

examples/liberty-car-booking/src/main/java/io/jefrajames/booking/CarBookingResource.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public String chatWithAssistant(
4040
@Path("/fraud")
4141
public FraudResponse detectFraudForCustomer(
4242
@QueryParam("name") String name,
43-
4443
@QueryParam("surname") String surname) {
4544
return fraudService.detectFraudForCustomer(name, surname);
4645
}
47-
4846
}

examples/liberty-car-booking/src/main/java/io/jefrajames/booking/ChatAiService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.time.temporal.ChronoUnit;
44

5+
import jakarta.enterprise.context.ApplicationScoped;
6+
57
import org.eclipse.microprofile.faulttolerance.Fallback;
68
import org.eclipse.microprofile.faulttolerance.Retry;
79
import org.eclipse.microprofile.faulttolerance.Timeout;
@@ -10,7 +12,7 @@
1012
import io.smallrye.llm.spi.RegisterAIService;
1113

1214
//@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
13-
@RegisterAIService(tools = BookingService.class, chatMemoryMaxMessages = 10)
15+
@RegisterAIService(scope = ApplicationScoped.class, tools = BookingService.class, chatMemoryMaxMessages = 10)
1416
public interface ChatAiService {
1517

1618
@SystemMessage("""

examples/liberty-car-booking/src/main/java/io/jefrajames/booking/DocRagIngestor.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
import java.io.File;
66
import java.util.List;
77

8+
import jakarta.enterprise.context.ApplicationScoped;
9+
import jakarta.enterprise.context.Initialized;
10+
import jakarta.enterprise.event.Observes;
11+
import jakarta.enterprise.inject.Produces;
12+
import jakarta.inject.Inject;
13+
814
import org.eclipse.microprofile.config.inject.ConfigProperty;
915

1016
import dev.langchain4j.data.document.Document;
@@ -13,13 +19,9 @@
1319
import dev.langchain4j.data.segment.TextSegment;
1420
import dev.langchain4j.model.embedding.EmbeddingModel;
1521
import dev.langchain4j.model.embedding.onnx.allminilml6v2.AllMiniLmL6V2EmbeddingModel;
22+
import dev.langchain4j.store.embedding.EmbeddingStore;
1623
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
1724
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
18-
import jakarta.enterprise.context.ApplicationScoped;
19-
import jakarta.enterprise.context.Initialized;
20-
import jakarta.enterprise.event.Observes;
21-
import jakarta.enterprise.inject.Produces;
22-
import jakarta.inject.Inject;
2325
import lombok.extern.java.Log;
2426

2527
@Log
@@ -32,9 +34,7 @@ public class DocRagIngestor {
3234

3335
// Used by ContentRetriever
3436
@Produces
35-
private InMemoryEmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>();
36-
37-
// private File docs = new File(System.getProperty("docragdir"));
37+
private EmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>();
3838

3939
@Inject
4040
@ConfigProperty(name = "app.docs-for-rag.dir")
@@ -60,9 +60,4 @@ public void ingest(@Observes @Initialized(ApplicationScoped.class) Object pointl
6060
log.info(String.format("DEMO %d documents ingested in %d msec", docs.size(),
6161
System.currentTimeMillis() - start));
6262
}
63-
64-
public static void main(String[] args) {
65-
66-
System.out.println(InMemoryEmbeddingStore.class.getInterfaces()[0]);
67-
}
6863
}

examples/liberty-car-booking/src/main/java/io/jefrajames/booking/FraudAiService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package io.jefrajames.booking;
22

3+
import java.time.temporal.ChronoUnit;
4+
5+
import org.eclipse.microprofile.faulttolerance.Fallback;
6+
import org.eclipse.microprofile.faulttolerance.Retry;
7+
import org.eclipse.microprofile.faulttolerance.Timeout;
8+
39
import dev.langchain4j.service.SystemMessage;
410
import dev.langchain4j.service.UserMessage;
511
import dev.langchain4j.service.V;
612
import io.smallrye.llm.spi.RegisterAIService;
713

8-
@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
9-
@RegisterAIService(chatMemoryMaxMessages = 5,
10-
11-
chatLanguageModelName = "chat-model")
14+
@RegisterAIService(chatMemoryMaxMessages = 5, chatLanguageModelName = "chat-model")
1215
public interface FraudAiService {
1316

1417
@SystemMessage("""
@@ -44,6 +47,9 @@ A booking overlap (and hence a fraud) occurs when there are several bookings for
4447
4548
You must not wrap JSON response in backticks, markdown, or in any other way, but return it as plain text.
4649
""")
50+
@Timeout(unit = ChronoUnit.MINUTES, value = 5)
51+
@Retry(maxRetries = 2)
52+
@Fallback(fallbackMethod = "fraudFallback")
4753
FraudResponse detectFraudForCustomer(@V("name") String name, @V("surname") String surname);
4854

4955
default FraudResponse fraudFallback(String name, String surname) {

examples/liberty-car-booking/src/main/resources/META-INF/microprofile-config.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ smallrye.llm.plugin.chat-model.config.temperature=0.1
1010
smallrye.llm.plugin.chat-model.config.topP=0.1
1111
smallrye.llm.plugin.chat-model.config.timeout=120s
1212
smallrye.llm.plugin.chat-model.config.max-retries=2
13-
#smallrye.llm.plugin.chat-model.config.logRequestsAndResponsess=false
13+
#smallrye.llm.plugin.chat-model.config.logRequestsAndResponses=true
1414

1515

1616
smallrye.llm.plugin.docRagRetriever.class=dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever

examples/quarkus-car-booking/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ smallrye.llm.plugin.chat-model.config.temperature=0.1
1111
smallrye.llm.plugin.chat-model.config.topP=0.1
1212
smallrye.llm.plugin.chat-model.config.timeout=120s
1313
smallrye.llm.plugin.chat-model.config.max-retries=2
14-
#smallrye.llm.plugin.chat-model.config.logRequestsAndResponsess=false
14+
#smallrye.llm.plugin.chat-model.config.logRequestsAndResponses=false
1515

1616

1717
smallrye.llm.plugin.docRagRetriever.class=dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever

0 commit comments

Comments
 (0)