From ae6cdb896ab0835021be2882b5edf04dc3037b90 Mon Sep 17 00:00:00 2001 From: Dmitry Afanasyev <71835315+Balshgit@users.noreply.github.com> Date: Fri, 29 Sep 2023 20:56:12 +0300 Subject: [PATCH] fix bot healthcheck endpoint (#22) --- bot_microservice/api/bot/controllers.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bot_microservice/api/bot/controllers.py b/bot_microservice/api/bot/controllers.py index 8b090ee..3e4c8d1 100644 --- a/bot_microservice/api/bot/controllers.py +++ b/bot_microservice/api/bot/controllers.py @@ -32,11 +32,12 @@ async def process_bot_updates(request: Request) -> None: }, ) async def gpt_healthcheck(response: Response) -> Response: - chat_gpt_service = ChatGptService(chat_gpt_model=settings.GPT_MODEL) - data = chat_gpt_service.build_request_data('Привет!') + chatgpt_service = ChatGptService(chat_gpt_model=settings.GPT_MODEL) + data = chatgpt_service.build_request_data("Привет!") + response.status_code = status.HTTP_200_OK 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: + chatgpt_response = await chatgpt_service.do_request(data) + if chatgpt_response.status_code != status.HTTP_200_OK or chatgpt_response.text == INVALID_GPT_MODEL_MESSAGE: response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR except Exception: response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR