Skip to content

abdulrahman305/genai-stack

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GenAI Stack

The GenAI Stack will get you started building your own GenAI application in no time. The demo applications can serve as inspiration or as a starting point. Learn more about the details in the introduction blog post.

Configure

Create a .env file from the environment template file env.example

Available variables:

Variable Name Default value Description
OLLAMA_BASE_URL http://host.docker.internal:11434 REQUIRED - URL to Ollama LLM API
NEO4J_URI neo4j://database:7687 REQUIRED - URL to Neo4j database
NEO4J_USERNAME neo4j REQUIRED - Username for Neo4j database
NEO4J_PASSWORD password REQUIRED - Password for Neo4j database
LLM llama2 REQUIRED - Can be any Ollama model tag, or gpt-4 or gpt-3.5 or claudev2
EMBEDDING_MODEL sentence_transformer REQUIRED - Can be sentence_transformer, openai, aws, ollama or google-genai-embedding-001
AWS_ACCESS_KEY_ID REQUIRED - Only if LLM=claudev2 or embedding_model=aws
AWS_SECRET_ACCESS_KEY REQUIRED - Only if LLM=claudev2 or embedding_model=aws
AWS_DEFAULT_REGION REQUIRED - Only if LLM=claudev2 or embedding_model=aws
OPENAI_API_KEY REQUIRED - Only if LLM=gpt-4 or LLM=gpt-3.5 or embedding_model=openai
GOOGLE_API_KEY REQUIRED - Only required when using GoogleGenai LLM or embedding model google-genai-embedding-001
LANGCHAIN_ENDPOINT "https://api.smith.langchain.com" OPTIONAL - URL to Langchain Smith API
LANGCHAIN_TRACING_V2 false OPTIONAL - Enable Langchain tracing v2
LANGCHAIN_PROJECT OPTIONAL - Langchain project name
LANGCHAIN_API_KEY OPTIONAL - Langchain API key

LLM Configuration

MacOS and Linux users can use any LLM that's available via Ollama. Check the "tags" section under the model page you want to use on https://ollama.ai/library and write the tag for the value of the environment variable LLM= in the .env file. All platforms can use GPT-3.5-turbo and GPT-4 (bring your own API keys for OpenAI models).

MacOS Install Ollama on MacOS and start it before running docker compose up using ollama serve in a separate terminal.

Linux No need to install Ollama manually, it will run in a container as part of the stack when running with the Linux profile: run docker compose --profile linux up. Make sure to set the OLLAMA_BASE_URL=http://llm:11434 in the .env file when using Ollama docker container.

To use the Linux-GPU profile: run docker compose --profile linux-gpu up. Also change OLLAMA_BASE_URL=http://llm-gpu:11434 in the .env file.

Windows Ollama now supports Windows. Install Ollama on Windows and start it before running docker compose up using ollama serve in a separate terminal. Alternatively, Windows users can generate an OpenAI API key and configure the stack to use gpt-3.5 or gpt-4 in the .env file.

Develop

Warning

There is a performance issue that impacts python applications in the 4.24.x releases of Docker Desktop. Please upgrade to the latest release before using this stack.

To start everything

docker compose up

If changes to build scripts have been made, rebuild.

docker compose up --build

To enter watch mode (auto rebuild on file changes). First start everything, then in new terminal:

docker compose watch

Shutdown If health check fails or containers don't start up as expected, shutdown completely to start up again.

docker compose down

Applications

Here's what's in this repo:

Name Main files Compose name URLs Description
Support Bot bot.py bot http://localhost:8501 Main usecase. Fullstack Python application.
Stack Overflow Loader loader.py loader http://localhost:8502 Load SO data into the database (create vector embeddings etc). Fullstack Python application.
PDF Reader pdf_bot.py pdf_bot http://localhost:8503 Read local PDF and ask it questions. Fullstack Python application.
Standalone Bot API api.py api http://localhost:8504 Standalone HTTP API streaming (SSE) + non-streaming endpoints Python.
Standalone Bot UI front-end/ front-end http://localhost:8505 Standalone client that uses the Standalone Bot API to interact with the model. JavaScript (Svelte) front-end.

The database can be explored at http://localhost:7474.

App 1 - Support Agent Bot

UI: http://localhost:8501 DB client: http://localhost:7474

  • answer support question based on recent entries
  • provide summarized answers with sources
  • demonstrate difference between
    • RAG Disabled (pure LLM response)
    • RAG Enabled (vector + knowledge graph context)
  • allow to generate a high quality support ticket for the current conversation based on the style of highly rated questions in the database.

