diff --git a/packages/jupyter-ai/jupyter_ai/extension.py b/packages/jupyter-ai/jupyter_ai/extension.py index f9d0fee56..dbea84009 100644 --- a/packages/jupyter-ai/jupyter_ai/extension.py +++ b/packages/jupyter-ai/jupyter_ai/extension.py @@ -1,3 +1,4 @@ +import os import time from dask.distributed import Client as DaskClient @@ -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, @@ -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)