From cca3212cde44f26fa6492eb33095150fdb540cc7 Mon Sep 17 00:00:00 2001 From: Joseph Villarreal Lopez Date: Thu, 18 Jan 2024 18:35:41 -0600 Subject: [PATCH 01/16] build: Update package versions and add langchain 0.0.349 --- requirements.txt | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/requirements.txt b/requirements.txt index e7ddf21b..239f437b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,18 @@ openai==0.28.1 -python-dotenv -wikipedia -tiktoken -neo4j -streamlit +python-dotenv==1.0.0 +wikipedia==1.4.0 +tiktoken==0.5.2 +neo4j==5.16.0 +streamlit==1.30.0 sentence_transformers==2.2.2 -Pillow -fastapi -PyPDF2 +pillow==10.2.0 +fastapi==0.109.0 +PyPDF2==3.0.1 torch==2.0.1 -pydantic -uvicorn -sse-starlette -boto3 +pydantic==2.5.3 +pydantic_core==2.14.6 +uvicorn==0.26.0 +sse-starlette==1.8.2 +boto3==1.34.22 + +langchain==0.0.349 \ No newline at end of file From 1edf5e7f590fdfbbf61d02bfae8fb4e8e645e171 Mon Sep 17 00:00:00 2001 From: Joseph Villarreal Lopez Date: Fri, 19 Jan 2024 10:16:08 -0600 Subject: [PATCH 02/16] Revert "build: Update package versions and add langchain 0.0.349" This reverts commit cca3212cde44f26fa6492eb33095150fdb540cc7. --- requirements.txt | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/requirements.txt b/requirements.txt index 239f437b..e7ddf21b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,18 +1,15 @@ openai==0.28.1 -python-dotenv==1.0.0 -wikipedia==1.4.0 -tiktoken==0.5.2 -neo4j==5.16.0 -streamlit==1.30.0 +python-dotenv +wikipedia +tiktoken +neo4j +streamlit sentence_transformers==2.2.2 -pillow==10.2.0 -fastapi==0.109.0 -PyPDF2==3.0.1 +Pillow +fastapi +PyPDF2 torch==2.0.1 -pydantic==2.5.3 -pydantic_core==2.14.6 -uvicorn==0.26.0 -sse-starlette==1.8.2 -boto3==1.34.22 - -langchain==0.0.349 \ No newline at end of file +pydantic +uvicorn +sse-starlette +boto3 From 20d54884d8f95720bcecc8409a717265531b86be Mon Sep 17 00:00:00 2001 From: Joseph Villarreal Lopez Date: Fri, 19 Jan 2024 10:18:18 -0600 Subject: [PATCH 03/16] Revert "Use 8502 port for the healthcheck (#110)" This reverts commit 6e5930ba7566e54cae7b16e536b23868b3f419a7. --- loader.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loader.Dockerfile b/loader.Dockerfile index d146b683..b146d311 100644 --- a/loader.Dockerfile +++ b/loader.Dockerfile @@ -19,6 +19,6 @@ COPY images ./images EXPOSE 8502 -HEALTHCHECK CMD curl --fail http://localhost:8502/_stcore/health +HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health ENTRYPOINT ["streamlit", "run", "loader.py", "--server.port=8502", "--server.address=0.0.0.0"] From bde09ab7fb9796d4a56e4c4b54b6a30a7b92bd9a Mon Sep 17 00:00:00 2001 From: Li Yi Date: Sat, 23 Dec 2023 06:01:20 +0800 Subject: [PATCH 04/16] Fix KeyError: 'ollama_base_url' (#97) Signed-off-by: Joseph Villarreal Lopez --- api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.py b/api.py index ed1d3480..f79b5158 100644 --- a/api.py +++ b/api.py @@ -36,7 +36,7 @@ embeddings, dimension = load_embedding_model( embedding_model_name, - config={ollama_base_url: ollama_base_url}, + config={"ollama_base_url": ollama_base_url}, logger=BaseLogger(), ) From 121714380cd90c4dd79d43faf5101cda90160430 Mon Sep 17 00:00:00 2001 From: Sanyam Jain Date: Sat, 23 Dec 2023 03:34:15 +0530 Subject: [PATCH 05/16] Fixed Typo and Grammar (#59) * Update README.md * Update readme.md --------- Co-authored-by: Jim Clark Signed-off-by: Joseph Villarreal Lopez --- front-end/README.md | 8 ++++---- readme.md | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/front-end/README.md b/front-end/README.md index 382941e0..a15d13f1 100644 --- a/front-end/README.md +++ b/front-end/README.md @@ -8,7 +8,7 @@ This template should help get you started developing with Svelte in Vite. ## Need an official Svelte framework? -Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. +Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS and Less and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. ## Technical considerations @@ -23,7 +23,7 @@ Should you later need the extended capabilities and extensibility provided by Sv **Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?** -Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information. +Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace while also adding `svelte` and `vite/client` type information. **Why include `.vscode/extensions.json`?** @@ -31,13 +31,13 @@ Other templates indirectly recommend extensions via the README, but this file al **Why enable `checkJs` in the JS template?** -It is likely that most cases of changing variable types in runtime are likely to be accidental, rather than deliberate. This provides advanced typechecking out of the box. Should you like to take advantage of the dynamically-typed nature of JavaScript, it is trivial to change the configuration. +It is likely that most cases of changing variable types in runtime are likely to be accidental rather than deliberate. This provides advanced typechecking out of the box. Should you like to take advantage of the dynamically-typed nature of JavaScript, it is trivial to change the configuration. **Why is HMR not preserving my local component state?** HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/sveltejs/svelte-hmr/tree/master/packages/svelte-hmr#preservation-of-local-state). -If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR. +If you have a state that's important to retain within a component, consider creating an external store that would not be replaced by HMR. ```js // store.js diff --git a/readme.md b/readme.md index b2e8f677..878d8f26 100644 --- a/readme.md +++ b/readme.md @@ -27,7 +27,7 @@ Available variables: ## 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 OpenAIs models). +All platforms can use GPT-3.5-turbo and GPT-4 (bring your own API keys for OpenAI models). **MacOS** Install [Ollama](https://ollama.ai) on MacOS and start it before running `docker compose up`. @@ -40,7 +40,7 @@ Make sure to set the `OLLAMA_BASE_URL=http://llm:11434` in the `.env` file when 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** -Not supported by Ollama, so Windows users need to generate a OpenAI API key and configure the stack to use `gpt-3.5` or `gpt-4` in the `.env` file. +Not supported by Ollama, so Windows users need to generate an OpenAI API key and configure the stack to use `gpt-3.5` or `gpt-4` in the `.env` file. # Develop > [!WARNING] @@ -50,7 +50,7 @@ Not supported by Ollama, so Windows users need to generate a OpenAI API key and ``` docker compose up ``` -If changes to build scripts has been made, **rebuild**. +If changes to build scripts have been made, **rebuild**. ``` docker compose up --build ``` @@ -77,7 +77,7 @@ Here's what's in this repo: | 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 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. @@ -110,7 +110,7 @@ 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 in vector index +- 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. From c35cfbb834e7b8f6d801e6155874899faff0b49c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20SIME?= <70714156+ssime-git@users.noreply.github.com> Date: Mon, 8 Jan 2024 17:53:56 +0100 Subject: [PATCH 06/16] running on WSL (#38) * run on wsl * run on windows WSL procedure Signed-off-by: Joseph Villarreal Lopez --- install_ollama.sh | 243 ++++++++++++++++++++++++++++++++++++++++++++++ running_on_wsl.md | 43 ++++++++ 2 files changed, 286 insertions(+) create mode 100644 install_ollama.sh create mode 100644 running_on_wsl.md diff --git a/install_ollama.sh b/install_ollama.sh new file mode 100644 index 00000000..b94cc95d --- /dev/null +++ b/install_ollama.sh @@ -0,0 +1,243 @@ +#!/bin/sh +# This script installs Ollama on Linux. +# It detects the current operating system architecture and installs the appropriate version of Ollama. + +set -eu + +status() { echo ">>> $*" >&2; } +error() { echo "ERROR $*"; exit 1; } +warning() { echo "WARNING: $*"; } + +TEMP_DIR=$(mktemp -d) +cleanup() { rm -rf $TEMP_DIR; } +trap cleanup EXIT + +available() { command -v $1 >/dev/null; } +require() { + local MISSING='' + for TOOL in $*; do + if ! available $TOOL; then + MISSING="$MISSING $TOOL" + fi + done + + echo $MISSING +} + +[ "$(uname -s)" = "Linux" ] || error 'This script is intended to run on Linux only.' + +case "$(uname -m)" in + x86_64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; + *) error "Unsupported architecture: $ARCH" ;; +esac + +SUDO= +if [ "$(id -u)" -ne 0 ]; then + # Running as root, no need for sudo + if ! available sudo; then + error "This script requires superuser permissions. Please re-run as root." + fi + + SUDO="sudo" +fi + +NEEDS=$(require curl awk grep sed tee xargs) +if [ -n "$NEEDS" ]; then + status "ERROR: The following tools are required but missing:" + for NEED in $NEEDS; do + echo " - $NEED" + done + exit 1 +fi + +status "Downloading ollama..." +curl --fail --show-error --location --progress-bar -o $TEMP_DIR/ollama "https://ollama.ai/download/ollama-linux-$ARCH" + +for BINDIR in /usr/local/bin /usr/bin /bin; do + echo $PATH | grep -q $BINDIR && break || continue +done + +status "Installing ollama to $BINDIR..." +$SUDO install -o0 -g0 -m755 -d $BINDIR +$SUDO install -o0 -g0 -m755 $TEMP_DIR/ollama $BINDIR/ollama + +install_success() { status 'Install complete. Run "ollama" from the command line.'; } +trap install_success EXIT + +# Everything from this point onwards is optional. + +configure_systemd() { + if ! id ollama >/dev/null 2>&1; then + status "Creating ollama user..." + $SUDO useradd -r -s /bin/false -m -d /usr/share/ollama ollama + fi + + status "Creating ollama systemd service..." + cat </dev/null +[Unit] +Description=Ollama Service +After=network-online.target + +[Service] +ExecStart=$BINDIR/ollama serve +User=ollama +Group=ollama +Restart=always +RestartSec=3 +Environment="HOME=/usr/share/ollama" +Environment="PATH=$PATH" + +[Install] +WantedBy=default.target +EOF + SYSTEMCTL_RUNNING="$(systemctl is-system-running || true)" + case $SYSTEMCTL_RUNNING in + running|degraded) + status "Enabling and starting ollama service..." + $SUDO systemctl daemon-reload + $SUDO systemctl enable ollama + + start_service() { $SUDO systemctl restart ollama; } + trap start_service EXIT + ;; + esac +} + +if available systemctl; then + configure_systemd +fi + +if ! available lspci && ! available lshw; then + warning "Unable to detect NVIDIA GPU. Install lspci or lshw to automatically detect and install NVIDIA CUDA drivers." + exit 0 +fi + +check_gpu() { + case $1 in + lspci) available lspci && lspci -d '10de:' | grep -q 'NVIDIA' || return 1 ;; + lshw) available lshw && $SUDO lshw -c display -numeric | grep -q 'vendor: .* \[10DE\]' || return 1 ;; + nvidia-smi) available nvidia-smi || return 1 ;; + esac +} + +if check_gpu nvidia-smi; then + status "NVIDIA GPU installed." + exit 0 +fi + +if ! check_gpu lspci && ! check_gpu lshw; then + warning "No NVIDIA GPU detected. Ollama will run in CPU-only mode." + exit 0 +fi + +# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#rhel-7-centos-7 +# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#rhel-8-rocky-8 +# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#rhel-9-rocky-9 +# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#fedora +install_cuda_driver_yum() { + status 'Installing NVIDIA repository...' + case $PACKAGE_MANAGER in + yum) + $SUDO $PACKAGE_MANAGER -y install yum-utils + $SUDO $PACKAGE_MANAGER-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/$1$2/$(uname -m)/cuda-$1$2.repo + ;; + dnf) + $SUDO $PACKAGE_MANAGER config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/$1$2/$(uname -m)/cuda-$1$2.repo + ;; + esac + + case $1 in + rhel) + status 'Installing EPEL repository...' + # EPEL is required for third-party dependencies such as dkms and libvdpau + $SUDO $PACKAGE_MANAGER -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-$2.noarch.rpm || true + ;; + esac + + status 'Installing CUDA driver...' + + if [ "$1" = 'centos' ] || [ "$1$2" = 'rhel7' ]; then + $SUDO $PACKAGE_MANAGER -y install nvidia-driver-latest-dkms + fi + + $SUDO $PACKAGE_MANAGER -y install cuda-drivers +} + +# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#ubuntu +# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#debian +install_cuda_driver_apt() { + status 'Installing NVIDIA repository...' + curl -fsSL -o $TEMP_DIR/cuda-keyring.deb https://developer.download.nvidia.com/compute/cuda/repos/$1$2/$(uname -m)/cuda-keyring_1.1-1_all.deb + + case $1 in + debian) + status 'Enabling contrib sources...' + $SUDO sed 's/main/contrib/' < /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/contrib.list > /dev/null + ;; + esac + + status 'Installing CUDA driver...' + $SUDO dpkg -i $TEMP_DIR/cuda-keyring.deb + $SUDO apt-get update + + [ -n "$SUDO" ] && SUDO_E="$SUDO -E" || SUDO_E= + DEBIAN_FRONTEND=noninteractive $SUDO_E apt-get -y install cuda-drivers -q +} + +if [ ! -f "/etc/os-release" ]; then + error "Unknown distribution. Skipping CUDA installation." +fi + +. /etc/os-release + +OS_NAME=$ID +OS_VERSION=$VERSION_ID + +PACKAGE_MANAGER= +for PACKAGE_MANAGER in dnf yum apt-get; do + if available $PACKAGE_MANAGER; then + break + fi +done + +if [ -z "$PACKAGE_MANAGER" ]; then + error "Unknown package manager. Skipping CUDA installation." +fi + +if ! check_gpu nvidia-smi || [ -z "$(nvidia-smi | grep -o "CUDA Version: [0-9]*\.[0-9]*")" ]; then + case $OS_NAME in + centos|rhel) install_cuda_driver_yum 'rhel' $OS_VERSION ;; + rocky) install_cuda_driver_yum 'rhel' $(echo $OS_VERSION | cut -c1) ;; + fedora) install_cuda_driver_yum $OS_NAME $OS_VERSION ;; + amzn) install_cuda_driver_yum 'fedora' '35' ;; + debian) install_cuda_driver_apt $OS_NAME $OS_VERSION ;; + ubuntu) install_cuda_driver_apt $OS_NAME $(echo $OS_VERSION | sed 's/\.//') ;; + *) exit ;; + esac +fi + +if ! lsmod | grep -q nvidia; then + KERNEL_RELEASE="$(uname -r)" + case $OS_NAME in + centos|rhel|rocky|amzn) $SUDO $PACKAGE_MANAGER -y install kernel-devel-$KERNEL_RELEASE kernel-headers-$KERNEL_RELEASE ;; + fedora) $SUDO $PACKAGE_MANAGER -y install kernel-devel-$KERNEL_RELEASE ;; + debian|ubuntu) $SUDO apt-get -y install linux-headers-$KERNEL_RELEASE ;; + *) exit ;; + esac + + NVIDIA_CUDA_VERSION=$($SUDO dkms status | awk -F: '/added/ { print $1 }') + if [ -n "$NVIDIA_CUDA_VERSION" ]; then + $SUDO dkms install $NVIDIA_CUDA_VERSION + fi + + if lsmod | grep -q nouveau; then + status 'Reboot to complete NVIDIA CUDA driver install.' + exit 0 + fi + + $SUDO modprobe nvidia +fi + + +status "NVIDIA CUDA drivers installed." diff --git a/running_on_wsl.md b/running_on_wsl.md new file mode 100644 index 00000000..473ec50e --- /dev/null +++ b/running_on_wsl.md @@ -0,0 +1,43 @@ +# Run the stack on WSL + +Note that for the stack to work on Windows, you should have running version on ollama installed somehow. Since Windows, is not yet supported, we can only use WSL. + +I won't cover the activation of WSL procedure which you will find very easy on internet. Assuming that you have a version of WSL on your local windows machine and a running docker Desktop software installer and running as well, you can follow the following steps: + +1. enable docker-desktop to use WSL using the following tutorial: + +>To connect WSL to Docker Desktop, you need to follow the instructions below: +> +>1. First, ensure that you have installed Docker Desktop for Windows on your machine. If you haven't, you can download it from ยน. +>2. Next, open Docker Desktop and navigate to **Settings**. +>3. From the **Settings** menu, select **Resources** and then click on **WSL Integration**. +>4. On the **WSL Integration** page, you will see a list of available WSL distributions. Select the distribution that you want to connect to Docker Desktop. +>5. Once you have selected the distribution, click on **Apply & Restart**. +> +>After following these steps, your WSL distribution should be connected to Docker Desktop. +> +> +>1. Docker Desktop WSL 2 backend on Windows | Docker Docs. https://docs.docker.com/desktop/wsl/. +>2. Get started with Docker containers on WSL | Microsoft Learn. https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers. +>3. How to configure Docker Desktop to work with the WSL. https://tutorials.releaseworksacademy.com/learn/how-to-configure-docker-desktop-to-work-with-the-wsl.html. +>4. How can I access wsl2 which is used by Docker desktop?. https://stackoverflow.com/questions/70449927/how-can-i-access-wsl2-which-is-used-by-docker-desktop. + +After the activation enter into the WSL with the command `wsl` and type `docker`. + +2. Install ollama on WSL using https://github.com/jmorganca/ollama (avec la commande `curl https://ollama.ai/install.sh | sh`) + - The script have been downloaded in `./install_ollama.sh` and you do the smae thing with `sh ./install_ollama.sh` + - To list the downloaded model: `ollama list`. This command could lead to: + ```sh + NAME ID SIZE MODIFIED + llama2:latest 7da22eda89ac 3.8 GB 22 minutes ago + ``` + - (OPTIONAL) To remove model: `ollama rm llama2` + - To run the ollama on WSL: `ollama run llama2` + +3. clone the repo +4. cd into the repo and enter wsl +5. run `docker-compose up` + +# Run the stack on MAC: + +On MAC you can follow this tutorial: https://collabnix.com/getting-started-with-genai-stack-powered-with-docker-langchain-neo4j-and-ollama/ \ No newline at end of file From 906fbbf2b43c459f981f6f4968aa9cee06269a82 Mon Sep 17 00:00:00 2001 From: Ignasi Date: Mon, 8 Jan 2024 17:54:58 +0100 Subject: [PATCH 07/16] Use 8502 port for the healthcheck (#110) Signed-off-by: Joseph Villarreal Lopez --- loader.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loader.Dockerfile b/loader.Dockerfile index b146d311..d146b683 100644 --- a/loader.Dockerfile +++ b/loader.Dockerfile @@ -19,6 +19,6 @@ COPY images ./images EXPOSE 8502 -HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health +HEALTHCHECK CMD curl --fail http://localhost:8502/_stcore/health ENTRYPOINT ["streamlit", "run", "loader.py", "--server.port=8502", "--server.address=0.0.0.0"] From aed1b5f9937611f46ae79aa9b83c79ce092c973d Mon Sep 17 00:00:00 2001 From: Gleb Zaveruha <7124044+Tachii@users.noreply.github.com> Date: Wed, 24 Jan 2024 18:41:12 +0200 Subject: [PATCH 08/16] Bump vite from 4.4.10 to 4.4.12 in /front-end (#107) Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 4.4.10 to 4.4.12.
Changelog

