diff --git a/{{cookiecutter.project_name}}/makefile b/{{cookiecutter.project_name}}/makefile index c33b2d3..e301648 100644 --- a/{{cookiecutter.project_name}}/makefile +++ b/{{cookiecutter.project_name}}/makefile @@ -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 git@github.com: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); \ @@ -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 @@ -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://git@github.com/alexandrainst/ragger.git --extras all + {%- else -%} + . .venv/bin/activate && pip install ragger[all]@git+ssh://git@github.com/alexandrainst/ragger.git + {%- endif %} diff --git a/{{cookiecutter.project_name}}/src/scripts/fix_dot_env_file.py b/{{cookiecutter.project_name}}/src/scripts/fix_dot_env_file.py index 6981085..cb48926 100644 --- a/{{cookiecutter.project_name}}/src/scripts/fix_dot_env_file.py +++ b/{{cookiecutter.project_name}}/src/scripts/fix_dot_env_file.py @@ -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 @@ -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( @@ -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") @@ -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