Skip to content

Commit

Permalink
Merge pull request #187 from alan-turing-institute/create-cli
Browse files Browse the repository at this point in the history
Tidy up CLI using Typer
  • Loading branch information
rchan26 authored Jun 12, 2024
2 parents a37292a + b462116 commit 2899713
Show file tree
Hide file tree
Showing 17 changed files with 2,038 additions and 900 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint_code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: 3.11
- uses: pre-commit/[email protected].0
- uses: pre-commit/[email protected].1
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/python-poetry/poetry
rev: 1.8.3
hooks:
- id: poetry-check
- id: poetry-lock

- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion ENVIRONMENT_VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Lastly, to avoid using CLI variables and be able to simply use `reginald_run`, y
- For `chat-completion-openai` and `llama-index-gpt-openai`, this refers to the model/engine name on OpenAI
- `LLAMA_INDEX_MODE`: mode to use ("query" or "chat") if using `llama-index` model
- `LLAMA_INDEX_DATA_DIR`: data directory if using `llama-index` model
- `LLAMA_INDEX_WHICH_INDEX`: index to use ("handbook", "wikis", "public" or "all_data") if using `llama-index` model
- `LLAMA_INDEX_WHICH_INDEX`: index to use ("handbook", "wikis", "public", "reg" or "all_data") if using `llama-index` model
- `LLAMA_INDEX_FORCE_NEW_INDEX`: whether to force a new index if using `llama-index` model
- `LLAMA_INDEX_MAX_INPUT_SIZE`: max input size if using `llama-index-llama-cpp` or `llama-index-hf` model
- `LLAMA_INDEX_IS_PATH`: whether to treat REGINALD_MODEL_NAME as a path if using `llama-index-llama-cpp` model
Expand Down
71 changes: 51 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,42 @@ Once, you do this, simply add this to your `.env` file:
echo "GITHUB_TOKEN='your-github-personal-access-token'" >> .env
```

### Running the Reginald bot locally
### running Reginald locally (without Slack)

In order to run the full Reginald app locally (i.e. setting up the full response engine along with the Slack bot), you can follow the steps below:
It is possible to run the Reginald model locally and interact with it completely through the command line via the `reginald chat` CLI - note that this is a wrapper around the [`reginald.run.run_chat_interact`](/reginald/run.py) function. To see CLI arguments:

1. Set environment variables (for more details on environtment variables, see the [environment variables README](ENVIRONMENT_VARIABLES.md)):
```bash
reginald chat --help
```

```bash
source .env
```
For example with using the `llama-index-llama-cpp` model running [Llama-2-7b-Chat](https://huggingface.co/TheBloke/Llama-2-7b-Chat-GGUF) (quantised to 4bit), you can run:

```bash
reginald chat \
--model llama-index-llama-cpp \
--model-name https://huggingface.co/TheBloke/Llama-2-7b-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf \
--mode chat \
--data-dir data/ \
--which-index handbook \
--n-gpu-layers 2
```

1. Run the bot using `reginald_run` - note that this actually runs [`reginald/run.py`](https://github.com/alan-turing-institute/reginald/blob/main/reginald/run.py). To see CLI arguments:
For an example with using the `llama-index-ollama` model running Llama3, you can run:

```bash
reginald_run --help
```
```bash
reginald chat \
--model llama-index-ollama \
--model-name llama3 \
--mode chat \
--data-dir data/ \
--which-index handbook
```

where you have set the `OLLAMA_API_ENDPOINT` environment variable to the endpoint of the OLLAMA API.

**For examples of running each of our different models, see the [models README](MODELS.md).**

The `reginald_run` CLI takes in several arguments such as:
The `reginald run_all` CLI takes in several arguments such as:
- `--model` (`-m`): to select the type of model to use (see the [models README](MODELS.md) for the list of models available)
- `--model-name` (`-n`): to select the sub-model to use within the model selected
- For `llama-index-llama-cpp` and `llama-index-hf` models, this specifies the LLM (or path to that model) which we would like to use
Expand All @@ -126,16 +143,31 @@ There are some CLI arguments specific to only the `llama-index-hf` model:

**Note**: specifying CLI arguments will override any environment variables set.

### Running the Reginald bot locally with Slack

In order to run the full Reginald app locally (i.e. setting up the full response engine along with the Slack bot), you can follow the steps below:

1. Set environment variables (for more details on environtment variables, see the [environment variables README](ENVIRONMENT_VARIABLES.md)):

```bash
source .env
```

1. Run the bot using `reginald run_all` - note that this is a wrapper around the [`reginald.run.run_full_pipeline`](/reginald/run.py) function. To see CLI arguments:

```bash
reginald run_all --help
```

For example, to set up a `llama-index-llama-cpp` _chat engine_ model running [Llama-2-7b-Chat](https://huggingface.co/TheBloke/Llama-2-7b-Chat-GGUF) (quantised to 4bit), you can run:

```bash
reginald_run \
reginald run_all \
--model llama-index-llama-cpp \
--model-name https://huggingface.co/TheBloke/Llama-2-7b-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf \
--mode chat \
--data-dir data/ \
--which-index handbook \
--max-input-size 4096 \
--n-gpu-layers 2
```

Expand All @@ -158,22 +190,21 @@ To do this, you can follow the steps below:
source .response_engine_env
```

