Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save skryvets/23deb010134c3c1b6971c0f77af2480e to your computer and use it in GitHub Desktop.

Select an option

Save skryvets/23deb010134c3c1b6971c0f77af2480e to your computer and use it in GitHub Desktop.

Revisions

  1. skryvets revised this gist Sep 27, 2024. 1 changed file with 4 additions and 19 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,3 @@



    # Building a Custom AI Chatbot with Spring Boot, React, and LangChain4j
    **Speaker:** Marcus Hellberg

    @@ -25,15 +22,12 @@ Incorporating LLMs into Java applications requires several tools and components
    - **Context Window (RAM):** Controls how much context is retained and processed during interactions.

    ![IMG_1187](https://gist.github.com/user-attachments/assets/65a4265d-a01f-4d03-8640-89b9318c7046)
    This diagram from the presentation illustrates the various components like Tools, Vector Store, CPU, and how they interact with the Context Window and Search Tools for optimal LLM use in a Java environment.

    ---

    ## AI for Engineers: APIs and Libraries

    - **LangChain4j**: A Java-based AI library facilitating LLM integrations.
    - **Hilla**: Exciting new features introduced here.

    - **Hilla**: A full-stack framework for building modern web applications, combining Spring Boot on the server side and TypeScript on the client side. It simplifies the development of reactive web apps.
    ---

    ## Agent Autonomy Levels
    @@ -46,8 +40,7 @@ This diagram from the presentation illustrates the various components like Tools
    - Most business apps will fall into this category.
    3. **Fully Autonomous**: Fully capable of making decisions without human intervention.

    ![Agent Autonomy Levels](./img/agent-autonomy.jpg)
    This graph illustrates the spectrum of agent autonomy, ranging from chatbots to fully autonomous agents, with **Copilot** being a middle ground.
    ![IMG_1188](https://gist.github.com/user-attachments/assets/2743c39a-8e64-4325-a962-3ce8b4f9987e)

    ---

    @@ -64,9 +57,7 @@ This graph illustrates the spectrum of agent autonomy, ranging from chatbots to
    - **Definition**: A token is a chunk of text (ranging from a character to a word) used for processing by the AI.
    - **Token Count**: The token count is typically about 25% greater than the word count.

    ![Context Window](./img/context-window.jpg)
    This diagram highlights the structure of a context window, showcasing how system prompts, history, user prompts, and relevant information are stored while ensuring room for responses.

    ![IMG_1189](https://gist.github.com/user-attachments/assets/5fe24083-2c9c-45c0-874e-c1d0721b8966)
    ---

    ## RAG (Retrieval Augmented Generation)
    @@ -84,15 +75,9 @@ This diagram highlights the structure of a context window, showcasing how system
    ---

    ## LangChain4j Specifics

    - **LangChain Interface**: Works similarly to Spring Data JPA, allowing developers to query LLMs.
    - **Reactive Nature**: LangChain allows real-time token streaming during responses.

    ### Key Components
    1. **System Prompt**: Defines a new AI identity for a session.
    2. **Config**: Provides access to the necessary data and configuration parameters.

    ### Code Snippet: LangChain4j Configuration
    ```java!
    LangChain4jConfig.java
    2. **Config**: Provides access to the necessary data and configuration parameters.
  2. skryvets created this gist Sep 27, 2024.
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,98 @@



    # Building a Custom AI Chatbot with Spring Boot, React, and LangChain4j
    **Speaker:** Marcus Hellberg

    **YouTube Link:** [Watch the video](https://www.youtube.com/watch?v=1dXKlRs5pbY)
    **GitHub Repository:** [java-ai-playground](https://github.com/marcushellberg/java-ai-playground)

    ---

    ## Key Concepts and Insights

    ### Vaading Perspective
    - **LLMs (Large Language Models)** are generic, but your business is unique.

    ### Tools for Java Developers to Build AI-Powered Applications
    Incorporating LLMs into Java applications requires several tools and components to manage resources efficiently:

    - **Tools (Programs):** Manage various AI processing functions.
    - **Vector Store (Disk):** Stores embeddings on disk or other storage mediums for retrieval.
    - **CPU (Processing):** Powers the execution of LLMs.
    - **Search Tools (Ethernet):** Helps retrieve relevant information.
    - **Other LLMs:** Can be integrated to provide more advanced functionalities.
    - **Context Window (RAM):** Controls how much context is retained and processed during interactions.

    ![IMG_1187](https://gist.github.com/user-attachments/assets/65a4265d-a01f-4d03-8640-89b9318c7046)
    This diagram from the presentation illustrates the various components like Tools, Vector Store, CPU, and how they interact with the Context Window and Search Tools for optimal LLM use in a Java environment.

    ---

    ## AI for Engineers: APIs and Libraries

    - **LangChain4j**: A Java-based AI library facilitating LLM integrations.
    - **Hilla**: Exciting new features introduced here.

    ---

    ## Agent Autonomy Levels

    1. **Chatbot**:
    - Knows a lot of things but lacks specific domain expertise.
    2. **Copilot**:
    - Acts on your behalf in predefined scenarios.
    - Monitors and assists users but doesn’t control the entire workflow.
    - Most business apps will fall into this category.
    3. **Fully Autonomous**: Fully capable of making decisions without human intervention.

    ![Agent Autonomy Levels](./img/agent-autonomy.jpg)
    This graph illustrates the spectrum of agent autonomy, ranging from chatbots to fully autonomous agents, with **Copilot** being a middle ground.

    ---

    ## Context Window
    - A **context window** is essential for determining the amount of information processed by the LLM in one session.
    - Components include:
    - **System Prompt**: Sets the behavior or identity of the AI.
    - **History**: Previous interactions.
    - **Prompt**: The user's input.
    - **Relevant Information**: Critical to the specific task at hand.
    - **Response Space**: Ensuring enough space is left for the AI's response.

    ### Tokens
    - **Definition**: A token is a chunk of text (ranging from a character to a word) used for processing by the AI.
    - **Token Count**: The token count is typically about 25% greater than the word count.

    ![Context Window](./img/context-window.jpg)
    This diagram highlights the structure of a context window, showcasing how system prompts, history, user prompts, and relevant information are stored while ensuring room for responses.

    ---

    ## RAG (Retrieval Augmented Generation)
    - **Definition**: A method where the AI retrieves specific case-related information before generating responses.
    - **LLMs Know Two Things**:
    1. Content they’re trained on.
    2. Specific information retrieved via **RAG**.

    ---

    ## Embedding Model
    - **Purpose**: Transforms text into vectors for processing.
    - **Vector Store**: Essential for storing and retrieving relevant vectorized information.

    ---

    ## LangChain4j Specifics

    - **LangChain Interface**: Works similarly to Spring Data JPA, allowing developers to query LLMs.
    - **Reactive Nature**: LangChain allows real-time token streaming during responses.

    ### Key Components
    1. **System Prompt**: Defines a new AI identity for a session.
    2. **Config**: Provides access to the necessary data and configuration parameters.

    ### Code Snippet: LangChain4j Configuration
    ```java!
    LangChain4jConfig.java