Skip to content

Commit

Permalink
Introducing a facade API : (#53)
Browse files Browse the repository at this point in the history
* Adding MP annotations to replace the LangChain4J ones.
* Registering AI services factories to use SmallRye default factories instead of Langchain4J default services.
* All examples now run with the MP annotations instead of Langchain4J annotations.
* Cleaning the poms

Signed-off-by: Emmanuel Hugonnet <[email protected]>
Co-authored-by: Buhake Sindi <[email protected]>
  • Loading branch information
ehsavoie and Buhake Sindi authored Oct 15, 2024
1 parent 78d97f5 commit b3b6794
Show file tree
Hide file tree
Showing 53 changed files with 1,824 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildNumber.properties
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

nb-configuration.xml
.idea


8 changes: 5 additions & 3 deletions examples/glassfish-car-booking/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
<version>${jakarta.jakartaee-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.smallrye.llm</groupId>
<artifactId>mp-ai-api</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.llm</groupId>
<artifactId>smallrye-llm-langchain4j-portable-extension</artifactId>
<version>1.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>jakarta.enterprise</groupId>
Expand Down Expand Up @@ -66,7 +69,6 @@
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j</artifactId>
<version>${dev.langchain4j.version}</version>
</dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
Expand All @@ -88,7 +90,7 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<scope>runtime</scope>
<version>2.0.9</version>
<version>2.0.16</version>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import java.util.Map;
import java.util.stream.Collectors;

import jakarta.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.ai.llm.Tool;

import dev.langchain4j.agent.tool.Tool;
import jakarta.enterprise.context.ApplicationScoped;
import lombok.extern.java.Log;

@ApplicationScoped
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.jefrajames.booking;

import dev.langchain4j.service.SystemMessage;
import io.smallrye.llm.spi.RegisterAIService;

import java.time.temporal.ChronoUnit;
import org.eclipse.microprofile.ai.llm.RegisterAIService;
import org.eclipse.microprofile.ai.llm.SystemMessage;

@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
@RegisterAIService(tools = BookingService.class, chatMemoryMaxMessages = 10, chatLanguageModelName = "chat-model")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.jefrajames.booking;

import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.UserMessage;
import dev.langchain4j.service.V;
import io.smallrye.llm.spi.RegisterAIService;
import org.eclipse.microprofile.ai.llm.RegisterAIService;
import org.eclipse.microprofile.ai.llm.SystemMessage;
import org.eclipse.microprofile.ai.llm.UserMessage;
import org.eclipse.microprofile.ai.llm.V;

@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
@RegisterAIService(chatMemoryMaxMessages = 5,

chatLanguageModelName = "chat-model")
public interface FraudAiService {

Expand Down
12 changes: 7 additions & 5 deletions examples/helidon-car-booking-portable-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,41 @@
<name>SmallRye LLM Examples: Helidon Car Booking Portable Extension</name>

<properties>
<version.io.helidon>4.0.7</version.io.helidon>
<mainClass>io.helidon.Main</mainClass>
<dev.langchain4j.version>0.34.0</dev.langchain4j.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.helidon</groupId>
<artifactId>helidon-bom</artifactId>
<version>4.0.7</version>
<version>${version.io.helidon}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.helidon</groupId>
<artifactId>helidon-dependencies</artifactId>
<version>4.0.7</version>
<version>${version.io.helidon}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.smallrye.llm</groupId>
<artifactId>mp-ai-api</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.llm</groupId>
<artifactId>smallrye-llm-langchain4j-portable-extension</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.smallrye.llm</groupId>
<artifactId>smallrye-llm-langchain4j-config-mpconfig</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- Adds all features available in MicroProfile -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import java.time.temporal.ChronoUnit;

import org.eclipse.microprofile.ai.llm.RegisterAIService;
import org.eclipse.microprofile.ai.llm.SystemMessage;
import org.eclipse.microprofile.faulttolerance.Fallback;
import org.eclipse.microprofile.faulttolerance.Retry;
import org.eclipse.microprofile.faulttolerance.Timeout;

import dev.langchain4j.service.SystemMessage;
import io.smallrye.llm.spi.RegisterAIService;

@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
@RegisterAIService(tools = BookingService.class, chatMemoryMaxMessages = 10, chatLanguageModelName = "chat-model")
public interface ChatAiService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

import java.time.temporal.ChronoUnit;

import org.eclipse.microprofile.ai.llm.RegisterAIService;
import org.eclipse.microprofile.ai.llm.SystemMessage;
import org.eclipse.microprofile.ai.llm.UserMessage;
import org.eclipse.microprofile.ai.llm.V;
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("""
Expand Down
12 changes: 7 additions & 5 deletions examples/helidon-car-booking/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,41 @@
<name>SmallRye LLM Examples: Helidon Car Booking</name>

<properties>
<version.io.helidon>4.0.7</version.io.helidon>
<mainClass>io.helidon.Main</mainClass>
<dev.langchain4j.version>0.34.0</dev.langchain4j.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.helidon</groupId>
<artifactId>helidon-bom</artifactId>
<version>4.0.7</version>
<version>${version.io.helidon}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.helidon</groupId>
<artifactId>helidon-dependencies</artifactId>
<version>4.0.7</version>
<version>${version.io.helidon}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.smallrye.llm</groupId>
<artifactId>mp-ai-api</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.llm</groupId>
<artifactId>smallrye-llm-langchain4j-buildcompatible-extension</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.smallrye.llm</groupId>
<artifactId>smallrye-llm-langchain4j-config-mpconfig</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- Adds all features available in MicroProfile -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import jakarta.enterprise.context.ApplicationScoped;

import dev.langchain4j.agent.tool.Tool;
import org.eclipse.microprofile.ai.llm.Tool;

import lombok.extern.java.Log;

@ApplicationScoped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import java.time.temporal.ChronoUnit;

import org.eclipse.microprofile.ai.llm.RegisterAIService;
import org.eclipse.microprofile.ai.llm.SystemMessage;
import org.eclipse.microprofile.faulttolerance.Fallback;
import org.eclipse.microprofile.faulttolerance.Retry;
import org.eclipse.microprofile.faulttolerance.Timeout;

import dev.langchain4j.service.SystemMessage;
import io.smallrye.llm.spi.RegisterAIService;

@SuppressWarnings("CdiManagedBeanInconsistencyInspection")
@RegisterAIService(tools = BookingService.class, chatMemoryMaxMessages = 10, chatLanguageModelName = "chat-model")
public interface ChatAiService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import java.time.temporal.ChronoUnit;

import org.eclipse.microprofile.ai.llm.RegisterAIService;
import org.eclipse.microprofile.ai.llm.SystemMessage;
import org.eclipse.microprofile.ai.llm.UserMessage;
import org.eclipse.microprofile.ai.llm.V;
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,

Expand Down
4 changes: 2 additions & 2 deletions examples/liberty-car-booking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ These are the steps to run this service.
## Application requirements:
- JDK 17 and higher
- Maven 3.9.9 and higher
- LangChain4j 0.33.0 or higher.
- LangChain4j 0.35.0 or higher.
- Testing against GPT 3.5 and 4.0 on a dedicated Azure instance (to be customized in your context).

Then you can access the application through the browser of your choice.
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit b3b6794

Please sign in to comment.