Skip to content

Commit

Permalink
feat: Update ragger implementation to package
Browse files Browse the repository at this point in the history
  • Loading branch information
saattrupdan committed Aug 13, 2024
1 parent 85cfebb commit 1fee7db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 62 deletions.
56 changes: 9 additions & 47 deletions {{cookiecutter.project_name}}/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,43 +69,6 @@ install-brew:

{%- if cookiecutter.open_source != 'y' %}

setup-ragger:
@if [ -d src/ragger ]; then \
echo "RAG functionality already added to the project. Skipping."; \
exit 1; \
fi
@if [ ! -d .venv ]; then \
echo "The project hasn't been installed yet. Please run 'make install' first."; \
exit 1; \
fi
@echo "Adding RAG functionality to the project..."
@cd src && git clone [email protected]:alexandrainst/ragger.git && rm -rf ragger/.git && cd -
@mv src/ragger/src/scripts/run_demo.py src/scripts/
@mv src/ragger/src/scripts/run_cli.py src/scripts/
@cp -R src/ragger/config/* config/
@if [ ! -f data/processed/document_store.jsonl ]; then \
mv src/ragger/data/processed/document_store.jsonl data/processed/; \
fi
@{{'poetry add' if cookiecutter.dependency_manager != 'pip' else '. .venv/bin/activate && pip install'}} -e src/ragger
@{{'poetry run ' if cookiecutter.dependency_manager != 'pip' else '. .venv/bin/activate && '}}python src/scripts/fix_dot_env_file.py --include-openai

add-rag: ## Add RAG functionality to the project
@$(MAKE) --quiet setup-ragger
@git add .
@echo "Added RAG functionality to the project, but haven't committed the changes yet. Please commit them manually."

update-rag: ## Update the RAG submodule - this requires `make add-rag` to have been run
@if [ -d src/ragger ]; then \
rm -rf src/ragger; \
$(MAKE) --quiet setup-ragger; \
git add .; \
echo "Updated RAG functionality, but haven't committed the changes yet (if any). Please commit them manually."; \
else \
echo "RAG code not found. Please run 'make add-rag' first."; \
fi
{%- endif %}
{%- if cookiecutter.dependency_manager != 'pip' %}

install-pipx:
@if [ "$(shell which pipx)" = "" ]; then \
uname=$$(uname); \
Expand Down Expand Up @@ -136,18 +99,10 @@ install-dependencies:
{%- endif %}

setup-environment-variables:
@if [ -d src/ragger ]; then \
{{'poetry run ' if cookiecutter.dependency_manager != 'pip' else '. .venv/bin/activate && '}}python src/scripts/fix_dot_env_file.py --include-openai; \
else \
{{'poetry run ' if cookiecutter.dependency_manager != 'pip' else '. .venv/bin/activate && '}}python src/scripts/fix_dot_env_file.py; \
fi
{{'poetry run ' if cookiecutter.dependency_manager != 'pip' else '. .venv/bin/activate && '}}python src/scripts/fix_dot_env_file.py; \

setup-environment-variables-non-interactive:
@if [ -d src/ragger ]; then \
{{'poetry run ' if cookiecutter.dependency_manager != 'pip' else '. .venv/bin/activate && '}}python src/scripts/fix_dot_env_file.py --include-openai --non-interactive; \
else \
{{'poetry run ' if cookiecutter.dependency_manager != 'pip' else '. .venv/bin/activate && '}}python src/scripts/fix_dot_env_file.py --non-interactive; \
fi
{{'poetry run ' if cookiecutter.dependency_manager != 'pip' else '. .venv/bin/activate && '}}python src/scripts/fix_dot_env_file.py --non-interactive; \

setup-git:
@git config --global init.defaultBranch main
Expand Down Expand Up @@ -222,3 +177,10 @@ type-check: ## Type-check the project
{%- else -%}
. .venv/bin/activate && mypy . --install-types --non-interactive --ignore-missing-imports --show-error-codes --check-untyped-defs
{%- endif %}

add-rag: ## Install the Ragger package, for RAG projects
{% if cookiecutter.dependency_manager != 'pip' -%}
@poetry add git+ssh://[email protected]/alexandrainst/ragger.git --extras all
{%- else -%}
. .venv/bin/activate && pip install ragger[all]@git+ssh://[email protected]/alexandrainst/ragger.git
{%- endif %}
17 changes: 2 additions & 15 deletions {{cookiecutter.project_name}}/src/scripts/fix_dot_env_file.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Checks related to the .env file in the repository.
Usage:
python src/scripts/fix_dot_env_file.py [--non-interactive] [--include-openai]
python src/scripts/fix_dot_env_file.py [--non-interactive]
"""

import subprocess
from pathlib import Path

import click
Expand All @@ -15,8 +14,6 @@
GIT_EMAIL="Enter your email, as registered on your Github account:\n> ",
)

OPENAI_ENVIRONMENT_VARIABLES = dict(OPENAI_API_KEY="Enter your OpenAI API key:\n> ")


@click.command()
@click.option(
Expand All @@ -25,20 +22,12 @@
default=False,
help="If set, the script will not ask for user input.",
)
@click.option(
"--include-openai",
is_flag=True,
default=False,
help="If set, the script will also ask for OpenAI environment variables.",
)
def fix_dot_env_file(non_interactive: bool, include_openai: bool) -> None:
def fix_dot_env_file(non_interactive: bool) -> None:
"""Ensures that the .env file exists and contains all desired variables.
Args:
non_interactive:
If set, the script will not ask for user input.
include_openai:
If set, the script will also ask for OpenAI environment variables.
"""
env_path = Path(".env")
name_and_email_path = Path(".name_and_email")
Expand All @@ -60,8 +49,6 @@ def fix_dot_env_file(non_interactive: bool, include_openai: bool) -> None:
}

desired_env_vars = DESIRED_ENVIRONMENT_VARIABLES
if include_openai:
desired_env_vars |= OPENAI_ENVIRONMENT_VARIABLES

# For each of the desired environment variables, check if it exists in the .env
# file
Expand Down

0 comments on commit 1fee7db

Please sign in to comment.