Skip to content

Commit

Permalink
⚡ Add cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Paillat-dev committed Jun 20, 2024
1 parent 34d3453 commit e31c8b2
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 72 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

cache/
4 changes: 3 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
from fastapi.security import OAuth2PasswordBearer
from concurrent.futures import ThreadPoolExecutor
from dotenv import load_dotenv
from cachier import cachier

load_dotenv()

app = FastAPI()

# auth with a bearer api key, whoose hash is stored in the environment variable API_KEY_HASH
# auth with a bearer api key, whose hash is stored in the environment variable API_KEY_HASH
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
API_KEY_HASH = os.getenv("API_KEY_HASH")
assert API_KEY_HASH, "API_KEY_HASH environment variable must be set"
Expand All @@ -42,6 +43,7 @@ class Classification(BaseModel):
scores: list[float] = [0.0] * len(DEFAULT_LABELS)


@cachier(cache_dir="./cache")
def classify_sync(message: str, labels: list[str]) -> dict:
result = classifier(message, candidate_labels=labels)
return result
Expand Down
83 changes: 82 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies = [
"numpy<2",
"transformers>=4.41.2",
"fastapi>=0.111.0",
"cachier>=3.0.0",
]
requires-python = "==3.11.*"
readme = "README.md"
Expand Down
70 changes: 0 additions & 70 deletions requiements.txt

This file was deleted.

5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

annotated-types==0.7.0
anyio==4.4.0
cachier==3.0.0
certifi==2024.6.2
charset-normalizer==3.3.2
click==8.1.7
Expand Down Expand Up @@ -42,16 +43,19 @@ nvidia-nvjitlink-cu12==12.5.40; platform_system == "Linux" and platform_machine
nvidia-nvtx-cu12==12.1.105; platform_system == "Linux" and platform_machine == "x86_64"
orjson==3.10.5
packaging==24.1
portalocker==2.8.2
pydantic==2.7.4
pydantic-core==2.18.4
pygments==2.18.0
python-dotenv==1.0.1
python-multipart==0.0.9
pywin32==306; platform_system == "Windows"
pyyaml==6.0.1
regex==2024.5.15
requests==2.32.3
rich==13.7.1
safetensors==0.4.3
setuptools==70.1.0
shellingham==1.5.4
sniffio==1.3.1
starlette==0.37.2
Expand All @@ -68,5 +72,6 @@ ujson==5.10.0
urllib3==2.2.2
uvicorn==0.30.1
uvloop==0.19.0; (sys_platform != "cygwin" and sys_platform != "win32") and platform_python_implementation != "PyPy"
watchdog==4.0.1
watchfiles==0.22.0
websockets==12.0

0 comments on commit e31c8b2

Please sign in to comment.