This project is a WhatsApp chatbot that uses the Cohere Command R+ model to summarize web links sent to it.
- 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 Google Cloud Run.
-
Clone the repository:
git clone https://github.com/tommylees112/whatsappLLM cd whatsappLLM
-
Create a Python environment and install dependencies:
pip install -r requirements.txt
-
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 COHERE_API_KEY=your_cohere_api_key
-
Run the FastAPI server locally:
uvicorn src.main:app --reload
-
(Optional) Run ngrok to expose the server to the internet:
ngrok http 8000
If you want to test the deployment manually, follow this guide
gcloud builds submit --tag $TAG
gcloud run deploy $APP --image $TAG --platform managed --region $REGION --allow-unauthenticated
Following this guide
Automatically deployed to cloudrun on push to main or dev
This project is set up to be deployed on Google Cloud Run. Use the following commands to build and deploy:
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
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"
Add secret variables to the google Secret Manager and read from deploy.yml
.
gcloud secrets create COHERE_API_KEY --data-file=.env
gcloud secrets create TWILIO_ACCOUNT_SID --data-file=.env
gcloud secrets create TWILIO_AUTH_TOKEN --data-file=.env
gcloud secrets create TWILIO_PHONE_NUMBER --data-file=.env
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
This project uses pre-commit hooks for code quality. To set up pre-commit:
- Install pre-commit:
pip install pre-commit
- Set up the git hooks:
pre-commit install
The pre-commit configuration can be found in .pre-commit-config.yaml
.
To run tests, use the following command:
pytest
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
## CLI Option Hit the api using curl
function llm() {
local url=$1
curl -s -X 'POST' \
'<GCLOUD URL>/summarize' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "{\"url\": \"$url\"}" | jq -r ".summary" | bat
}