Skip to content

Commit

Permalink
mock response for predict keyword endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vietnguyengit committed Oct 25, 2024
1 parent a0b996f commit a24873a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ You might want to update the `poetry.lock` file after manually modifying `pyproj
3. Run the FastAPI server:

```shell
poetry run uvicorn data_discovery_ai.server:app --reload
poetry run uvicorn data_discovery_ai.server:app --reload --log-config=log_config.yaml
```

4. Run the tests:
Expand Down
12 changes: 9 additions & 3 deletions data_discovery_ai/routes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Dict

from fastapi import APIRouter, Depends
from pydantic import BaseModel
import logging
Expand All @@ -21,10 +23,14 @@ async def hello():


@router.post("/predict-keyword", dependencies=[Depends(api_key_auth)])
async def predict_keyword(payload: PredictKeywordRequest) -> str:
async def predict_keyword(payload: PredictKeywordRequest) -> dict[str, str]:
# TODO: just placeholder for now, the client where calling this endpoint should only know 2 things: selected
# model name, and the raw input
selected_model = validate_model_name(payload.selected_model)
raw_input = payload.raw_input
logger.debug(f"selected_model: {selected_model}, raw_input: {raw_input}")
return keywordClassifier(None, None, None, None, None)
logger.info(f"selected_model: {selected_model}, raw_input: {raw_input}")
# predicted_keyword = keywordClassifier(None, None, None, None, None)
response = {
"predicted_keyword": "sample_predicted_keyword"
}
return response
2 changes: 1 addition & 1 deletion data_discovery_ai/utils/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def api_key_auth(x_api_key: str = Security(api_key_header)):

def validate_model_name(selected_model: str):
if selected_model.lower() in AVAILABLE_MODELS:
return True
return selected_model.lower()
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid selected model name"
)
3 changes: 3 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

poetry run uvicorn --host 0.0.0.0 data_discovery_ai.server:app --log-config=log_config.yaml
34 changes: 34 additions & 0 deletions log_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: 1
disable_existing_loggers: False
formatters:
default:
# "()": uvicorn.logging.DefaultFormatter
format: "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
access:
# "()": uvicorn.logging.AccessFormatter
format: "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
handlers:
default:
formatter: default
class: logging.StreamHandler
stream: ext://sys.stderr
access:
formatter: access
class: logging.StreamHandler
stream: ext://sys.stdout
loggers:
uvicorn.error:
level: INFO
handlers:
- default
propagate: no
uvicorn.access:
level: INFO
handlers:
- access
propagate: no
root:
level: DEBUG
handlers:
- default
propagate: no
2 changes: 1 addition & 1 deletion poetry.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 @@ -24,6 +24,7 @@ starlette = "0.40.0"
torch = "2.5.0"
imblearn = "^0.0"
iterative-stratification = "^0.1.9"
pyyaml = "^6.0.2"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.2"
Expand Down

0 comments on commit a24873a

Please sign in to comment.