-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from baloise/main
Refactor api routes
- Loading branch information
Showing
20 changed files
with
216 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
poetry.lock | ||
.install.stamp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
{ | ||
"recommendations": ["matangover.mypy"] | ||
"recommendations": [ | ||
"matangover.mypy", | ||
"pamaron.pytest-runner", | ||
"tamasfe.even-better-toml", | ||
"ms-vscode.makefile-tools" | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,41 @@ | ||
FROM python:3.13-bookworm | ||
FROM alpine:latest | ||
|
||
# set metadata | ||
LABEL maintainer="culmat, trichie, robbizbal" \ | ||
description="Yo-Yo-Maskr application Docker image" \ | ||
version="0.1.0" | ||
|
||
WORKDIR /app | ||
# set default environment variables | ||
ENV OLLAMA_BASE_URL=http://localhost:11434 \ | ||
OLLAMA_MODEL=llama3.2:latest \ | ||
HTTPX_CLIENT_VERIFY= | ||
|
||
# install Python and dependencies | ||
RUN apk add --no-cache --update \ | ||
python3 \ | ||
py3-pip \ | ||
make \ | ||
bash \ | ||
&& rm -rf ~/.cache/* /usr/local/share/man /tmp/* | ||
|
||
RUN python3 -m pip install pipx --break-system-packages \ | ||
&& python3 -m pipx ensurepath \ | ||
&& python3 -m pipx completions | ||
|
||
# add app src | ||
COPY . /app/ | ||
|
||
RUN "./install_dependencies.sh" | ||
# set workdir | ||
WORKDIR /app | ||
|
||
# set script permissions | ||
RUN chmod +x entrypoint.sh setup.sh | ||
|
||
# run app setup script | ||
RUN "./setup.sh" | ||
|
||
# expose port | ||
EXPOSE 8000 | ||
|
||
CMD ["fastapi", "run", "src/api.py"] | ||
# run app | ||
ENTRYPOINT ["/app/entrypoint.sh"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Define variables | ||
POETRY := $(shell command -v poetry 2> /dev/null) | ||
INSTALL_STAMP := .install.stamp | ||
|
||
# Set the default goal | ||
.DEFAULT_GOAL := help | ||
|
||
# Declare phony targets | ||
.PHONY: help install clean lint format test cleaner run dev | ||
|
||
# Help target to display available commands | ||
help: | ||
@echo "Please use 'make <target>' where <target> is one of:" | ||
@echo "" | ||
@echo " install - Install packages and prepare environment" | ||
@echo " clean - Remove all temporary files" | ||
@echo " cleaner - Remove all temporary files and the .venv folder" | ||
@echo " lint - Run the code linters" | ||
@echo " format - Reformat code" | ||
@echo " test - Run all the tests" | ||
@echo " dev - Run in dev mode with auto reload" | ||
@echo " run - Run in prod mode with 4 workers" | ||
@echo "" | ||
|
||
# Install target to set up the environment with Poetry | ||
install: $(INSTALL_STAMP) | ||
|
||
$(INSTALL_STAMP): pyproject.toml | ||
@if [ -z $(POETRY) ]; then echo "Poetry could not be found. Please install it."; exit 2; fi | ||
$(POETRY) install | ||
touch $(INSTALL_STAMP) | ||
|
||
# Clean target to remove temporary files and caches | ||
clean: | ||
find . -type d -name "__pycache__" | xargs rm -rf {} | ||
rm -rf $(INSTALL_STAMP) .coverage .mypy_cache | ||
|
||
# Clean target to remove temporary files and caches | ||
cleaner: | ||
$(MAKE) clean | ||
rm -rf .venv | ||
|
||
# Lint target to run code linters | ||
lint: $(INSTALL_STAMP) | ||
$(POETRY) run ruff check . | ||
$(POETRY) run mypy . | ||
|
||
# Format target to reformat code using Black | ||
format: $(INSTALL_STAMP) | ||
$(POETRY) run ruff format . | ||
|
||
# Test target to run tests with coverage | ||
test: $(INSTALL_STAMP) | ||
$(POETRY) run pytest . | ||
|
||
# Run target to execute the application for production | ||
dev: $(INSTALL_STAMP) | ||
$(POETRY) run uvicorn src.app:app --host 0.0.0.0 --port 8000 --reload | ||
|
||
# Run target to execute the application for production | ||
run: $(INSTALL_STAMP) | ||
# $(POETRY) run gunicorn src.app:app --workers 4 --worker-class uvicorn.workers.UvicornWorker | ||
$(POETRY) run uvicorn src.app:app --host 0.0.0.0 --port 8000 --reload | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
#set -x | ||
echo "$(cat banner.txt)" | ||
export PATH="/root/.local/bin:$PATH" | ||
make run |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pipx install poetry | ||
pipx ensurepath | ||
. ~/.bashrc | ||
make install |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import fastapi | ||
from fastapi.responses import JSONResponse | ||
from fastapi import Request, routing | ||
|
||
router = fastapi.APIRouter() | ||
|
||
@router.get("/health", response_class=JSONResponse, include_in_schema=False) | ||
def health(): | ||
return {"status": "ok"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import fastapi | ||
from fastapi.responses import JSONResponse | ||
from fastapi import Request, routing | ||
from pydantic import BaseModel | ||
from ..utils.llm import llm_find_entities | ||
|
||
router = fastapi.APIRouter() | ||
|
||
class MaskRequest(BaseModel): | ||
text: str | ||
|
||
@router.post("/mask", response_class=JSONResponse, include_in_schema=True) | ||
async def mask(request: MaskRequest): | ||
entities = llm_find_entities(request.text) | ||
return {"original_text": request.text, "llm_entities": entities} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from fastapi import FastAPI | ||
|
||
from src.gui import landing | ||
from src.api import health | ||
from src.api import mask | ||
|
||
app = FastAPI() | ||
|
||
app.include_router(landing.router) | ||
app.include_router(health.router, prefix="/api") | ||
app.include_router(mask.router, prefix="/api") | ||
|
||
if __name__ == "__main__": | ||
import uvicorn | ||
uvicorn.run(app, host="0.0.0.0", port=8000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import fastapi | ||
from fastapi.responses import HTMLResponse | ||
from fastapi import Request, routing | ||
|
||
router = fastapi.APIRouter() | ||
|
||
@router.get("/", response_class=HTMLResponse, include_in_schema=False) | ||
def landing(): | ||
return "<h1>hola mundo</h1>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Simple Form</title> | ||
</head> | ||
<body> | ||
<h1>Contact Us</h1> | ||
<form method="post"> | ||
<label for="name">Name:</label><br> | ||
<input type="text" id="name" name="name"><br><br> | ||
|
||
<label for="email">Email:</label><br> | ||
<input type="email" id="email" name="email"><br><br> | ||
|
||
<input type="submit" value="Submit"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from dotenv import load_dotenv | ||
import os | ||
load_dotenv() | ||
|
||
OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL") | ||
OLLAMA_MODEL = os.getenv("OLLAMA_MODEL") | ||
HTTPX_CLIENT_VERIFY = os.getenv("HTTPX_CLIENT_VERIFY") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters