Skip to content

Commit

Permalink
Merge pull request #112 from kbase/dev_jupyterhub
Browse files Browse the repository at this point in the history
enable jupyter ai
  • Loading branch information
Tianhao-Gu authored Oct 23, 2024
2 parents 379e53f + 0d9cdcd commit 161bfbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ RUN chown -R spark_user:spark /.jupyter
# Set up JupyterHub directories
ENV JUPYTERHUB_CONFIG_DIR=/srv/jupyterhub
RUN mkdir -p ${JUPYTERHUB_CONFIG_DIR}
ENV JUPYTER_AI_CONFIG_FILE=jupyter_jupyter_ai_config.json
COPY ./config/${JUPYTER_AI_CONFIG_FILE} ${JUPYTERHUB_CONFIG_DIR}/${JUPYTER_AI_CONFIG_FILE}
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
Expand Down
8 changes: 8 additions & 0 deletions config/jupyter_jupyter_ai_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"AiExtension": {
"allowed_providers": [
"openai",
"openai-chat"
]
}
}
5 changes: 5 additions & 0 deletions src/jupyterhub_config/custom_docker_spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']) / os.environ['JUPYTER_AI_CONFIG_FILE']
shutil.copy2(jupyter_notebook_config, jupyter_dir / os.environ['JUPYTER_AI_CONFIG_FILE'])

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)
Expand Down

0 comments on commit 161bfbb

Please sign in to comment.