Skip to content

Commit

Permalink
Merge pull request #13 from tommylees112/aws_lambda
Browse files Browse the repository at this point in the history
[WHA-10] update d2 files
  • Loading branch information
tommylees112 authored Sep 13, 2024
2 parents b04cefd + 6bbd073 commit 2a37c30
Show file tree
Hide file tree
Showing 28 changed files with 729 additions and 778 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FLASK_APP=INSERT_HERE
COHERE_API_KEY=INSERT_HERE
TWILIO_ACCOUNT_SID=INSERT_HERE
TWILIO_AUTH_TOKEN=INSERT_HERE
TWILIO_PHONE_NUMBER=INSERT_HERE
Empty file added .github/workflows/deploy.yml
Empty file.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
__pycache__
.vscode
.ruff_cache
d2/*.png
d2/*.png
.pytest_cache
.gcloud_env.sh
upload_secrets.sh
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ repos:
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/psf/black
rev: 21.11b0 # Use the latest version of Black
hooks:
- id: black
args: [--fast] # Use the fast mode of Black
additional_dependencies: [click==8.0.4] # Use specific version of click
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.373 # Use the latest Pyright version
hooks:
- id: pyright
- repo: https://github.com/pycqa/isort
rev: 5.12.0 # Use the latest version available
hooks:
- id: isort
name: isort (python)
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.9-slim@sha256:980b778550c0d938574f1b556362b27601ea5c620130a572feb63ac1df03eda5

ENV PYTHONUNBUFFERED True

ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# set the port to 1234
ENV PORT 1234

# create the environment and install the dependencies
RUN pip install --no-cache-dir -r requirements.txt

# As an example here we're running the web service with one worker on uvicorn.
CMD exec uvicorn src.main:app --host 0.0.0.0 --port ${PORT} --workers 1
3 changes: 0 additions & 3 deletions Procfile

This file was deleted.

139 changes: 82 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,110 @@
This project is a WhatsApp chatbot that uses the Cohere Command R+ model to summarize web links sent to it.

## Features
- Summarizes the content of web pages.

- Summarizes the content of web pages using the LangChain WebBaseLoader to extract information from URLs.
- Integrated with WhatsApp via Twilio API.
- Uses Cohere Command R+ model for summarization.
- Deployed on Heroku.
- Deployed on Google Cloud Run.

## Deployment
![Facebook Whatsapp Manager](src/static/facebook_whatsapp.png)
![Verification of whatsapp](src/static/whatsapp_verification.png)
[Connection to Whatsapp via twilio](https://www.twilio.com/docs/whatsapp/self-sign-up)
## Setup

Deployed [here](https://stormy-fortress-61944-2c1ff9dc107f.herokuapp.com/) on Heroku.
```
1. Clone the repository:
```bash
git clone https://github.com/tommylees112/whatsappLLM
cd whatsappLLM
```

heroku addons:info redis-pointy-97986
```
2. Create a Python environment and install dependencies:
```bash
pip install -r requirements.txt
```

## Monitoring
3. Set up environment variables:
Create a `.env` file in the root directory and add the following variables:
```
TWILIO_ACCOUNT_SID=your_twilio_account_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
TWILIO_PHONE_NUMBER=your_twilio_phone_number
OG_TWILIO_PHONE_NUMBER=your_og_twilio_phone_number
COHERE_API_KEY=your_cohere_api_key
```

- [Heroku](https://dashboard.heroku.com/apps/stormy-fortress-61944)
- [Twilio Whatsapp Senders](https://console.twilio.com/us1/develop/sms/senders/whatsapp-senders/XE2357b321ff41b31f05ca6b44fd626c5d)
- [Twilio SMS Logs](https://console.twilio.com/us1/monitor/logs/sms)
- [Meta Whatsapp Business Homepage](https://business.facebook.com/settings/info?business_id=965893078343863)
- [Cohere dashboard](https://dashboard.cohere.com/api-keys)
4. Run the FastAPI server locally:
```bash
uvicorn src.main:app --reload
```

Check heroku status
```bash
heroku login
5. (Optional) Run ngrok to expose the server to the internet:
```bash
ngrok http 8000
```

heroku logs --tail
## Deployment

# check the status of the dynos
heroku ps
Following this [guide](https://github.com/sekR4/FastAPI-on-Google-Cloud-Run?tab=readme-ov-file)

heroku logs --tail --ps worker
This project is set up to be deployed on Google Cloud Run. Use the following commands to build and deploy:

```bash
export PROJECT_ID=<YOUR_UNIQUE_LOWER_CASE_PROJECT_ID>
export APP=myapp
export PORT=1234
export REGION="europe-west3"
export TAG="gcr.io/$PROJECT_ID/$APP"
docker build -t $TAG . && docker run -dp $PORT:$PORT -e PORT=$PORT $TAG
```

Create bash session in the virtual machine
[Upload secrets to github](https://cli.github.com/manual/gh_secret_set)
```bash
gh secret set COHERE_API_KEY --body "KEY_GOES_HERE"
gh secret set COHERE_API_KEY --body "KEY_GOES_HERE"
gh secret set TWILIO_ACCOUNT_SID --body "KEY_GOES_HERE"
gh secret set TWILIO_AUTH_TOKEN --body "KEY_GOES_HERE"
gh secret set TWILIO_PHONE_NUMBER --body "KEY_GOES_HERE"
```
heroku run bash

$ celery -A src.app.celery status
# See all info about the app
```bash
gcloud run services describe $APP --region $REGION

URL=$(gcloud run services describe $APP --region $REGION --format 'value(status.url)')

curl $URL

gcloud run services update my-service \
--location=us-central1 \
--update-env-vars=MY_VAR=my_value,ANOTHER_VAR=another_value
```

## Setup

1. Clone the repository:
```bash
git clone https://github.com/tommylees112/whatsappLLM
cd whatsappLLM
```
## Monitoring

2. Create the python environment & install dependencies
```
```
- [Twilio Whatsapp Senders](https://console.twilio.com/us1/develop/sms/senders/whatsapp-senders/XE2357b321ff41b31f05ca6b44fd626c5d)
- [Twilio SMS Logs](https://console.twilio.com/us1/monitor/logs/sms)
- [Meta Whatsapp Business Homepage](https://business.facebook.com/settings/info?business_id=965893078343863)
- [Cohere dashboard](https://dashboard.cohere.com/api-keys)

2. Run the flask server locally
```bash
export FLASK_APP=src/app.py

flask run
```
## Development

3. Run the ngrok server exposing it to the internet
```
ngrok http 5000
```

4. Start the redis broker and check it
```bash
brew services start redis
redis-cli ping
This project uses pre-commit hooks for code quality. To set up pre-commit:

redis-server
```
1. Install pre-commit: `pip install pre-commit`
2. Set up the git hooks: `pre-commit install`

5. Start the celeery worker
```
celery -A src.app.celery worker --loglevel=debug
The pre-commit configuration can be found in `.pre-commit-config.yaml`.

## Testing

To run tests, use the following command:
```bash
pytest
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

celery -A src.app.celery inspect ping
```
This project is open source and available under the [MIT License](LICENSE).
98 changes: 0 additions & 98 deletions environment.yml

This file was deleted.

Loading

0 comments on commit 2a37c30

Please sign in to comment.