Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasFaria committed Apr 22, 2024
1 parent 42c9e0c commit e5501e6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 67 deletions.
56 changes: 0 additions & 56 deletions app/dev.py

This file was deleted.

17 changes: 10 additions & 7 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,17 @@ async def predict_batch(
prob_min: float = 0.01,
):
"""
Endpoint for predicting batches of data.
Args:
credentials (HTTPBasicCredentials): The credentials for authentication.
liasses (Liasses): The input data in the form of Liasses object.
nb_echos_max (int, optional): The maximum number of predictions to return. Defaults to 5.
prob_min (float, optional): The minimum probability threshold for predictions. Defaults to 0.01.
Returns:
dict: Response containing APE codes.
list: The list of predicted responses.
"""

query = preprocess_batch(training_names, liasses.dict())

if nb_echos_max != 1:
Expand Down Expand Up @@ -277,13 +279,14 @@ async def eval_batch(
liasses: LiassesEvaluation,
):
"""
Evaluate a batch of liasses.
Args:
credentials (HTTPBasicCredentials): The credentials for authentication.
liasses (LiassesEvaluation): The liasses to be evaluated.
Returns:
dict: Response containing APE codes.
dict: A dictionary containing the evaluation results.
"""

query = preprocess_batch(liasses.dict(), nb_echos_max=2)
Expand Down
28 changes: 24 additions & 4 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from fastapi import Depends, HTTPException, Request, status
from fastapi.security import HTTPBasic, HTTPBasicCredentials

security = HTTPBasic()


def get_model(model_name: str, model_version: str) -> object:
"""
Expand Down Expand Up @@ -41,22 +39,44 @@ def get_model(model_name: str, model_version: str) -> object:


async def optional_security(request: Request):
"""
Determines whether to apply optional security measures based on the value of the AUTH_API environment variable.
Args:
request (Request): The incoming request object.
Returns:
Union[HTTPBasic, None]: An instance of the HTTPBasic class if AUTH_API is set to "True", otherwise None.
"""
if os.getenv("AUTH_API") == "True":
return await security(request)
return await HTTPBasic(request)
else:
return None


def get_current_username(
credentials: Optional[HTTPBasicCredentials] = Depends(optional_security),
):
"""
Retrieves the current username based on the provided credentials.
Args:
credentials (Optional[HTTPBasicCredentials]): The credentials used for authentication.
Returns:
str: The username extracted from the credentials.
Raises:
HTTPException: If authentication fails.
"""
if os.getenv("AUTH_API") == "True":
if not (credentials.username == os.getenv("API_USERNAME")) or not (
credentials.password == os.getenv("API_PASSWORD")
):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Authentification failed",
detail="Authentication failed",
headers={"WWW-Authenticate": "Basic"},
)
return credentials.username
Expand Down

0 comments on commit e5501e6

Please sign in to comment.