Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace c.ServerApp.root_dir by environment variable #327

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/jupyter-ai/jupyter_ai/extension.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import time

from dask.distributed import Client as DaskClient
Expand Down Expand Up @@ -71,6 +72,13 @@ def initialize_settings(self):
# consumers a Future that resolves to the Dask client when awaited.
dask_client_future = loop.create_task(self._get_dask_client())

# get root directory for read and writing
save_dir = os.environ.get("JUPYTERAI_SAVEDIR")
if not save_dir:
save_dir = self.serverapp.root_dir
if not os.access(save_dir, os.W_OK):
save_dir = os.getcwd()

# initialize chat handlers
chat_handler_kwargs = {
"log": self.log,
Expand All @@ -85,11 +93,11 @@ def initialize_settings(self):
)
generate_chat_handler = GenerateChatHandler(
**chat_handler_kwargs,
root_dir=self.serverapp.root_dir,
root_dir=save_dir,
)
learn_chat_handler = LearnChatHandler(
**chat_handler_kwargs,
root_dir=self.serverapp.root_dir,
root_dir=save_dir,
dask_client_future=dask_client_future,
)
help_chat_handler = HelpChatHandler(**chat_handler_kwargs)
Expand Down