Skip to content

Commit

Permalink
update linter
Browse files Browse the repository at this point in the history
  • Loading branch information
tommylees112 committed Sep 13, 2024
1 parent ba6063d commit 6bbd073
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 21 deletions.
Empty file added .github/workflows/deploy.yml
Empty file.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ __pycache__
.ruff_cache
d2/*.png
.pytest_cache
.gcloud_env.sh
.gcloud_env.sh
upload_secrets.sh
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ repos:
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)
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ This project is a WhatsApp chatbot that uses the Cohere Command R+ model to summ

## Deployment

Following this [guide](https://github.com/sekR4/FastAPI-on-Google-Cloud-Run?tab=readme-ov-file)

This project is set up to be deployed on Google Cloud Run. Use the following commands to build and deploy:

```bash
Expand All @@ -55,6 +57,28 @@ export TAG="gcr.io/$PROJECT_ID/$APP"
docker build -t $TAG . && docker run -dp $PORT:$PORT -e PORT=$PORT $TAG
```

[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"
```

# 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
```


## Monitoring

Expand All @@ -79,7 +103,6 @@ To run tests, use the following command:
pytest
```


## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
Expand Down
3 changes: 2 additions & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"""

import os

from dotenv import load_dotenv
from pydantic_settings import BaseSettings
from pydantic import Field
from pydantic_settings import BaseSettings

# Load environment variables from .env file
load_dotenv()
Expand Down
6 changes: 4 additions & 2 deletions src/core/summarizer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import re
from typing import List

from langchain_community.document_loaders import WebBaseLoader
from langchain_core.documents.base import Document
from typing import List
from loguru import logger

from src.services.cohere import CohereService
import re


class Summarizer:
Expand Down
8 changes: 4 additions & 4 deletions src/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
Provide reusable components for the application.
"""

from src.services.summarizer import Summarizer
from src.services.cohere import CohereService
from src.services.twilio import TwilioService
from src.config import settings
from typing import cast

from src.config import settings
from src.services.cohere import CohereService
from src.services.summarizer import Summarizer
from src.services.twilio import TwilioService

cohere_service = CohereService(cast(str, settings.COHERE_API_KEY))
twilio_service = TwilioService(
Expand Down
14 changes: 9 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from fastapi import FastAPI, Depends, HTTPException, Request, Response
import json
import os

import uvicorn
from fastapi import Depends, FastAPI, HTTPException, Request, Response
from loguru import logger
from pydantic import BaseModel, Field

from src.dependencies import get_summarizer, get_twilio_service
from src.services.summarizer import Summarizer
from src.services.twilio import TwilioService
from src.dependencies import get_summarizer, get_twilio_service
from loguru import logger
import uvicorn
import json

app = FastAPI()

Expand Down Expand Up @@ -96,4 +99,5 @@ async def webhook(

if __name__ == "__main__":
logger.info("Starting FastAPI server...")
port = int(os.environ.get("PORT", 8080))
uvicorn.run("src.main:app", host="0.0.0.0", port=8000, reload=True)
5 changes: 3 additions & 2 deletions src/services/cohere.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import cohere
from cohere.types.non_streamed_chat_response import NonStreamedChatResponse
from loguru import logger

from src.config import settings
from src.utils import analyze_text
from loguru import logger
import cohere


class CohereService:
Expand Down
6 changes: 4 additions & 2 deletions src/services/summarizer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import re
from typing import List

from langchain_community.document_loaders import WebBaseLoader
from langchain_core.documents.base import Document
from typing import List
from loguru import logger

from src.services.cohere import CohereService
from src.utils import append_protocol_to_url
import re


class Summarizer:
Expand Down
3 changes: 2 additions & 1 deletion src/services/twilio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from twilio.rest import Client
from loguru import logger
from twilio.rest import Client

from src.config import settings
from src.utils import analyze_text

Expand Down
4 changes: 2 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def append_protocol_to_url(url: str) -> str:

def analyze_text(text: str, use_nltk: bool = False) -> dict:
if use_nltk:
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize, sent_tokenize
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import sent_tokenize, word_tokenize

nltk.download("stopwords")

Expand Down

0 comments on commit 6bbd073

Please sign in to comment.