Skip to content

Commit

Permalink
Merge pull request #34 from smallrye/20-liberty-feature
Browse files Browse the repository at this point in the history
20 liberty feature
  • Loading branch information
Emily-Jiang authored Sep 26, 2024
2 parents ed25557 + 1948850 commit 3815068
Show file tree
Hide file tree
Showing 39 changed files with 1,616 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/helidon-car-booking-portable-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dev.langchain4j.version>0.33.0</dev.langchain4j.version>
<dev.langchain4j.version>0.34.0</dev.langchain4j.version>
</properties>

<dependencies>
Expand Down
18 changes: 9 additions & 9 deletions examples/helidon-car-booking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ It is derived from my [Quarkus-LangChain4j](https://github.com/jefrajames/car-bo
It is based on a simplified car booking application inspired from the [Java meets AI](https://www.youtube.com/watch?v=BD1MSLbs9KE) talk from Lize Raes at Devoxx Belgium 2023. The car booking company is called "Miles of Smiles" and the application exposes two AI services:

. a chat service to freely discuss with a customer assistant
. a fraud service to determine if a customer is a frauder.
. a fraud service to determine if a customer is a fraudster.

For the sake of simplicity, there is no database interaction, the application is standalone and can be used "as is". Of course thanks to Quarkus, it can easily be extended according to your needs.

Warning: you must first configure the application to connect to an LLM that supports Function Calling (see Environment Variables below).

## Technical context

The project has been developped and tested with:
The project has been developed and tested with:

* Java 22 (Temurin OpenJDK distro)
* Helidon 4.0.7
Expand All @@ -32,19 +32,19 @@ During my tests, GPT 3.5 has proved to be faster but less precise en consistent

Quarkus provides a deep integration with LangChain4j thanks to a specific [extension](https://docs.quarkiverse.io/quarkus-langchain4j/dev/index.html).

In particular, it provides a powerful @RegisterAiService annotation and network interractions with LLMs are managed with its own RestClient.
In particular, it provides a powerful @RegisterAiService annotation and network interactions with LLMs are managed with its own RestClient.

This example is based on a standard usage of LangChain4j with Helidon. There is no such deep integration.

I've added 3 technical classes to manage "the glue" (more or less the equivallent of @RegisterAiService):
I've added 3 technical classes to manage "the glue" (more or less the equivalent of `@RegisterAiService`):

* ModelFactory: generates an OpenAI Chat model
* ChatAiServiceFactory: generates a Chat assistant
* FraudAiServiceFactrory: generates a Fraud assistant.

I've been obliged to turn FraudResponse in a POJO. It seems that Google GSON, used to deserialize OpenAI responses does not support Java Record.

In contrast with Quarkus, network interractions with LLMs are based on standard LangChain4j. For instance, the Azure SDK is used with Azure OpenAI.
In contrast with Quarkus, network interactions with LLMs are based on standard LangChain4j. For instance, the Azure SDK is used with Azure OpenAI.

## Packaging the application

Expand All @@ -66,19 +66,19 @@ Note: native mode not yet tested.

The application exposes a REST API documented with OpenAPI.

To interract with the application go to: http://localhost:8080/openapi/ui.
To interact with the application go to: http://localhost:8080/openapi/ui.


Typical questions you can ask in the Chat:

* Hello, how can you help me?
* What is your list of cars?
* What is your cancelation policy?
* What is your cancellation policy?
* What is your fleet size? Be short please.
* How many electric cars do you have?
* My name is James Bond, please list my bookings
* Is my booking 123-456 cancelable?
* Is my booking 234-567 cancelable?
* Is my booking 123-456 cancellable?
* Is my booking 234-567 cancellable?
* Can you check the duration please?
* I'm James Bond, can I cancel all my booking 345-678?
* Can you provide the details of all my bookings?
Expand Down
2 changes: 1 addition & 1 deletion examples/helidon-car-booking/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dev.langchain4j.version>0.33.0</dev.langchain4j.version>
<dev.langchain4j.version>0.34.0</dev.langchain4j.version>
</properties>

<dependencies>
Expand Down
75 changes: 75 additions & 0 deletions examples/liberty-car-booking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Car Booking (Open Liberty)

These are the steps to run this service.

1. Go to the root `smallrye-llm` directory, then build it using the command:
> `mvn clean install -e`
2. Once the project is built, move to directory `cd examples/liberty-car-booking` and run the following command to install the bundle as a user liberty feature:
> `mvn liberty:dev -e`

## Application requirements:
- JDK 17 and higher
- Maven 3.9.9 and higher
- LangChain4j 0.33.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.

## Differences with Quarkus-LangChain4j

Quarkus provides a deep integration with LangChain4j thanks to a specific [extension](https://docs.quarkiverse.io/quarkus-langchain4j/dev/index.html).

In particular, it provides a powerful `@RegisterAiService` annotation and network interactions with LLMs are managed with its own RestClient.

This example is based on a standard usage of LangChain4j with Helidon. There is no such deep integration.

I've added 3 technical classes to manage "the glue" (more or less the equivalent of `@RegisterAiService`):

* ModelFactory: generates an OpenAI Chat model
* ChatAiServiceFactory: generates a Chat assistant
* FraudAiServiceFactory: generates a Fraud assistant.

I've been obliged to turn FraudResponse in a POJO. It seems that Google GSON, used to deserialize OpenAI responses does not support Java Record.

In contrast with Quarkus, network interactions with LLMs are based on standard LangChain4j. For instance, the Azure SDK is used with Azure OpenAI.

## Packaging the application

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.

## Running the application

To run in dev mode with OpenLiberty: Run the following command in the CLI: `mvn liberty:dev`.

To run in JVM mode (after packaging): `mvn liberty:start`. To stop the running server: `mvn liberty:stop`.


## Playing with the application

The application exposes a REST API documented with OpenAPI.

To interact with the application go to: [http://localhost:9080/openapi/ui](http://localhost:8080/openapi/ui).


Typical questions you can ask in the Chat:

* Hello, how can you help me?
* What is your list of cars?
* What is your cancellation policy?
* What is your fleet size? Be short please.
* How many electric cars do you have?
* My name is James Bond, please list my bookings
* Is my booking 123-456 cancelable?
* Is my booking 234-567 cancelable?
* Can you check the duration please?
* I'm James Bond, can I cancel all my booking 345-678?
* Can you provide the details of all my bookings?

You can ask fraud for:

* James Bond
* Emilio Largo
22 changes: 22 additions & 0 deletions examples/liberty-car-booking/docs-for-rag/apple-pie-recipe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Special Apple Pie Recipe

Here's a very brief overview of what you can expect when you make this special apple pie at home:

1.Make the filling:
On the stove, make a paste with flour and butter.
Add the sugar and water and bring to a boil.
Simmer, then remove from heat.

2.Assemble the pie:
Press one crust into a pie plate.
Place the sliced apples on the bottom crust.
Use the top crust to make a lattice crust according to the recipe below.
Pour the butter-sugar mixture over the lattice crust.

3.Bake the pie:
Bake the pie in a preheated oven until the apples are soft and the crust is golden brown.

4.How Long to Bake Apple Pie
You'll bake the pie at 425 degrees F for 15 minutes, then you'll reduce the temperature to 350 degrees F and continue baking for 35-45 minutes.
All in all, the pie will bake for about one hour, give or take a few minutes.
You'll know the pie is done when the apples are soft and the crust is a beautiful golden brown color.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Miles of Smiles general information and main figures

1) Population: 500 employees
2) Geography: 40 countries accross Europe, America and Asia
3) Fleet: 1000 cars, 10% electric
4) Satisfaction rating: 99%
11 changes: 11 additions & 0 deletions examples/liberty-car-booking/docs-for-rag/list-of-cars.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Miles of Smiles Car Rental list of cars

Aston Martin
BMW
DS
Mercedes
Renault
Peugeot
Porsche
Tesla
Toyota
37 changes: 37 additions & 0 deletions examples/liberty-car-booking/docs-for-rag/terms-of-use.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Miles of Smiles Car Rental Services Terms of Use

1. Introduction
These Terms of Service (“Terms”) govern the access or use by you, an individual, from within any country in the world, of applications, websites, content, products, and services (“Services”) made available by Miles of Smiles Car Rental Services, a company registered in the United States of America.

2. The Services
Miles of Smiles rents out vehicles to the end user. We reserve the right to temporarily or permanently discontinue the Services at any time and are not liable for any modification, suspension or discontinuation of the Services.

3. Bookings
3.1 Users may make a booking through our website or mobile application.
3.2 You must provide accurate, current and complete information during the reservation process. You are responsible for all charges incurred under your account.
3.3 All bookings are subject to vehicle availability.

4. Cancellation Policy
4.1 Reservations lasting less than three days cannot be cancelled
4.2 Reservations can be cancelled up to 7 days prior to the start of the booking period.

5. Use of Vehicle
5.1 All cars rented from Miles of Smiles must not be used:
for any illegal purpose or in connection with any criminal offense.
for teaching someone to drive.
in any race, rally or contest.
while under the influence of alcohol or drugs.

6. Liability
6.1 Users will be held liable for any damage, loss, or theft that occurs during the rental period.
6.2 We do not accept liability for any indirect or consequential loss, damage, or expense including but not limited to loss of profits.

7. Governing Law
These terms will be governed by and construed in accordance with the laws of the United States of America, and any disputes relating to these terms will be subject to the exclusive jurisdiction of the courts of United States.

8. Changes to These Terms
We may revise these terms of use at any time by amending this page. You are expected to check this page from time to time to take notice of any changes we made.

9. Acceptance of These Terms
By using the Services, you acknowledge that you have read and understand these Terms and agree to be bound by them.
If you do not agree to these Terms, please do not use or access our Services.
Loading

0 comments on commit 3815068

Please sign in to comment.