From 175038122515e3b94405e9429b6c36f70f216915 Mon Sep 17 00:00:00 2001 From: Gilbert Kwan Date: Fri, 14 Feb 2025 10:08:48 -0500 Subject: [PATCH] Update jakartaee-microprofile-example to use MicroProfile 7 (#144) update the jakartaee-microprofile-example - use MicroProfile 7 - replace the default chat model to `mistralai/Mistral-Nemo-Instruct-2407` - update the Maven project to use Java 21 and latest dependencies Signed-off-by: Gilbert Kwan --- jakartaee-microprofile-example/README.md | 6 +++--- jakartaee-microprofile-example/pom.xml | 18 +++++++++--------- .../langchain4j/example/chat/ChatAgent.java | 4 +++- .../src/main/liberty/config/server.xml | 16 +++++++++------- .../META-INF/microprofile-config.properties | 3 ++- .../dev/langchan4j/example/ChatServiceIT.java | 2 +- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/jakartaee-microprofile-example/README.md b/jakartaee-microprofile-example/README.md index 095a01ca..576bd09a 100644 --- a/jakartaee-microprofile-example/README.md +++ b/jakartaee-microprofile-example/README.md @@ -3,7 +3,7 @@ This example demonstrates LangChain4J in a Jakarta EE / MicroProfile application ## Prerequisites: -- [Java 17](https://developer.ibm.com/languages/java/semeru-runtimes/downloads) +- [Java 21](https://developer.ibm.com/languages/java/semeru-runtimes/downloads) - Hugging Face API Key - Sign up and log in to https://huggingface.co. - Go to [Access Tokens](https://huggingface.co/settings/tokens). @@ -21,7 +21,7 @@ cd langchain4j-examples/jakartaee-microprofile-example Set the following environment variables: ``` -export JAVA_HOME= +export JAVA_HOME= export HUGGING_FACE_API_KEY= ``` @@ -44,7 +44,7 @@ Use the Maven wrapper to start the application by using the [Liberty dev mode](h Which are the most used models? ``` - ``` - any documentation? + show me the documentation ``` diff --git a/jakartaee-microprofile-example/pom.xml b/jakartaee-microprofile-example/pom.xml index 269c1f27..f6311ec4 100644 --- a/jakartaee-microprofile-example/pom.xml +++ b/jakartaee-microprofile-example/pom.xml @@ -10,8 +10,8 @@ war - 17 - 17 + 21 + 21 UTF-8 @@ -25,7 +25,7 @@ org.eclipse.microprofile microprofile - 6.1 + 7.0 pom provided @@ -42,24 +42,24 @@ org.slf4j slf4j-reload4j - 2.0.12 + 2.0.16 org.slf4j slf4j-api - 2.0.12 + 2.0.16 org.junit.jupiter junit-jupiter - 5.10.2 + 5.11.4 test org.jboss.resteasy resteasy-client - 6.2.10.Final + 6.2.11.Final test @@ -94,7 +94,7 @@ io.openliberty.tools liberty-maven-plugin - 3.11.1 + 3.11.2 @@ -106,7 +106,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 3.2.5 + 3.5.2 diff --git a/jakartaee-microprofile-example/src/main/java/dev/langchain4j/example/chat/ChatAgent.java b/jakartaee-microprofile-example/src/main/java/dev/langchain4j/example/chat/ChatAgent.java index c6b0cf03..7dae7c6a 100644 --- a/jakartaee-microprofile-example/src/main/java/dev/langchain4j/example/chat/ChatAgent.java +++ b/jakartaee-microprofile-example/src/main/java/dev/langchain4j/example/chat/ChatAgent.java @@ -65,7 +65,9 @@ public Assistant getAssistant() { } public String chat(String sessionId, String message) { - return getAssistant().chat(sessionId, message).trim(); + String reply = getAssistant().chat(sessionId, message).trim(); + int i = reply.lastIndexOf(message); + return i > 0 ? reply.substring(i) : reply; } } diff --git a/jakartaee-microprofile-example/src/main/liberty/config/server.xml b/jakartaee-microprofile-example/src/main/liberty/config/server.xml index 4f39323a..319b3730 100644 --- a/jakartaee-microprofile-example/src/main/liberty/config/server.xml +++ b/jakartaee-microprofile-example/src/main/liberty/config/server.xml @@ -2,13 +2,15 @@ - cdi-4.0 - jsonb-3.0 - mpConfig-3.1 - mpMetrics-5.1 - mpOpenAPI-3.1 - restfulWS-3.1 - websocket-2.1 + jakartaee-10.0 + microprofile-7.0 + cdi + jsonb + mpConfig + mpMetrics + mpOpenAPI + restfulWS + websocket diff --git a/jakartaee-microprofile-example/src/main/resources/META-INF/microprofile-config.properties b/jakartaee-microprofile-example/src/main/resources/META-INF/microprofile-config.properties index 9d3427ce..5c87675e 100644 --- a/jakartaee-microprofile-example/src/main/resources/META-INF/microprofile-config.properties +++ b/jakartaee-microprofile-example/src/main/resources/META-INF/microprofile-config.properties @@ -1,5 +1,6 @@ hugging.face.api.key=set it by env variable -chat.model.id=NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO +#chat.model.id=meta-llama/Llama-3.2-1B-Instruct +chat.model.id=mistralai/Mistral-Nemo-Instruct-2407 chat.model.timeout=120 chat.model.max.token=200 chat.model.temperature=1.0 diff --git a/jakartaee-microprofile-example/src/test/java/it/dev/langchan4j/example/ChatServiceIT.java b/jakartaee-microprofile-example/src/test/java/it/dev/langchan4j/example/ChatServiceIT.java index e5fc7169..3c87269d 100644 --- a/jakartaee-microprofile-example/src/test/java/it/dev/langchan4j/example/ChatServiceIT.java +++ b/jakartaee-microprofile-example/src/test/java/it/dev/langchan4j/example/ChatServiceIT.java @@ -21,7 +21,7 @@ public void testChat() throws Exception { countDown = new CountDownLatch(1); URI uri = new URI("ws://localhost:9080/chat"); ChatClient client = new ChatClient(uri); - client.sendMessage("When was langchain4j launched?"); + client.sendMessage("When was the LangChain4j launched?"); countDown.await(120, TimeUnit.SECONDS); client.close(); }