Skip to content

Commit

Permalink
Added chatbot-easy-rag sample from Quarkus LangChain4J.
Browse files Browse the repository at this point in the history
  • Loading branch information
lreimer committed Dec 3, 2024
1 parent a248292 commit ba11d7b
Show file tree
Hide file tree
Showing 27 changed files with 1,500 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ gradle-app.setting
.classpath

.vscode/
.DS_Store
.DS_Store
target/
5 changes: 5 additions & 0 deletions chatbot-easy-rag/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
!target/quarkus-app/*
46 changes: 46 additions & 0 deletions chatbot-easy-rag/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
release.properties
.flattened-pom.xml

# Eclipse
.project
.classpath
.settings/
bin/

# IntelliJ
.idea
*.ipr
*.iml
*.iws

# NetBeans
nb-configuration.xml

# Visual Studio Code
.vscode
.factorypath

# OSX
.DS_Store

# Vim
*.swp
*.swo

# patch
*.orig
*.rej

# Local environment
.env

# Plugin directory
/.quarkus/cli/plugins/
# TLS Certificates
.certs/
easy-rag-embeddings.json
1 change: 1 addition & 0 deletions chatbot-easy-rag/.mvn/wrapper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
maven-wrapper.jar
93 changes: 93 additions & 0 deletions chatbot-easy-rag/.mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.io.IOException;
import java.io.InputStream;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.ThreadLocalRandom;

public final class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "3.3.2";

private static final boolean VERBOSE = Boolean.parseBoolean(System.getenv("MVNW_VERBOSE"));

public static void main(String[] args) {
log("Apache Maven Wrapper Downloader " + WRAPPER_VERSION);

if (args.length != 2) {
System.err.println(" - ERROR wrapperUrl or wrapperJarPath parameter missing");
System.exit(1);
}

try {
log(" - Downloader started");
final URL wrapperUrl = URI.create(args[0]).toURL();
final String jarPath = args[1].replace("..", ""); // Sanitize path
final Path wrapperJarPath = Paths.get(jarPath).toAbsolutePath().normalize();
downloadFileFromURL(wrapperUrl, wrapperJarPath);
log("Done");
} catch (IOException e) {
System.err.println("- Error downloading: " + e.getMessage());
if (VERBOSE) {
e.printStackTrace();
}
System.exit(1);
}
}

private static void downloadFileFromURL(URL wrapperUrl, Path wrapperJarPath)
throws IOException {
log(" - Downloading to: " + wrapperJarPath);
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
final String username = System.getenv("MVNW_USERNAME");
final char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
Path temp = wrapperJarPath
.getParent()
.resolve(wrapperJarPath.getFileName() + "."
+ Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp");
try (InputStream inStream = wrapperUrl.openStream()) {
Files.copy(inStream, temp, StandardCopyOption.REPLACE_EXISTING);
Files.move(temp, wrapperJarPath, StandardCopyOption.REPLACE_EXISTING);
} finally {
Files.deleteIfExists(temp);
}
log(" - Downloader complete");
}

private static void log(String msg) {
if (VERBOSE) {
System.out.println(msg);
}
}

}
20 changes: 20 additions & 0 deletions chatbot-easy-rag/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.2
distributionType=source
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar
61 changes: 61 additions & 0 deletions chatbot-easy-rag/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Chatbot example with Easy RAG

This example demonstrates how to create a simple chatbot with RAG using
`quarkus-langchain4j` and specifically the Easy RAG extension.
For more information about Easy RAG, refer to the file
`docs/modules/ROOT/pages/easy-rag.adoc`.

## Running the example

A prerequisite to running this example is to provide your OpenAI API key.

```
export QUARKUS_LANGCHAIN4J_OPENAI_API_KEY=<your-openai-api-key>
```

Then, simply run the project in Dev mode:

```
mvn quarkus:dev
```

## Using the example


Open your browser and navigate to http://localhost:8080. Click the red robot
in the bottom right corner to open the chat window.

The chatbot is a conversational agent that uses information from the files
in `src/main/resources/catalog` to answer your questions about banking
products. More information about how it works is shown on the webpage.

## Using other model providers

### Compatible OpenAI serving infrastructure

Add `quarkus.langchain4j.openai.base-url=http://yourerver` to `application.properties`.

In this case, `quarkus.langchain4j.openai.api-key` is generally not needed.

### Ollama


Replace:

```xml
<dependency>
<groupId>io.quarkiverse.langchain4j</groupId>
<artifactId>quarkus-langchain4j-openai</artifactId>
<version>${quarkus-langchain4j.version}</version>
</dependency>
```

with

```xml
<dependency>
<groupId>io.quarkiverse.langchain4j</groupId>
<artifactId>quarkus-langchain4j-ollama</artifactId>
<version>${quarkus-langchain4j.version}</version>
</dependency>
```
Binary file not shown.
4 changes: 4 additions & 0 deletions chatbot-easy-rag/catalog/retirement-money-market.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The "Retirement Money Market" saving account offers individual retirement account holders tax advantages and diversification.

The is no monthly maintenance fee.
The minimum deposit to open an account is $100, or a 25$ automatic monthly deposit.
Binary file not shown.
11 changes: 11 additions & 0 deletions chatbot-easy-rag/catalog/standard-saving-account.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The "Standard savings account" offers a first-time savers and those with low balances a hassle-free way to save.
The monthly maintenance fee is waived for the first 12 months. After that, the fee is waived if you maintain a minimum daily balance of $300 or more, or if you set up an automatic transfer of $25 or more from a checking account to your savings account each month.
The minimum opening deposit is $25.

The "Standard savings account" offers the following benefits:

* $0 ATM transaction and surcharge fees
* $0 overdraft protection transfer fees made from an eligible linked checking account
* Account alerts: Set up email or text message reminders about low balances, transactions, payments and more
* Automated savings options: Link your saving accounts to another bank account and set up recurring transfers
* E-Statements: quickly access your saving account statement online anytime. They are automatically archived and they are free.
Loading

0 comments on commit ba11d7b

Please sign in to comment.