diff --git a/examples/helidon-car-booking/pom.xml b/examples/helidon-car-booking/pom.xml
index 3e1d666..d564ed2 100644
--- a/examples/helidon-car-booking/pom.xml
+++ b/examples/helidon-car-booking/pom.xml
@@ -12,7 +12,6 @@
io.helidon.Main
- 0.34.0
diff --git a/examples/liberty-car-booking/README.md b/examples/liberty-car-booking/README.md
index 92561c7..3d61654 100644
--- a/examples/liberty-car-booking/README.md
+++ b/examples/liberty-car-booking/README.md
@@ -39,7 +39,7 @@ To package the application in JVM mode run: `mvn package`.
## Configuration
-All configuration is centralized in `microprofile-config.properties`(found is `resources\META-INF` folder) and can be redefined using environment variables.
+All configuration is centralized in `microprofile-config.properties` (found is `resources\META-INF` folder) and can be redefined using environment variables.
## Running the application
diff --git a/examples/liberty-car-booking/pom.xml b/examples/liberty-car-booking/pom.xml
index 69ef05c..4ce601d 100644
--- a/examples/liberty-car-booking/pom.xml
+++ b/examples/liberty-car-booking/pom.xml
@@ -17,20 +17,24 @@
-
- UTF-8
- UTF-8
- 10.0.0
- 6.1
- 3.13.0
- 3.4.0
-
- ${project.build.directory}/liberty/wlp/usr/shared/resources/lib/
-
+
+ UTF-8
+ UTF-8
+ 10.0.0
+ 6.1
+ 3.13.0
+ 3.4.0
+
+
+
+
+
+
+ ${project.build.directory}/liberty/wlp/usr/shared/resources/lib/
+
-
jakarta.platform
jakarta.jakartaee-api
@@ -45,46 +49,19 @@
pom
provided
-
-
-
-
-
- ai.djl.huggingface
- tokenizers
- 0.30.0
-
-
-
-
-
-
-
-
-
- org.eclipse.microprofile
- microprofile
- pom
-
+
+ ai.djl.huggingface
+ tokenizers
+ 0.30.0
+
+
+
+
+
+ org.eclipse.microprofile
+ microprofile
+ pom
+
io.smallrye.llm
@@ -96,27 +73,9 @@
smallrye-llm-langchain4j-portable-extension
-
-
-
-
org.projectlombok
lombok
- provided
@@ -130,7 +89,6 @@
langchain4j-hugging-face
-
dev.langchain4j
langchain4j-azure-open-ai
@@ -146,7 +104,6 @@
langchain4j-embeddings-all-minilm-l6-v2
-
ai.djl.huggingface
tokenizers
@@ -156,7 +113,6 @@
org.slf4j
slf4j-jdk14
- runtime
@@ -164,7 +120,6 @@
${project.artifactId}
-
io.openliberty.tools
liberty-maven-plugin
diff --git a/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/CarBookingResource.java b/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/CarBookingResource.java
index 8faf5f9..1922a3b 100644
--- a/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/CarBookingResource.java
+++ b/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/CarBookingResource.java
@@ -40,9 +40,7 @@ public String chatWithAssistant(
@Path("/fraud")
public FraudResponse detectFraudForCustomer(
@QueryParam("name") String name,
-
@QueryParam("surname") String surname) {
return fraudService.detectFraudForCustomer(name, surname);
}
-
}
diff --git a/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/ChatAiService.java b/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/ChatAiService.java
index bc6892f..660e718 100644
--- a/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/ChatAiService.java
+++ b/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/ChatAiService.java
@@ -2,6 +2,8 @@
import java.time.temporal.ChronoUnit;
+import jakarta.enterprise.context.ApplicationScoped;
+
import org.eclipse.microprofile.faulttolerance.Fallback;
import org.eclipse.microprofile.faulttolerance.Retry;
import org.eclipse.microprofile.faulttolerance.Timeout;
@@ -10,7 +12,7 @@
import io.smallrye.llm.spi.RegisterAIService;
//@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
-@RegisterAIService(tools = BookingService.class, chatMemoryMaxMessages = 10)
+@RegisterAIService(scope = ApplicationScoped.class, tools = BookingService.class, chatMemoryMaxMessages = 10)
public interface ChatAiService {
@SystemMessage("""
diff --git a/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/DocRagIngestor.java b/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/DocRagIngestor.java
index 70d7ff1..f50a395 100644
--- a/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/DocRagIngestor.java
+++ b/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/DocRagIngestor.java
@@ -16,8 +16,10 @@
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.parser.TextDocumentParser;
import dev.langchain4j.data.document.splitter.DocumentSplitters;
+import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.model.embedding.onnx.allminilml6v2.AllMiniLmL6V2EmbeddingModel;
+import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import lombok.extern.java.Log;
@@ -32,9 +34,7 @@ public class DocRagIngestor {
// Used by ContentRetriever
@Produces
- private InMemoryEmbeddingStore embeddingStore = new InMemoryEmbeddingStore<>();
-
- // private File docs = new File(System.getProperty("docragdir"));
+ private EmbeddingStore embeddingStore = new InMemoryEmbeddingStore<>();
@Inject
@ConfigProperty(name = "app.docs-for-rag.dir")
@@ -60,9 +60,4 @@ public void ingest(@Observes @Initialized(ApplicationScoped.class) Object pointl
log.info(String.format("DEMO %d documents ingested in %d msec", docs.size(),
System.currentTimeMillis() - start));
}
-
- public static void main(String[] args) {
-
- System.out.println(InMemoryEmbeddingStore.class.getInterfaces()[0]);
- }
}
diff --git a/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/FraudAiService.java b/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/FraudAiService.java
index 68488de..bb33cd4 100644
--- a/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/FraudAiService.java
+++ b/examples/liberty-car-booking/src/main/java/io/jefrajames/booking/FraudAiService.java
@@ -1,14 +1,17 @@
package io.jefrajames.booking;
+import java.time.temporal.ChronoUnit;
+
+import org.eclipse.microprofile.faulttolerance.Fallback;
+import org.eclipse.microprofile.faulttolerance.Retry;
+import org.eclipse.microprofile.faulttolerance.Timeout;
+
import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.UserMessage;
import dev.langchain4j.service.V;
import io.smallrye.llm.spi.RegisterAIService;
-@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
-@RegisterAIService(chatMemoryMaxMessages = 5,
-
- chatLanguageModelName = "chat-model")
+@RegisterAIService(chatMemoryMaxMessages = 5, chatLanguageModelName = "chat-model")
public interface FraudAiService {
@SystemMessage("""
@@ -44,6 +47,9 @@ A booking overlap (and hence a fraud) occurs when there are several bookings for
You must not wrap JSON response in backticks, markdown, or in any other way, but return it as plain text.
""")
+ @Timeout(unit = ChronoUnit.MINUTES, value = 5)
+ @Retry(maxRetries = 2)
+ @Fallback(fallbackMethod = "fraudFallback")
FraudResponse detectFraudForCustomer(@V("name") String name, @V("surname") String surname);
default FraudResponse fraudFallback(String name, String surname) {
diff --git a/examples/liberty-car-booking/src/main/resources/META-INF/microprofile-config.properties b/examples/liberty-car-booking/src/main/resources/META-INF/microprofile-config.properties
index c793531..89d8303 100644
--- a/examples/liberty-car-booking/src/main/resources/META-INF/microprofile-config.properties
+++ b/examples/liberty-car-booking/src/main/resources/META-INF/microprofile-config.properties
@@ -10,7 +10,7 @@ smallrye.llm.plugin.chat-model.config.temperature=0.1
smallrye.llm.plugin.chat-model.config.topP=0.1
smallrye.llm.plugin.chat-model.config.timeout=120s
smallrye.llm.plugin.chat-model.config.max-retries=2
-#smallrye.llm.plugin.chat-model.config.logRequestsAndResponsess=false
+#smallrye.llm.plugin.chat-model.config.logRequestsAndResponses=true
smallrye.llm.plugin.docRagRetriever.class=dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever
diff --git a/examples/quarkus-car-booking/src/main/resources/application.properties b/examples/quarkus-car-booking/src/main/resources/application.properties
index 08f08e3..d9ab556 100644
--- a/examples/quarkus-car-booking/src/main/resources/application.properties
+++ b/examples/quarkus-car-booking/src/main/resources/application.properties
@@ -11,7 +11,7 @@ smallrye.llm.plugin.chat-model.config.temperature=0.1
smallrye.llm.plugin.chat-model.config.topP=0.1
smallrye.llm.plugin.chat-model.config.timeout=120s
smallrye.llm.plugin.chat-model.config.max-retries=2
-#smallrye.llm.plugin.chat-model.config.logRequestsAndResponsess=false
+#smallrye.llm.plugin.chat-model.config.logRequestsAndResponses=false
smallrye.llm.plugin.docRagRetriever.class=dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever
diff --git a/smallrye-llm-langchain4j-core/src/main/java/io/smallrye/llm/aiservice/CommonAIServiceCreator.java b/smallrye-llm-langchain4j-core/src/main/java/io/smallrye/llm/aiservice/CommonAIServiceCreator.java
index 35546d9..1db83a6 100644
--- a/smallrye-llm-langchain4j-core/src/main/java/io/smallrye/llm/aiservice/CommonAIServiceCreator.java
+++ b/smallrye-llm-langchain4j-core/src/main/java/io/smallrye/llm/aiservice/CommonAIServiceCreator.java
@@ -1,6 +1,8 @@
package io.smallrye.llm.aiservice;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.List;
@@ -9,9 +11,15 @@
import org.jboss.logging.Logger;
+import dev.langchain4j.memory.chat.ChatMemoryProvider;
+import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
+import dev.langchain4j.model.moderation.ModerationModel;
import dev.langchain4j.rag.content.retriever.ContentRetriever;
import dev.langchain4j.service.AiServices;
+import dev.langchain4j.service.MemoryId;
+import dev.langchain4j.service.Moderate;
+import dev.langchain4j.store.memory.chat.ChatMemoryStore;
import io.smallrye.llm.core.langchain4j.core.config.spi.ChatMemoryFactoryProvider;
import io.smallrye.llm.spi.RegisterAIService;
@@ -20,7 +28,7 @@ public class CommonAIServiceCreator {
private static final Logger LOGGER = Logger.getLogger(CommonAIServiceCreator.class);
@SuppressWarnings("unchecked")
- public static Object create(Instance