Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up CLI using Typer #187

Merged
merged 27 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b629b75
feat: add `cli.py` to call refactor of `run.py`
spool Jun 10, 2024
1083908
chore: apply `pre-commit`
spool Jun 10, 2024
88da200
feat(ci): add `poetry-lock` and `poetry-check` `pre-commit`
spool Jun 10, 2024
7be7052
replace boolean args to string and fix error with bot
rchan26 Jun 10, 2024
92f12fc
add arguments to app and run-all cli
rchan26 Jun 10, 2024
97ba844
add create-index cli
rchan26 Jun 10, 2024
62cd9b0
dependency bot upgrades
rchan26 Jun 10, 2024
c924227
examples of help
rchan26 Jun 11, 2024
291324f
first cli for interaction
rchan26 Jun 11, 2024
5f6eebe
change to use tiktoken and add cli for chat
rchan26 Jun 11, 2024
f03d989
fix error in chat interaction function
rchan26 Jun 11, 2024
c5d219b
fix(test): add passing `test_chat_cli` and `test_chat_interactive_exit`
spool Jun 11, 2024
5a48bb4
something i cant remember
rchan26 Jun 11, 2024
3c4ed88
fix(ci): run `poetry.lock`
spool Jun 11, 2024
b4eb3e4
update poetry lock using 1.8.3
rchan26 Jun 11, 2024
09cea8e
fix(ci): add `poetry` as a `dev` dependency
spool Jun 11, 2024
8f0057b
Merge remote-tracking branch 'origin/create-cli' into create-cli
spool Jun 11, 2024
89f044f
fix(ci): upgrade `.pre-commt` `poetry 1.7.0` -> `1.8.3`
spool Jun 11, 2024
fa224ed
fix(ci): upgrade `.pre-commt` `poetry 1.8.2` -> `1.8.3`
spool Jun 11, 2024
af4ef86
fix(ci): force run `poetry.lock` check
spool Jun 11, 2024
096aee5
add help to cli options
rchan26 Jun 11, 2024
f422c39
update readme to new CLI
rchan26 Jun 11, 2024
47f649f
add 'reg' data index option
rchan26 Jun 11, 2024
400eb0e
add 'reg' data index option
rchan26 Jun 11, 2024
2cb0197
update docker readme
rchan26 Jun 11, 2024
c42ee8f
Merge branch 'main' into create-cli
rchan26 Jun 12, 2024
b462116
chore: update `poetry.lock`
spool Jun 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading