Skip to content

Commit

Permalink
enable jupyter ai
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianhao-Gu committed Oct 22, 2024
1 parent 5ec475d commit 8fcd344
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
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']) / 'jupyter_jupyter_ai_config.json'
shutil.copy2(jupyter_notebook_config, jupyter_dir / 'jupyter_jupyter_ai_config.json')

Check warning on line 99 in src/jupyterhub_config/custom_docker_spawner.py

View check run for this annotation

Codecov / codecov/patch

src/jupyterhub_config/custom_docker_spawner.py#L98-L99

Added lines #L98 - L99 were not covered by tests

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 8fcd344

Please sign in to comment.