-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
e1d2d82
commit e408b82
Showing
4 changed files
with
189 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
''; | ||
} |