From ccf9bc4fc7564a11a903a15fc16e50efa735bab4 Mon Sep 17 00:00:00 2001 From: Ranjan Shrestha Date: Tue, 12 Dec 2023 11:32:46 +0545 Subject: [PATCH] endpoint added to retrieve the models info; --- analysis_module/mock_templates.py | 15 +++++++++++ analysis_module/views/models_info.py | 39 ++++++++++++++++++++++++++++ core_server/env.py | 8 ++++++ core_server/settings.py | 7 +++++ core_server/urls.py | 2 ++ docker-compose-prod.yml | 7 +++++ docker-compose.yml | 8 ++++++ 7 files changed, 86 insertions(+) create mode 100644 analysis_module/views/models_info.py diff --git a/analysis_module/mock_templates.py b/analysis_module/mock_templates.py index f1f41dd..f95139b 100644 --- a/analysis_module/mock_templates.py +++ b/analysis_module/mock_templates.py @@ -1,5 +1,20 @@ from typing import List, Dict +MODELS_INFO_MOCK: Dict = { + "classification_model": { + "id": "classification_model_mock", + "version": "1.0.0" + }, + "geolocation_model": { + "id": "geolocation_model_mock", + "version": "1.0.0" + }, + "reliability_model": { + "id": "reliability_model_mock", + "version": "1.0.0" + } +} + MOCK_GEOLOCATION: List = [ { "ent": "Cauca", diff --git a/analysis_module/views/models_info.py b/analysis_module/views/models_info.py new file mode 100644 index 0000000..abf8d0c --- /dev/null +++ b/analysis_module/views/models_info.py @@ -0,0 +1,39 @@ +from rest_framework.decorators import api_view, permission_classes +from rest_framework.request import Request +from rest_framework.response import Response +from rest_framework.permissions import IsAuthenticated + +from analysis_module.mock_templates import MODELS_INFO_MOCK +from core_server.settings import IS_MOCKSERVER + +from core_server.settings import ( + CLASSIFICATION_MODEL_ID, + CLASSIFICATION_MODEL_VERSION, + GEOLOCATION_MODEL_ID, + GEOLOCATION_MODEL_VERSION, + RELIABILITY_MODEL_ID, + RELIABILITY_MODEL_VERSION +) + + +@api_view(["GET"]) +@permission_classes([IsAuthenticated]) +def models_detail(request: Request): + """ Get the models information """ + if IS_MOCKSERVER: + return Response(MODELS_INFO_MOCK) + + return Response({ + "classification_model": { + "id": CLASSIFICATION_MODEL_ID, + "version": CLASSIFICATION_MODEL_VERSION + }, + "geolocation_model": { + "id": GEOLOCATION_MODEL_ID, + "version": GEOLOCATION_MODEL_VERSION + }, + "reliablity_model": { + "id": RELIABILITY_MODEL_ID, + "version": RELIABILITY_MODEL_VERSION + } + }) diff --git a/core_server/env.py b/core_server/env.py index e740d25..07b8c91 100644 --- a/core_server/env.py +++ b/core_server/env.py @@ -53,4 +53,12 @@ CLASSIFICATION_MODEL_ENDPOINT=(str, "main-model-cpu"), SUMMARIZATION_V2_ECS_ENDPOINT=(str, None), TEXTEXTRACTION_ECS_ENDPOINT=(str, None), + + # MODEL INFO + CLASSIFICATION_MODEL_ID=str, + CLASSIFICATION_MODEL_VERSION=str, + GEOLOCATION_MODEL_ID=str, + GEOLOCATION_MODEL_VERSION=str, + RELIABILITY_MODEL_ID=str, + RELIABILITY_MODEL_VERSION=str, ) diff --git a/core_server/settings.py b/core_server/settings.py index fa1ff1a..ffb2c04 100644 --- a/core_server/settings.py +++ b/core_server/settings.py @@ -63,6 +63,13 @@ ECS_REQUESTS_BATCH_SIZE = env("ECS_REQUESTS_BATCH_SIZE") MAX_NLP_PROCESSING_ATTEMPTS = env("MAX_NLP_PROCESSING_ATTEMPTS") +CLASSIFICATION_MODEL_ID = env("CLASSIFICATION_MODEL_ID") +CLASSIFICATION_MODEL_VERSION = env("CLASSIFICATION_MODEL_VERSION") +GEOLOCATION_MODEL_ID = env("GEOLOCATION_MODEL_ID") +GEOLOCATION_MODEL_VERSION = env("GEOLOCATION_MODEL_VERSION") +RELIABILITY_MODEL_ID = env("RELIABILITY_MODEL_ID") +RELIABILITY_MODEL_VERSION = env("RELIABILITY_MODEL_VERSION") + # Application definition INSTALLED_APPS = [ diff --git a/core_server/urls.py b/core_server/urls.py index 5501847..e958574 100644 --- a/core_server/urls.py +++ b/core_server/urls.py @@ -34,6 +34,7 @@ entry_extraction ) from analysis_module.views.text_extraction import text_extraction +from analysis_module.views.models_info import models_detail from core.views import token_auth_dummy_view urlpatterns = [ @@ -48,5 +49,6 @@ path("api/v1/nlp-tags/", nlp_tags), path("api/v1/entry-classification/", entry_classification), path("api/v1/analysismodule/status//", request_status), + path("api/v1/models-info/", models_detail), path("api/v1/test-auth/", token_auth_dummy_view), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index dfce978..b1e7b35 100644 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -47,6 +47,13 @@ x-server: &base-server-config TEXTEXTRACTION_ECS_ENDPOINT: ${TEXTEXTRACTION_ECS_ENDPOINT:?Provide text extraction endpoint} ENTRYEXTRACTION_ECS_ENDPOINT: ${ENTRYEXTRACTION_ECS_ENDPOINT:?Provide entry extraction endpoint} + # MODEL_INFO + CLASSIFICATION_MODEL_ID: ${CLASSIFICATION_MODEL_ID:-classification-model} + CLASSIFICATION_MODEL_VERSION: ${CLASSIFICATION_MODEL_VERSION:-1.0.0} + GEOLOCATION_MODEL_ID: ${GEOLOCATION_MODEL_ID:-geolocation-model} + GEOLOCATION_MODEL_VERSION: ${GEOLOCATION_MODEL_VERSION:-1.0.0} + RELIABILITY_MODEL_ID: ${RELIABILITY_MODEL_ID:-reliability-model} + RELIABILITY_MODEL_VERSION: ${RELIABILITY_MODEL_VERSION:-1.0.0} tty: true depends_on: diff --git a/docker-compose.yml b/docker-compose.yml index 330fdc0..25a7d66 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -60,6 +60,14 @@ x-server: &base-server-config SENTRY_DSN: ${SENTRY_DSN:-} SENTRY_TRACES_SAMPLE_RATE: ${SENTRY_TRACES_SAMPLE_RATE:-0.2} + # MODEL_INFO + CLASSIFICATION_MODEL_ID: ${CLASSIFICATION_MODEL_ID:-classification-model} + CLASSIFICATION_MODEL_VERSION: ${CLASSIFICATION_MODEL_VERSION:-1.0.0} + GEOLOCATION_MODEL_ID: ${GEOLOCATION_MODEL_ID:-geolocation-model} + GEOLOCATION_MODEL_VERSION: ${GEOLOCATION_MODEL_VERSION:-1.0.0} + RELIABILITY_MODEL_ID: ${RELIABILITY_MODEL_ID:-reliability-model} + RELIABILITY_MODEL_VERSION: ${RELIABILITY_MODEL_VERSION:-1.0.0} + volumes: - ./:/code/ tty: true