mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-12-16 21:20:39 +03:00
add gpt model health check (#21)
This commit is contained in:
@@ -2,6 +2,8 @@ from fastapi import APIRouter, Request
|
||||
from starlette import status
|
||||
from starlette.responses import Response
|
||||
|
||||
from constants import INVALID_GPT_MODEL_MESSAGE
|
||||
from core.utils import ChatGptService
|
||||
from settings.config import settings
|
||||
|
||||
router = APIRouter()
|
||||
@@ -9,7 +11,7 @@ router = APIRouter()
|
||||
|
||||
@router.post(
|
||||
f"/{settings.TELEGRAM_API_TOKEN}",
|
||||
name="system:process_bot_updates",
|
||||
name="bot:process_bot_updates",
|
||||
response_class=Response,
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
summary="process bot updates",
|
||||
@@ -17,3 +19,26 @@ router = APIRouter()
|
||||
)
|
||||
async def process_bot_updates(request: Request) -> None:
|
||||
await request.app.state.queue.put_updates_on_queue(request)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/bot-healthcheck",
|
||||
name="bot:gpt_healthcheck",
|
||||
response_class=Response,
|
||||
summary="bot healthcheck",
|
||||
responses={
|
||||
status.HTTP_500_INTERNAL_SERVER_ERROR: {"description": "Request to chat gpt not success"},
|
||||
status.HTTP_200_OK: {"description": "Successful Response"},
|
||||
},
|
||||
)
|
||||
async def gpt_healthcheck(response: Response) -> Response:
|
||||
chat_gpt_service = ChatGptService(chat_gpt_model=settings.GPT_MODEL)
|
||||
data = chat_gpt_service.build_request_data('Привет!')
|
||||
try:
|
||||
gpt_response = await chat_gpt_service.do_request(data)
|
||||
if gpt_response.text == INVALID_GPT_MODEL_MESSAGE or response.status_code != status.HTTP_200_OK:
|
||||
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
except Exception:
|
||||
response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
|
||||
return Response(status_code=response.status_code, content=None)
|
||||
|
||||
Reference in New Issue
Block a user