Skip to content

Commit

Permalink
endpoint added to retrieve the models info;
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjan-stha committed Dec 12, 2023
1 parent 379ed47 commit ccf9bc4
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
15 changes: 15 additions & 0 deletions analysis_module/mock_templates.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
39 changes: 39 additions & 0 deletions analysis_module/views/models_info.py
Original file line number Diff line number Diff line change
@@ -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
}
})
8 changes: 8 additions & 0 deletions core_server/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
7 changes: 7 additions & 0 deletions core_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 2 additions & 0 deletions core_server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -48,5 +49,6 @@
path("api/v1/nlp-tags/", nlp_tags),
path("api/v1/entry-classification/", entry_classification),
path("api/v1/analysismodule/status/<uuid:unique_id>/", 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)
7 changes: 7 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ccf9bc4

Please sign in to comment.