https://github.com/alan-turing-institute/reginald
Reginald repository for REG Hack Week 23
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.5%) to scientific vocabulary
Repository
Reginald repository for REG Hack Week 23
Basic Info
- Host: GitHub
- Owner: alan-turing-institute
- Language: Jupyter Notebook
- Default Branch: main
- Size: 88.7 MB
Statistics
- Stars: 3
- Watchers: 12
- Forks: 0
- Open Issues: 24
- Releases: 1
Metadata Files
README.md
Reginald
The Reginald project consists of:
├── azure
│ └── scripts to setup Reginald infrastructure on Azure
├── data
│ └── directory to store llama-index data indexes and other public Turing data
├── docker
│ └── scripts for building a Docker images for both Reginald app and Slack-bot only app
├── notebooks
│ └── data processing notebooks
│ └── development notebooks for llama-index Reginald models
└── reginald
└── models: scripts for setting up query and chat engines
└── slack_bot: scripts for setting up Slack bot
└── scripts for setting up end to end Slack bot with query engine
Slack bot
This is a simple Slack bot written in Python that listens for direct messages and @mentions in any channel it is in and responds with a message and an emoji.
The bot uses web sockets for communication.
How the bot responds to messages is determined by the response engine that is set up - see the models README for more details of the models available.
The main models we use are:
- llama-index-llama-cpp: a model which uses the llama-index library to query a data index and then uses a quantised LLM (implemented using llama-python-cpp) to generate a response
- llama-index-hf: a model which uses the llama-index library to query a data index and then uses an LLM from Huggingface to generate a response
- llama-index-gpt-azure: a model which uses the llama-index library to query a data index and then uses the Azure OpenAI API to query a LLM to generate a response
Prerequisites
This project uses Poetry for dependency management. Make sure you have Poetry installed on your machine.
Install the project dependencies:
bash
poetry install --all-extras
If you only want to run a subset of the available packages then use:
- for the LLM-only and Slack-bot-only setup:
--extras api_bot - for the Azure configuration:
--extras azure - for running notebooks regarding using fine-tuning:
--extras ft_notebooks - for running notebooks regarding using
llama-index:--extras llama_index_notebooks
Without installing extras, you will have the packages required in order to run the full Reginald model on your machine.
Install the pre-commit hooks
bash
pre-commit install
Obtaining Slack tokens
To set up the Slack bot, you must set Slack bot environment variables. To obtain them from Slack, follow the steps below:
Set up the bot in Slack: Socket Mode Client.
To connect to Slack, the bot requires an app token and a bot token. Put these into into a
.envfile:bash echo "SLACK_BOT_TOKEN='your-bot-user-oauth-access-token'" >> .env echo "SLACK_APP_TOKEN='your-app-level-token'" >> .envActivate the virtual environment:
bash poetry shell
GitHub access tokens
We are currently using llama-hub GitHub readers for creating our data indexes and pulling from relevant repos for issues and files.
As a prerequisite, you will need to generate a "classic" personal access token with the repo and read:org scopes - see here for instructions for creating and obtaining your personal access token.
Once, you do this, simply add this to your .env file:
bash
echo "GITHUB_TOKEN='your-github-personal-access-token'" >> .env
running Reginald locally (without Slack)
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 function. To see CLI arguments:
bash
reginald chat --help
For example with using the llama-index-llama-cpp model running Llama-2-7b-Chat (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
For an example with using the llama-index-ollama model running Llama3, you can run:
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.
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 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
- For chat-completion-azure and llama-index-gpt-azure, this refers to the deployment name on Azure
- For chat-completion-openai and llama-index-gpt-openai, this refers to the model/engine name on OpenAI
There are some CLI arguments specific to only the llama-index models:
- --mode: to determine whether to use 'query' or 'chat' engine
- --data-dir (-d): specify the data directory location
- --which-index (-w): specify the directory name for looking up/writing data index (for llama-index models)
- --force-new-index (-f): whether or not to force create a new data index
There are some CLI arguments specific to only the llama-index-llama-cpp and llama-index-hf models:
- --max-input-size (-max): maxumum input size of LLM
There are some CLI arguments specific to only the llama-index-llama-cpp model:
- --is-path (-p): whether or not the model-name passed is a path to the model
- --n-gpu-layers (-ngl): number of layers to offload to GPU if using llama-index-llama-cpp model
There are some CLI arguments specific to only the llama-index-hf model:
- --device (-dev): device to host Huggingface model if using 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:
Set environment variables (for more details on environtment variables, see the environment variables README):
bash source .envRun the bot using
reginald run_all- note that this is a wrapper around thereginald.run.run_full_pipelinefunction. 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 (quantised to 4bit), you can run:
bash
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 \
--n-gpu-layers 2
The bot will now listen for @mentions in the channels it's added to and respond with a simple message.
Running the response engine and Slack bot separately
There are some cases where you'd want to run the response engine and Slack bot separately.
For instance, with the llama-index-llama-cpp and llama-index-hf models, you are hosting your own LLM which you might want to host on a machine with GPUs.
The Slack bot can then be run on a separate (more cost-efficient) machine.
Doing this allows you to change the model or machine running the model without having to change the Slack bot.
To do this, you can follow the steps below:
- On the machine where you want to run the response engine, run the following command:
1. Set up environment variables for the response engine (for more details on environtment variables, see the [environment variables README](ENVIRONMENT_VARIABLES.md)):
```bash
source .response_engine_env
```
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 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 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 \
--n-gpu-layers 2
```
- On the machine where you want to run the Slack bot, run the following command:
1. Set up environment variables for the Slack bot (for more details on environtment variables, see the [environment variables README](ENVIRONMENT_VARIABLES.md)):
```bash
source .slack_bot_env
```
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 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 bot --emoji llama
```
Running the bot in Docker
For full details of Docker setup, see the Docker README.
Running the bot in Azure
Go to the
azuredirectoryEnsure that you have installed
Pulumiand theAzure CLISetup the Pulumi backend and deploy
bash
./setup.sh && AZURE_KEYVAULT_AUTH_VIA_CLI=true pulumi up -y
Owner
- Name: The Alan Turing Institute
- Login: alan-turing-institute
- Kind: organization
- Email: info@turing.ac.uk
- Website: https://turing.ac.uk
- Repositories: 477
- Profile: https://github.com/alan-turing-institute
The UK's national institute for data science and artificial intelligence.
GitHub Events
Total
Last Year
Issues and Pull Requests
Last synced: about 1 year ago
All Time
- Total issues: 78
- Total pull requests: 115
- Average time to close issues: 18 days
- Average time to close pull requests: 2 days
- Total issue authors: 6
- Total pull request authors: 8
- Average comments per issue: 1.18
- Average comments per pull request: 0.5
- Merged pull requests: 109
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- rchan26 (32)
- rwood-97 (10)
- jemrobinson (6)
- LevanBokeria (4)
- mhauru (2)
- griff-rees (1)
- tomaslaz (1)
Pull Request Authors
- dependabot[bot] (29)
- rchan26 (22)
- jemrobinson (21)
- rwood-97 (16)
- mhauru (3)
- griff-rees (2)
- ots22 (1)
- lannelin (1)
- DavidBeavan (1)
- LevanBokeria (1)
- tomaslaz (1)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v3 composite
- docker/build-push-action v4 composite
- docker/login-action v2 composite
- docker/metadata-action v4 composite
- python 3.11.4 build
- 180 dependencies
- accelerate ^0.23.0
- bitsandbytes ^0.41.1
- datasets ^2.12.0
- faiss-cpu ^1.7.4
- fastapi ^0.103.1
- gitpython ^3.1.36
- gradio ^3.34.0
- httpx ^0.25.0
- ipykernel ^6.23.2
- langchain ^0.0.327
- llama-cpp-python ^0.2.11
- llama-hub ^0.0.42
- llama-index ^0.8.57
- nbconvert ^7.8.0
- nest_asyncio ^1.5.8
- openai ^0.27.8
- pandas ^2.0.2
- pulumi ^3.70.0
- pulumi-azure-native ^1.103.0
- pydantic ^2.4.1
- python >=3.11,<3.12
- requests ^2.31.0
- safetensors ^0.3.3
- sentence-transformers ^2.2.2
- slack-sdk ^3.21.3
- torch --- - !ruby/hash:ActiveSupport::HashWithIndifferentAccess version: "^2.0.1" markers: sys_platform != 'linux' source: PyPI - !ruby/hash:ActiveSupport::HashWithIndifferentAccess version: "^2.0.1+cpu" markers: sys_platform == 'linux' source: torchcpu
- transformers ^4.33.2
- uvicorn ^0.23.2
- python 3.11.4 build
- actions/cache v3 composite
- actions/checkout v4 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- pre-commit/action v3.0.1 composite
- python 3.11.9 build
- python 3.11.9 build