Files
full-stack-fastapi-template/backend/app/api/routes/utils.py

53 lines
1.4 KiB
Python
Raw Normal View History

from fastapi import APIRouter, Depends
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
from app.api.deps import get_current_active_superuser
from app.models import Message
from app.utils import generate_test_email, send_email, fast_json_response
router = APIRouter(prefix="/utils", tags=["utils"])
@router.post(
"/test-email/",
dependencies=[Depends(get_current_active_superuser)],
status_code=201,
)
def test_email(email_to: EmailStr) -> Message:
"""
Test emails.
"""
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,
)
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
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)
async with httpx.AsyncClient() as client:
response = await client.post(
"http://120.76.41.122:3000/classify",
2025-08-13 09:52:39 +08:00
json={"text": f"{cleaned_text}"}
)
result = response.json()
return fast_json_response(data=result)