From 9af5be00330336c05ec13a6e908f3463e2d8d4a6 Mon Sep 17 00:00:00 2001 From: thepetk Date: Mon, 23 Sep 2024 13:44:13 +0100 Subject: [PATCH] Add bearer auth support to codegen Signed-off-by: thepetk --- .../natural_language_processing/codegen/app/codegen-app.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/recipes/natural_language_processing/codegen/app/codegen-app.py b/recipes/natural_language_processing/codegen/app/codegen-app.py index 13d3345a..f1c02d25 100644 --- a/recipes/natural_language_processing/codegen/app/codegen-app.py +++ b/recipes/natural_language_processing/codegen/app/codegen-app.py @@ -10,6 +10,10 @@ model_service = os.getenv("MODEL_ENDPOINT", "http://localhost:8001") model_service = f"{model_service}/v1" +model_service_bearer = os.getenv("MODEL_ENDPOINT_BEARER") +request_kwargs = {} +if model_service_bearer is not None: + request_kwargs = {"headers": {"Authorization": f"Bearer {model_service_bearer}"}} @st.cache_resource(show_spinner=False) def checking_model_service(): @@ -18,7 +22,7 @@ def checking_model_service(): ready = False while not ready: try: - request = requests.get(f'{model_service}/models') + request = requests.get(f'{model_service}/models', **request_kwargs) if request.status_code == 200: ready = True except: