Skip to content

Commit f937234

Browse files
authored
feat(medcat-trainer): configurable remote model service timeout & prev suggestion from PR on context manager (#309)
Co-authored-by: Tom Searle <tom@cogstack.org>
1 parent 652b09e commit f937234

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

medcat-trainer/envs/env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ EMAIL_USER=example@cogstack.org
4646
EMAIL_PASS="to be changed"
4747
EMAIL_HOST=mail.cogstack.org
4848
EMAIL_PORT=465
49+
50+
# Remote model service timeout in seconds
51+
REMOTE_MODEL_SERVICE_TIMEOUT=60

medcat-trainer/envs/env-prod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ LOAD_NUM_DOC_PAGES=10
4444
EMAIL_USER=example@cogstack.org
4545
EMAIL_PASS="to be changed"
4646
EMAIL_HOST=mail.cogstack.org
47-
EMAIL_PORT=465
47+
EMAIL_PORT=465
48+
49+
# Remote model service timeout in seconds
50+
REMOTE_MODEL_SERVICE_TIMEOUT=60

medcat-trainer/webapp/api/api/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ def call_remote_model_service(service_url, text):
6464
"text": text
6565
}
6666

67+
# Get timeout from environment variable, default to 60 seconds
68+
timeout = int(os.getenv('REMOTE_MODEL_SERVICE_TIMEOUT', '60'))
69+
6770
try:
68-
response = requests.post(api_url, json=payload, timeout=60)
71+
response = requests.post(api_url, json=payload, timeout=timeout)
6972
response.raise_for_status()
7073
result = response.json()
7174

medcat-trainer/webapp/api/api/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from rest_framework.response import Response
2020
from medcat.components.ner.trf.deid import DeIdModel
2121
from medcat.utils.cdb_utils import ch2pt_from_pt2ch, get_all_ch, snomed_ct_concept_path
22+
from medcat.utils.config_utils import temp_changed_config
23+
2224

2325
from .admin import download_projects_with_text, download_projects_without_text, \
2426
import_concepts_from_cdb
@@ -678,10 +680,8 @@ def annotate_text(request):
678680
logger.warning(f'Failed to get children for CUI {parent_cui}: {e}')
679681
cuis_set = expanded_cuis
680682

681-
curr_cuis = cat.config.components.linking.filters
682-
cat.config.components.linking.filters.cuis = cuis_set
683-
spacy_doc = cat(message)
684-
cat.config.components.linking.filters = curr_cuis
683+
with temp_changed_config(cat.config.components.linking, 'filters', cuis_set):
684+
spacy_doc = cat(message)
685685

686686
ents = []
687687
anno_tkns = []

0 commit comments

Comments
 (0)