(Chat input + RAG mode selector)

(CTA to auto generate support ticket draft) (UI of the auto generated support ticket draft)

App 2 - Loader

UI: http://localhost:8502 DB client: http://localhost:7474

  • import recent Stack Overflow data for certain tags into a KG
  • embed questions and answers and store them in vector index
  • UI: choose tags, run import, see progress, some stats of data in the database
  • Load high ranked questions (regardless of tags) to support the ticket generation feature of App 1.

App 3 Question / Answer with a local PDF

UI: http://localhost:8503
DB client: http://localhost:7474

This application lets you load a local PDF into text chunks and embed it into Neo4j so you can ask questions about its contents and have the LLM answer them using vector similarity search.

App 4 Standalone HTTP API

Endpoints:

Example cURL command:

curl http://localhost:8504/query-stream\?text\=minimal%20hello%20world%20in%20python\&rag\=false

Exposes the functionality to answer questions in the same way as App 1 above. Uses same code and prompts.

App 5 Static front-end

UI: http://localhost:8505

This application has the same features as App 1, but is built separate from the back-end code using modern best practices (Vite, Svelte, Tailwind).
The auto-reload on changes are instant using the Docker watch sync config.

Setup Instructions

  1. Clone the repository:

    git clone https://github.com/your-repo/genai-stack.git
    cd genai-stack
  2. Create and configure the .env file:

    cp env.example .env
    # Edit the .env file with your preferred settings
  3. Build and start the Docker containers:

    docker compose up --build
  4. Access the applications:

Usage Examples

Support Bot

  1. Open the Support Bot UI at http://localhost:8501.
  2. Enter a support question in the chat input.
  3. Select the RAG mode (Disabled or Enabled).
  4. Click "Send" to get a response from the bot.
  5. Optionally, generate a support ticket draft based on the conversation.

Stack Overflow Loader

  1. Open the Stack Overflow Loader UI at http://localhost:8502.
  2. Enter the tags you want to import data for.
  3. Specify the number of pages and the start page.
  4. Click "Import" to load the data into the Neo4j database.
  5. Optionally, import highly ranked questions regardless of tags.

PDF Reader

  1. Open the PDF Reader UI at http://localhost:8503.
  2. Upload a PDF file.
  3. Enter a question related to the content of the PDF.
  4. Click "Ask" to get a response from the bot.

Standalone Bot API

  1. Use the following endpoints to interact with the API:
  2. Example cURL command:
    curl http://localhost:8504/query-stream\?text\=minimal%20hello%20world%20in%20python\&rag\=false

Standalone Bot UI

  1. Open the Standalone Bot UI at http://localhost:8505.
  2. Enter a support question in the chat input.
  3. Select the RAG mode (Disabled or Enabled).
  4. Click "Send" to get a response from the bot.

Explanations of Components

Support Bot

The Support Bot is a fullstack Python application that answers support questions based on recent entries. It provides summarized answers with sources and demonstrates the difference between RAG Disabled (pure LLM response) and RAG Enabled (vector + knowledge graph context). It also allows generating high-quality support ticket drafts based on the style of highly rated questions in the database.

Stack Overflow Loader

The Stack Overflow Loader is a fullstack Python application that imports recent Stack Overflow data for certain tags into a knowledge graph. It embeds questions and answers and stores them in a vector index. The UI allows choosing tags, running the import, and seeing progress and some stats of data in the database. It also supports loading highly ranked questions regardless of tags to support the ticket generation feature of the Support Bot.

PDF Reader

The PDF Reader is a fullstack Python application that lets you load a local PDF into text chunks and embed it into Neo4j. You can then ask questions about its contents and have the LLM answer them using vector similarity search.

Standalone Bot API

The Standalone Bot API is a Python application that exposes the functionality to answer questions in the same way as the Support Bot. It provides both streaming (SSE) and non-streaming endpoints.

Standalone Bot UI

The Standalone Bot UI is a JavaScript (Svelte) front-end application that has the same features as the Support Bot. It is built separately from the back-end code using modern best practices (Vite, Svelte, Tailwind). The auto-reload on changes is instant using the Docker watch sync config.

About

Langchain + Docker + Neo4j + Ollama

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 57.9%
  • Svelte 14.3%
  • Shell 12.4%
  • JavaScript 7.5%
  • Dockerfile 6.7%
  • HTML 0.6%
  • CSS 0.6%