2019-03-11 13:36:42 +04:00
|
|
|
from fastapi import APIRouter, Depends
|
2020-01-19 22:40:50 +01:00
|
|
|
from pydantic.networks import EmailStr
|
2025-08-13 00:44:44 +08:00
|
|
|
import httpx
|
2025-08-13 00:48:54 +08:00
|
|
|
from pydantic import BaseModel
|
2025-08-13 09:52:39 +08:00
|
|
|
import re
|
2019-02-09 19:42:36 +04:00
|
|
|
|
2023-12-27 13:49:36 -05:00
|
|
|
from app.api.deps import get_current_active_superuser
|
|
|
|
|
from app.models import Message
|
2025-08-13 08:52:10 +08:00
|
|
|
from app.utils import generate_test_email, send_email, fast_json_response
|
2019-02-09 19:42:36 +04:00
|
|
|
|
2024-12-02 13:04:03 +01:00
|
|
|
router = APIRouter(prefix="/utils", tags=["utils"])
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
|
|
2023-12-27 13:49:36 -05:00
|
|
|
@router.post(
|
|
|
|
|
"/test-email/",
|
|
|
|
|
dependencies=[Depends(get_current_active_superuser)],
|
|
|
|
|
status_code=201,
|
|
|
|
|
)
|
|
|
|
|
def test_email(email_to: EmailStr) -> Message:
|
2019-02-09 19:42:36 +04:00
|
|
|
"""
|
:sparkles: Add Items (crud, models, endpoints), utils, refactor (#14)
* Update CRUD utils to use types better.
* Simplify Pydantic model names, from `UserInCreate` to `UserCreate`, etc.
* Upgrade packages.
* Add new generic "Items" models, crud utils, endpoints, and tests. To facilitate re-using them to create new functionality. As they are simple and generic (not like Users), it's easier to copy-paste and adapt them to each use case.
* Update endpoints/*path operations* to simplify code and use new utilities, prefix and tags in `include_router`.
* Update testing utils.
* Update linting rules, relax vulture to reduce false positives.
* Update migrations to include new Items.
* Update project README.md with tips about how to start with backend.
2019-04-19 09:45:23 +04:00
|
|
|
Test emails.
|
2019-02-09 19:42:36 +04:00
|
|
|
"""
|
2024-03-10 00:02:36 +01:00
|
|
|
email_data = generate_test_email(email_to=email_to)
|
|
|
|
|
send_email(
|
|
|
|
|
email_to=email_to,
|
|
|
|
|
subject=email_data.subject,
|
|
|
|
|
html_content=email_data.html_content,
|
|
|
|
|
)
|
2023-12-27 13:49:36 -05:00
|
|
|
return Message(message="Test email sent")
|
2024-09-12 15:21:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/health-check/")
|
|
|
|
|
async def health_check() -> bool:
|
|
|
|
|
return True
|
2025-08-13 00:38:27 +08:00
|
|
|
|
|
|
|
|
class ClassifyRequest(BaseModel):
|
|
|
|
|
text: str
|
|
|
|
|
|
|
|
|
|
@router.post("/bentoml_classifiy")
|
|
|
|
|
async def bentoml_classifiy(data: ClassifyRequest):
|
2025-08-13 09:52:39 +08:00
|
|
|
text = data.text
|
|
|
|
|
cleaned_text = text.strip().replace("\n", "")
|
|
|
|
|
cleaned_text = re.sub(r'[\x00-\x1F]', '', cleaned_text)
|
|
|
|
|
|
|
|
|
|
|
2025-08-13 00:38:27 +08:00
|
|
|
async with httpx.AsyncClient() as client:
|
|
|
|
|
response = await client.post(
|
2025-08-13 01:08:08 +08:00
|
|
|
"http://120.76.41.122:3000/classify",
|
2025-08-13 09:52:39 +08:00
|
|
|
json={"text": f"{cleaned_text}"}
|
2025-08-13 00:38:27 +08:00
|
|
|
)
|
|
|
|
|
result = response.json()
|
2025-08-13 08:52:10 +08:00
|
|
|
return fast_json_response(data=result)
|