From 8fcd3449164fc5e372f11e3579e390dc96117d35 Mon Sep 17 00:00:00 2001 From: Tianhao-Gu Date: Tue, 22 Oct 2024 15:35:11 -0500 Subject: [PATCH] enable jupyter ai --- Dockerfile | 1 + config/jupyter_jupyter_ai_config.json | 8 ++++++++ src/jupyterhub_config/custom_docker_spawner.py | 5 +++++ 3 files changed, 14 insertions(+) create mode 100644 config/jupyter_jupyter_ai_config.json diff --git a/Dockerfile b/Dockerfile index cba6138..eaea9df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -64,6 +64,7 @@ RUN chown -R spark_user:spark /.jupyter # Set up JupyterHub directories ENV JUPYTERHUB_CONFIG_DIR=/srv/jupyterhub RUN mkdir -p ${JUPYTERHUB_CONFIG_DIR} +COPY ./config/jupyter_jupyter_ai_config.json ${JUPYTERHUB_CONFIG_DIR}/jupyter_jupyter_ai_config.json COPY ./src/notebook_utils/startup.py ${JUPYTERHUB_CONFIG_DIR}/startup.py COPY ./config/jupyterhub_config.py ${JUPYTERHUB_CONFIG_DIR}/jupyterhub_config.py COPY ./scripts/spawn_notebook.sh ${JUPYTERHUB_CONFIG_DIR}/spawn_notebook.sh diff --git a/config/jupyter_jupyter_ai_config.json b/config/jupyter_jupyter_ai_config.json new file mode 100644 index 0000000..d9ab722 --- /dev/null +++ b/config/jupyter_jupyter_ai_config.json @@ -0,0 +1,8 @@ +{ + "AiExtension": { + "allowed_providers": [ + "openai", + "openai-chat" + ] + } +} \ No newline at end of file diff --git a/src/jupyterhub_config/custom_docker_spawner.py b/src/jupyterhub_config/custom_docker_spawner.py index 33dc946..d8adbbd 100644 --- a/src/jupyterhub_config/custom_docker_spawner.py +++ b/src/jupyterhub_config/custom_docker_spawner.py @@ -93,6 +93,11 @@ def _ensure_user_jupyter_directory(self, user_dir: Path): jupyter_runtime_dir.mkdir(parents=True, exist_ok=True) juputer_data_dir.mkdir(parents=True, exist_ok=True) + # copy the jupyter_jupyter_ai_config.json file to the user's .jupyter directory + # ref: https://jupyter-ai.readthedocs.io/en/latest/users/index.html#configuring-as-a-config-file + jupyter_notebook_config = Path(os.environ['JUPYTERHUB_CONFIG_DIR']) / 'jupyter_jupyter_ai_config.json' + shutil.copy2(jupyter_notebook_config, jupyter_dir / 'jupyter_jupyter_ai_config.json') + self.environment['JUPYTER_CONFIG_DIR'] = str(jupyter_dir) self.environment['JUPYTER_RUNTIME_DIR'] = str(jupyter_runtime_dir) self.environment['JUPYTER_DATA_DIR'] = str(juputer_data_dir)