Giter Site home page Giter Site logo

langchain4j-searchbot's Introduction

Native LangChain4j Searchbot

This is a Java command-line chatbot application that leverages LangChain4j and the OPENAI API model "gpt-4".

LangChain4j is a Java version of LangChain to simplify integrating AI/LLM capabilities into Java applications.

The example is based on a LangChain4j tutorial. This application is enhanced with GraalVM Native Image Maven plugin that enables you to easily create a native executable for a Java application.

The goal of this project is to demonstrate:

  • how easy it is to ahead-of-time compile a CLI application that uses the LLM
  • the use of Profile-guided optimizations and SBOM Native Image features

Prerequisites

  • GraalVM JDK (sdk install java 21.0.2-graal)
  • Maven
  • OPENAI API key

NOTE: To interact with the OpenAI API, you need to either get and store an OPENAI API key in an environment variable OPENAI_API_KEY.

Package the Aplication into a Native Executable Using with Maven

  1. Clone this repository with Git and then enter it:

    git clone https://github.com/olyagpl/langchain4j-searchbot.git
    cd langchain4j-searchbot
  2. Compile and create a JAR file with all dependencies (required for Native Image):

    $ mvn clean package
  3. Create a native executable using the Maven plugin for Native Image:

    $ mvn -Pnative package

    This produces a Linux self-contained executable version of the seachbot!

  4. Interact with the seachbot:

    $ ./target/searchbot “Why should I visit Lviv?

Apply Profile-Guided Optimizations to Create an Optimized Native Executable

Profile-Guided Optimizations is the technique fetching the profiling information to the AOT compiler to improve the performance and file size of a native executable.

  1. Build an “instrumented” executable and run it to gather profiles:

    $ native-image -jar ./target/searchbot-1.0-jar-with-dependencies.jar --pgo-instrument -o ./target/searchbot-instrumented
    $ ./target/searchbot-instrumented “What is the weather today?
  2. Build a PGO-optimized executable that will pick up the gathered profiles, and run:

    $ native-image -jar ./target/searchbot-1.0-jar-with-dependencies.jar --pgo -o ./target/searchbot-pgo-optimized
    $ ./target/searchbot-pgo-optimized “What is JavaDay Lviv”

Learn More

langchain4j-searchbot's People

Contributors

olyagpl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.