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

48 lines
1.2 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
from app.api.deps import get_current_active_superuser
from app.models import Message
from app.utils import generate_test_email, send_email
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):
async with httpx.AsyncClient() as client:
response = await client.post(
"http://120.76.41.122:3000/classify",
2025-08-13 01:00:29 +08:00
json={"text": f"{data.text}"}
)
result = response.json()
return result