Sourced from vite's changelog.

4.4.12 (2023-12-04)

4.4.11 (2023-10-05)

  • revert: "fix: use string manipulation instead of regex to inject esbuild helpers (54e1275), closes #14094
Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=vite&package-manager=npm_and_yarn&previous-version=4.4.10&new-version=4.4.12)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/Signal-Spot/genai-stack/network/alerts).
Signed-off-by: Joseph Villarreal Lopez --- front-end/package-lock.json | 8 ++++---- front-end/package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/front-end/package-lock.json b/front-end/package-lock.json index 72b6715c..2689a6bb 100644 --- a/front-end/package-lock.json +++ b/front-end/package-lock.json @@ -16,7 +16,7 @@ "postcss": "^8.4.31", "svelte": "^4.0.5", "tailwindcss": "^3.3.3", - "vite": "^4.4.5" + "vite": "^4.4.12" } }, "node_modules/@alloc/quick-lru": { @@ -1792,9 +1792,9 @@ "dev": true }, "node_modules/vite": { - "version": "4.4.10", - "resolved": "https://registry.npmjs.org/vite/-/vite-4.4.10.tgz", - "integrity": "sha512-TzIjiqx9BEXF8yzYdF2NTf1kFFbjMjUSV0LFZ3HyHoI3SGSPLnnFUKiIQtL3gl2AjHvMrprOvQ3amzaHgQlAxw==", + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/vite/-/vite-4.5.1.tgz", + "integrity": "sha512-AXXFaAJ8yebyqzoNB9fu2pHoo/nWX+xZlaRwoeYUxEqBO+Zj4msE5G+BhGBll9lYEKv9Hfks52PAF2X7qDYXQA==", "dev": true, "dependencies": { "esbuild": "^0.18.10", diff --git a/front-end/package.json b/front-end/package.json index 005b8a6d..910db7cd 100644 --- a/front-end/package.json +++ b/front-end/package.json @@ -14,7 +14,7 @@ "postcss": "^8.4.31", "svelte": "^4.0.5", "tailwindcss": "^3.3.3", - "vite": "^4.4.5" + "vite": "^4.4.12" }, "dependencies": { "svelte-markdown": "^0.4.0" From b817c4559ba860740143f14356a005dd5d816987 Mon Sep 17 00:00:00 2001 From: Michael Hunger Date: Wed, 31 Jan 2024 22:28:11 +0100 Subject: [PATCH 09/16] Langchain 0.1.0 update (#121) Signed-off-by: Joseph Villarreal Lopez --- api.py | 2 +- bot.py | 2 +- chains.py | 28 ++++++++++++++++++---------- loader.py | 2 +- pdf_bot.py | 4 ++-- requirements.txt | 5 ++++- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/api.py b/api.py index f79b5158..37271d96 100644 --- a/api.py +++ b/api.py @@ -1,6 +1,6 @@ import os -from langchain.graphs import Neo4jGraph +from langchain_community.graphs import Neo4jGraph from dotenv import load_dotenv from utils import ( create_vector_index, diff --git a/bot.py b/bot.py index 61a5cd98..4146af07 100644 --- a/bot.py +++ b/bot.py @@ -3,7 +3,7 @@ import streamlit as st from streamlit.logger import get_logger from langchain.callbacks.base import BaseCallbackHandler -from langchain.graphs import Neo4jGraph +from langchain_community.graphs import Neo4jGraph from dotenv import load_dotenv from utils import ( create_vector_index, diff --git a/chains.py b/chains.py index cfd87825..1166adf7 100644 --- a/chains.py +++ b/chains.py @@ -1,18 +1,26 @@ -from langchain.embeddings.openai import OpenAIEmbeddings -from langchain.embeddings import ( - OllamaEmbeddings, - SentenceTransformerEmbeddings, - BedrockEmbeddings, -) -from langchain.chat_models import ChatOpenAI, ChatOllama, BedrockChat -from langchain.vectorstores.neo4j_vector import Neo4jVector + +from langchain_openai import OpenAIEmbeddings +from langchain_community.embeddings import OllamaEmbeddings +from langchain_community.embeddings import BedrockEmbeddings +from langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddings + +from langchain_openai import ChatOpenAI +from langchain_community.chat_models import ChatOllama +from langchain_community.chat_models import BedrockChat + +from langchain_community.graphs import Neo4jGraph + +from langchain_community.vectorstores import Neo4jVector + from langchain.chains import RetrievalQAWithSourcesChain from langchain.chains.qa_with_sources import load_qa_with_sources_chain -from langchain.prompts.chat import ( + +from langchain.prompts import ( ChatPromptTemplate, - SystemMessagePromptTemplate, HumanMessagePromptTemplate, + SystemMessagePromptTemplate ) + from typing import List, Any from utils import BaseLogger, extract_title_and_question diff --git a/loader.py b/loader.py index 8cc08023..6a620604 100644 --- a/loader.py +++ b/loader.py @@ -1,7 +1,7 @@ import os import requests from dotenv import load_dotenv -from langchain.graphs import Neo4jGraph +from langchain_community.graphs import Neo4jGraph import streamlit as st from streamlit.logger import get_logger from chains import load_embedding_model diff --git a/pdf_bot.py b/pdf_bot.py index 08ef9d41..fb8f4d46 100644 --- a/pdf_bot.py +++ b/pdf_bot.py @@ -3,9 +3,9 @@ import streamlit as st from langchain.chains import RetrievalQA from PyPDF2 import PdfReader -from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.callbacks.base import BaseCallbackHandler -from langchain.vectorstores.neo4j_vector import Neo4jVector +from langchain.text_splitter import RecursiveCharacterTextSplitter +from langchain_community.vectorstores import Neo4jVector from streamlit.logger import get_logger from chains import ( load_embedding_model, diff --git a/requirements.txt b/requirements.txt index e7ddf21b..9aa7e4c8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -openai==0.28.1 +openai python-dotenv wikipedia tiktoken @@ -13,3 +13,6 @@ pydantic uvicorn sse-starlette boto3 +# missing from the langchain base image? +langchain-openai +langchain-community From e1433d37d4bd5a7d3764ed8b4c4005a0a865ae0b Mon Sep 17 00:00:00 2001 From: Li Yi Date: Thu, 1 Feb 2024 05:28:37 +0800 Subject: [PATCH 10/16] Pull model if not present locally (#119) Signed-off-by: denverdino Signed-off-by: Joseph Villarreal Lopez --- pull_model.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pull_model.Dockerfile b/pull_model.Dockerfile index e858b7f9..4c8a9e33 100644 --- a/pull_model.Dockerfile +++ b/pull_model.Dockerfile @@ -26,7 +26,7 @@ COPY < /dev/null || ./bin/ollama pull %s'" llm llm)) (async/>!! done :stop)) (println "OLLAMA model only pulled if both LLM and OLLAMA_BASE_URL are set and the LLM model is not gpt"))) From 503d11f0867b99211157f48bafa7d25f627f4bad Mon Sep 17 00:00:00 2001 From: "Emmanuel I. Obi" Date: Wed, 31 Jan 2024 15:28:58 -0600 Subject: [PATCH 11/16] adds user directive to database service (#104) Signed-off-by: Joseph Villarreal Lopez --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index 1c94b858..ae1170df 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,6 +30,7 @@ services: tty: true database: + user: neo4j:neo4j image: neo4j:5.11 ports: - 7687:7687 From 7f5d0302a0837202bacaf551192f12b777b3c180 Mon Sep 17 00:00:00 2001 From: Joseph Villarreal Lopez Date: Wed, 14 Feb 2024 10:49:22 -0600 Subject: [PATCH 12/16] fix(neo4j): increase healthcheck timeouts Signed-off-by: Joseph Villarreal Lopez --- docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ae1170df..b027ca64 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,9 +43,9 @@ services: - NEO4J_db_tx__log_rotation_retention__policy=false healthcheck: test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider localhost:7474 || exit 1"] - interval: 5s - timeout: 3s - retries: 5 + interval: 15s + timeout: 30s + retries: 10 networks: - net From e087ba95bd03b86bf81e606ebd4ba6b5d1819886 Mon Sep 17 00:00:00 2001 From: Joseph Villarreal Lopez Date: Mon, 19 Feb 2024 17:40:25 -0600 Subject: [PATCH 13/16] feat(chains): Add Google Generative AI Embeddings as an option Adds support for Google's Generative AI Embeddings as an optional embedding model for Langchain. This model can be selected using the `EMBEDDING_MODEL` environment variable, and requires a valid Google API key to be set via the `GOOGLE_API_KEY` environment variable. The embedding model is configured with a model dimension of 768. Signed-off-by: Joseph Villarreal Lopez --- chains.py | 7 +++++++ docker-compose.yml | 6 +++++- env.example | 10 ++++++++-- readme.md | 3 ++- requirements.txt | 1 + 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/chains.py b/chains.py index 1166adf7..9ad10f40 100644 --- a/chains.py +++ b/chains.py @@ -23,6 +23,7 @@ from typing import List, Any from utils import BaseLogger, extract_title_and_question +from langchain_google_genai import GoogleGenerativeAIEmbeddings def load_embedding_model(embedding_model_name: str, logger=BaseLogger(), config={}): @@ -40,6 +41,12 @@ def load_embedding_model(embedding_model_name: str, logger=BaseLogger(), config= embeddings = BedrockEmbeddings() dimension = 1536 logger.info("Embedding: Using AWS") + elif embedding_model_name == "google-genai-embedding-001": + embeddings = GoogleGenerativeAIEmbeddings( + model="models/embedding-001" + ) + dimension = 768 + logger.info("Embedding: Using Google Generative AI Embeddings") else: embeddings = SentenceTransformerEmbeddings( model_name="all-MiniLM-L6-v2", cache_folder="/embedding_model" diff --git a/docker-compose.yml b/docker-compose.yml index b027ca64..ad8ff878 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -60,6 +60,7 @@ services: - NEO4J_PASSWORD=${NEO4J_PASSWORD-password} - NEO4J_USERNAME=${NEO4J_USERNAME-neo4j} - OPENAI_API_KEY=${OPENAI_API_KEY-} + - GOOGLE_API_KEY=${GOOGLE_API_KEY-} - OLLAMA_BASE_URL=${OLLAMA_BASE_URL-http://host.docker.internal:11434} - EMBEDDING_MODEL=${EMBEDDING_MODEL-sentence_transformer} - LANGCHAIN_ENDPOINT=${LANGCHAIN_ENDPOINT-"https://api.smith.langchain.com"} @@ -100,7 +101,8 @@ services: - NEO4J_URI=${NEO4J_URI-neo4j://database:7687} - NEO4J_PASSWORD=${NEO4J_PASSWORD-password} - NEO4J_USERNAME=${NEO4J_USERNAME-neo4j} - - OPENAI_API_KEY=${OPENAI_API_KEY-} + - OPENAI_API_KEY=${OPENAI_API_KEY-} + - GOOGLE_API_KEY=${GOOGLE_API_KEY-} - OLLAMA_BASE_URL=${OLLAMA_BASE_URL-http://host.docker.internal:11434} - LLM=${LLM-llama2} - EMBEDDING_MODEL=${EMBEDDING_MODEL-sentence_transformer} @@ -139,6 +141,7 @@ services: - NEO4J_PASSWORD=${NEO4J_PASSWORD-password} - NEO4J_USERNAME=${NEO4J_USERNAME-neo4j} - OPENAI_API_KEY=${OPENAI_API_KEY-} + - GOOGLE_API_KEY=${GOOGLE_API_KEY-} - OLLAMA_BASE_URL=${OLLAMA_BASE_URL-http://host.docker.internal:11434} - LLM=${LLM-llama2} - EMBEDDING_MODEL=${EMBEDDING_MODEL-sentence_transformer} @@ -179,6 +182,7 @@ services: - NEO4J_PASSWORD=${NEO4J_PASSWORD-password} - NEO4J_USERNAME=${NEO4J_USERNAME-neo4j} - OPENAI_API_KEY=${OPENAI_API_KEY} + - GOOGLE_API_KEY=${GOOGLE_API_KEY} - OLLAMA_BASE_URL=${OLLAMA_BASE_URL-http://host.docker.internal:11434} - LLM=${LLM-llama2} - EMBEDDING_MODEL=${EMBEDDING_MODEL-sentence_transformer} diff --git a/env.example b/env.example index 2a9457ac..88e33cc3 100644 --- a/env.example +++ b/env.example @@ -2,7 +2,7 @@ # LLM and Embedding Model #***************************************************************** LLM=llama2 #or any Ollama model tag, gpt-4, gpt-3.5, or claudev2 -EMBEDDING_MODEL=sentence_transformer #or openai, ollama, or aws +EMBEDDING_MODEL=sentence_transformer #or google-genai-embedding-001 openai, ollama, or aws #***************************************************************** # Neo4j @@ -40,4 +40,10 @@ EMBEDDING_MODEL=sentence_transformer #or openai, ollama, or aws #AWS_ACCESS_KEY_ID= #AWS_SECRET_ACCESS_KEY= -#AWS_DEFAULT_REGION=us-east-1 \ No newline at end of file +#AWS_DEFAULT_REGION=us-east-1 + +#***************************************************************** +# GOOGLE +#***************************************************************** +# Only required when using GoogleGenai LLM or embedding model +GOOGLE_API_KEY= diff --git a/readme.md b/readme.md index 878d8f26..56d64fe5 100644 --- a/readme.md +++ b/readme.md @@ -15,11 +15,12 @@ Available variables: | 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 or ollama | +| 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 | diff --git a/requirements.txt b/requirements.txt index 9aa7e4c8..c28bcec6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ boto3 # missing from the langchain base image? langchain-openai langchain-community +langchain-google-genai \ No newline at end of file From d307affb89fc5b62dd88f327571827cfa6c7619a Mon Sep 17 00:00:00 2001 From: Joseph Villarreal Lopez Date: Mon, 19 Feb 2024 18:18:40 -0600 Subject: [PATCH 14/16] feat(chains): add OpenAI embedding model options Add OpenAI embedding models: - openai-embedding-3-small - openai-embedding-3-large Update docs and examples to reflect these changes. --- chains.py | 14 +++++++++++--- env.example | 2 +- readme.md | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/chains.py b/chains.py index 1166adf7..72e99c57 100644 --- a/chains.py +++ b/chains.py @@ -32,10 +32,18 @@ def load_embedding_model(embedding_model_name: str, logger=BaseLogger(), config= ) dimension = 4096 logger.info("Embedding: Using Ollama") - elif embedding_model_name == "openai": - embeddings = OpenAIEmbeddings() + elif embedding_model_name == "openai-embedding-3-small": + embeddings = OpenAIEmbeddings( + model="text-embedding-3-small" + ) dimension = 1536 - logger.info("Embedding: Using OpenAI") + logger.info("Embedding: Using OpenAI text-embedding-3-small") + elif embedding_model_name == "openai-embedding-3-large": + embeddings = OpenAIEmbeddings( + model="text-embedding-3-large" + ) + dimension = 3072 + logger.info("Embedding: Using OpenAI text-embedding-3-large") elif embedding_model_name == "aws": embeddings = BedrockEmbeddings() dimension = 1536 diff --git a/env.example b/env.example index 2a9457ac..8a614df9 100644 --- a/env.example +++ b/env.example @@ -2,7 +2,7 @@ # LLM and Embedding Model #***************************************************************** LLM=llama2 #or any Ollama model tag, gpt-4, gpt-3.5, or claudev2 -EMBEDDING_MODEL=sentence_transformer #or openai, ollama, or aws +EMBEDDING_MODEL=sentence_transformer #or openai-embedding-3-small, openai-embedding-3-large, ollama, or aws #***************************************************************** # Neo4j diff --git a/readme.md b/readme.md index 878d8f26..b282536d 100644 --- a/readme.md +++ b/readme.md @@ -15,11 +15,11 @@ Available variables: | 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 or ollama | +| EMBEDDING_MODEL | sentence_transformer | REQUIRED - Can be sentence_transformer, openai-embedding-3-small, openai-embedding-3-large, aws or ollama | | 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 | +| OPENAI_API_KEY | | REQUIRED - Only if LLM=gpt-4 or LLM=gpt-3.5 or embedding_model=openai-* | | 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 | From 764be9e8bc469e7cc9f9ec2a1e8c7fa5fec6d4ef Mon Sep 17 00:00:00 2001 From: Joseph Villarreal Lopez Date: Wed, 21 Feb 2024 09:35:40 -0600 Subject: [PATCH 15/16] Update loader.Dockerfile --- loader.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loader.Dockerfile b/loader.Dockerfile index b146d311..d146b683 100644 --- a/loader.Dockerfile +++ b/loader.Dockerfile @@ -19,6 +19,6 @@ COPY images ./images EXPOSE 8502 -HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health +HEALTHCHECK CMD curl --fail http://localhost:8502/_stcore/health ENTRYPOINT ["streamlit", "run", "loader.py", "--server.port=8502", "--server.address=0.0.0.0"] From 73a16a63a35861f2175788dc737c1c423a9b9212 Mon Sep 17 00:00:00 2001 From: Joseph Villarreal Lopez Date: Wed, 21 Feb 2024 09:36:47 -0600 Subject: [PATCH 16/16] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 06eaa755..da052f38 100644 --- a/readme.md +++ b/readme.md @@ -15,7 +15,7 @@ Available variables: | 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-embedding-3-small, openai-embedding-3-large, aws or ollama | +| EMBEDDING_MODEL | sentence_transformer | REQUIRED - Can be sentence_transformer, openai-embedding-3-small, openai-embedding-3-large, 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 |