feat: add Nix as Rag service runner option (#1480)

* feat: add nix as option for RAG runner

* fix: remove default embedding model

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* stylua format

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Jorge Luis Suarez
2025-03-04 07:50:24 -08:00
committed by GitHub
parent e1d2d825e2
commit e408b820c8
4 changed files with 189 additions and 53 deletions

23
py/rag-service/run.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# Set the target directory (use the first argument or default to a temporary directory)
TARGET_DIR=$1
if [ -z "$TARGET_DIR" ]; then
TARGET_DIR="/tmp/avante-rag-service"
fi
# Create the target directory if it doesn't exist
mkdir -p "$TARGET_DIR"
# Copy the required files to the target directory
cp -r src/ "$TARGET_DIR"
cp requirements.txt "$TARGET_DIR"
cp shell.nix "$TARGET_DIR"
echo "Files have been copied to $TARGET_DIR"
# Change to the target directory
cd "$TARGET_DIR"
# Run the RAG service using nix-shell
# The environment variables (PORT, DATA_DIR, OPENAI_API_KEY, OPENAI_BASE_URL) are passed from the parent process
nix-shell

46
py/rag-service/shell.nix Executable file
View File

@@ -0,0 +1,46 @@
{ pkgs ? import <nixpkgs> {} }:
let
logFile = "shell_log.txt";
python = pkgs.python311;
in pkgs.mkShell {
packages = [
python
pkgs.uv
pkgs.stdenv.cc.cc.lib
];
env = {
PYTHONUNBUFFERED = 1;
PYTHONDONTWRITEBYTECODE = 1;
LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH";
};
shellHook = ''
# Start with a fresh log file
echo "=== avante.nvim RAG service setup log $(date '+%Y-%m-%d %H:%M:%S') ===" > "${logFile}"
# Function to run commands and log their output
run_and_log() {
echo "$ $1" >> "${logFile}"
eval "$1" 2>&1 | tee -a "${logFile}"
echo "" >> "${logFile}"
}
# Log environment info
run_and_log "echo 'Environment: $(uname -a)'"
run_and_log "echo 'Python version: $(python --version)'"
run_and_log "echo 'UV version: $(uv --version)'"
if [ ! -d ".venv" ]; then
run_and_log "uv venv"
else
echo "Using existing virtual environment" tee -a "${logFile}"
fi
run_and_log source ".venv/bin/activate"
run_and_log "uv pip install -r requirements.txt"
run_and_log "uv run fastapi run src/main.py --port $PORT --workers 3"
'';
}