2. Set up response engine using `reginald_run_api_llm` - note that this actually runs [`reginald/models/app.py`](https://github.com/alan-turing-institute/reginald/blob/main/reginald/models/app.py). To see CLI arguments:
2. Set up response engine using `reginald app` - note that this is a wrapper around the [`reginald.run.run_reginald_app`](/reginald/run.py) function. To see CLI arguments:

```bash
reginald_run_api_llm --help
reginald app --help
```

This command uses many of the same CLI arguments as described above. For example to set up a `llama-index-llama-cpp` _chat engine_ model running [Llama-2-7b-Chat](https://huggingface.co/TheBloke/Llama-2-7b-Chat-GGUF) (quantised to 4bit), you can run:

```bash
reginald_run_api_llm \
reginald app \
--model llama-index-llama-cpp \
--model-name https://huggingface.co/TheBloke/Llama-2-7b-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf \
--mode chat \
--data-dir data/ \
--which-index handbook \
--max-input-size 4096 \
--n-gpu-layers 2
```

Expand All @@ -185,16 +216,16 @@ To do this, you can follow the steps below:
source .slack_bot_env
```
2. Set up Slack bot using `reginald_run_api_bot` - note that this actually runs [`reginald/slack_bot/setup_bot.py`](https://github.com/alan-turing-institute/reginald/blob/main/reginald/slack_bot/setup_bot.py). To see CLI arguments:
2. Set up Slack bot using `reginald bot` - note that this is a wrapper around the [`reginald.run.run_bot`](/reginald/run.py) function. To see CLI arguments:

```bash
reginald_run_api_bot --help
reginald bot --help
```

This command takes in an emoji to respond with. For example, to set up a Slack bot that responds with the `:llama:` emoji, you can run:

```bash
reginald_run_api_bot --emoji llama
reginald bot --emoji llama
```

### Running the bot in Docker
Expand Down
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The following environment variables can be used by this image:
- For `chat-completion-openai` and `llama-index-gpt-openai`, this refers to the model/engine name on OpenAI
- `LLAMA_INDEX_MODE`: mode to use ("query" or "chat") if using `llama-index` model
- `LLAMA_INDEX_DATA_DIR`: data directory if using `llama-index` model
- `LLAMA_INDEX_WHICH_INDEX`: index to use ("handbook", "wikis", "public" or "all_data") if using `llama-index` model
- `LLAMA_INDEX_WHICH_INDEX`: index to use ("handbook", "wikis", "public", "reg" or "all_data") if using `llama-index` model
- `LLAMA_INDEX_FORCE_NEW_INDEX`: whether to force a new index if using `llama-index` model
- `LLAMA_INDEX_MAX_INPUT_SIZE`: max input size if using `llama-index-llama-cpp` or `llama-index-hf` model
- `LLAMA_INDEX_IS_PATH`: whether to treat REGINALD_MODEL_NAME as a path if using `llama-index-llama-cpp` model
Expand Down
Loading

0 comments on commit 2899713

Please sign in to comment.