From 914b4e6696b1dc8a6ed3c6898712e2da110ec9dc Mon Sep 17 00:00:00 2001 From: Bo Xu Date: Thu, 23 Feb 2023 07:50:03 -0800 Subject: [PATCH 1/3] Fix broken rich search module --- server/__init__.py | 7 ++++++- server/configmodule.py | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/__init__.py b/server/__init__.py index b3c4941266..0cfb137f8b 100644 --- a/server/__init__.py +++ b/server/__init__.py @@ -38,6 +38,7 @@ import server.lib.util as libutil from server.services.discovery import configure_endpoints_from_ingress from server.services.discovery import get_health_check_urls +import server.services.ai as ai propagator = google_cloud_format.GoogleCloudFormatPropagator() @@ -288,7 +289,11 @@ def create_app(): app.config['BABEL_DEFAULT_LOCALE'] = i18n.DEFAULT_LOCALE app.config['BABEL_TRANSLATION_DIRECTORIES'] = 'i18n' - # Initialize the AI module. + # Enable the AI module. + if cfg.ENABLE_AI: + app.config['AI_CONTEXT'] = ai.Context() + + # # Enable the NL model. if os.environ.get('ENABLE_MODEL') == 'true': libutil.check_backend_ready([app.config['NL_ROOT'] + '/healthz']) # Some specific imports for the NL Interface. diff --git a/server/configmodule.py b/server/configmodule.py index cb8c02f502..971bbc27ff 100644 --- a/server/configmodule.py +++ b/server/configmodule.py @@ -16,6 +16,7 @@ class Config: os.environ.get('MIXER_HASH')) API_ROOT = 'http://127.0.0.1:8081' # Port for Kubernetes ESP. NL_ROOT = 'http://127.0.0.1:6060' # Port for Kubernetes ESP. + ENABLE_AI = False AI_CONFIG_PATH = '/datacommons/ai/ai.yaml' SECRET_PROJECT = os.environ.get('SECRET_PROJECT') or '' MAPS_API_KEY = os.environ.get('MAPS_API_KEY') or '' @@ -59,6 +60,7 @@ class StagingConfig(Config): class AutopushConfig(Config): GA_ACCOUNT = 'G-Y6ZXZ9JK3H' GCS_BUCKET = 'datcom-website-autopush-resources' + ENABLE_AI = True LOG_QUERY = True @@ -126,7 +128,7 @@ class LocalBaseConfig(Config): API_ROOT = 'https://autopush.api.datacommons.org' API_PROJECT = 'datcom-mixer-autopush' AI_CONFIG_PATH = os.path.abspath( - os.path.join(os.path.curdir, '..', 'deploy/overlays/local/ai.yaml')) + os.path.join(os.path.curdir, 'deploy/overlays/local/ai.yaml')) SCHEME = 'http' GCS_BUCKET = 'datcom-website-autopush-resources' LOG_QUERY = True From c2ce2fcb5b65f59b3a58743ea50c1fe0328430e0 Mon Sep 17 00:00:00 2001 From: Bo Xu Date: Thu, 23 Feb 2023 08:35:41 -0800 Subject: [PATCH 2/3] fix lint --- server/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/__init__.py b/server/__init__.py index 0cfb137f8b..c21b1b0791 100644 --- a/server/__init__.py +++ b/server/__init__.py @@ -36,9 +36,9 @@ from server.lib.disaster_dashboard import get_disaster_dashboard_data import server.lib.i18n as i18n import server.lib.util as libutil +import server.services.ai as ai from server.services.discovery import configure_endpoints_from_ingress from server.services.discovery import get_health_check_urls -import server.services.ai as ai propagator = google_cloud_format.GoogleCloudFormatPropagator() From 262db392f56a3fcd3b7c31767de5b68602c929f7 Mon Sep 17 00:00:00 2001 From: Bo Xu Date: Thu, 23 Feb 2023 13:22:30 -0800 Subject: [PATCH 3/3] merge --- server/app_env/_base.py | 1 + server/app_env/autopush.py | 1 + server/app_env/local.py | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/server/app_env/_base.py b/server/app_env/_base.py index 7280f45442..3fb0a76f0c 100644 --- a/server/app_env/_base.py +++ b/server/app_env/_base.py @@ -30,6 +30,7 @@ class Config: os.environ.get('MIXER_HASH')) API_ROOT = 'http://127.0.0.1:8081' # Port for Kubernetes ESP. NL_ROOT = 'http://127.0.0.1:6060' # Port for Kubernetes ESP. + ENABLE_AI = False AI_CONFIG_PATH = '/datacommons/ai/ai.yaml' SECRET_PROJECT = os.environ.get('SECRET_PROJECT') or '' MAPS_API_KEY = os.environ.get('MAPS_API_KEY') or '' diff --git a/server/app_env/autopush.py b/server/app_env/autopush.py index 86010f87a3..d4d65c0bb2 100644 --- a/server/app_env/autopush.py +++ b/server/app_env/autopush.py @@ -18,4 +18,5 @@ class Config(_base.Config): GA_ACCOUNT = 'G-Y6ZXZ9JK3H' GCS_BUCKET = 'datcom-website-autopush-resources' + ENABLE_AI = True LOG_QUERY = True \ No newline at end of file diff --git a/server/app_env/local.py b/server/app_env/local.py index 7f61fe05ca..9e43b9c711 100644 --- a/server/app_env/local.py +++ b/server/app_env/local.py @@ -22,7 +22,7 @@ class Config(_base.Config): API_ROOT = 'https://autopush.api.datacommons.org' API_PROJECT = 'datcom-mixer-autopush' AI_CONFIG_PATH = os.path.abspath( - os.path.join(os.path.curdir, '..', 'deploy/overlays/local/ai.yaml')) + os.path.join(os.path.curdir, 'deploy/overlays/local/ai.yaml')) SCHEME = 'http' GCS_BUCKET = 'datcom-website-autopush-resources' LOG_QUERY = True