My task seems simple: I am using jupyter-ai in a jupyter lab / mybinder.org environment and my goal is to configure it in a way that there is an LLM already pre-selected and -configured when the jupyter environment starts.
After a lot of trial and error I have now managed to do this successfully on my local linux system. However, I am not sure if I achieved this by creating an overrides.json which lives in the .local/jupyter folder, or by simply starting jupyter lab once with jupyter lab --AiExtension.default_language_model=openai-chat:gpt-4. There is now a config.json in a jupyter-ai subfolder, which includes the setting for the default LLM and which jupyter lab automatically seems to use when it starts (I assume either the command created it or the overrides.json). So the default LLM in jupyter ai is now set to openai locally every time I start jupyter lab (just with ‘jupyter lab’), which is - technically - exactly what I want.
However, I also want this to work when I start a binder via mybinder.org from my github-repository and I still absolutely fail to do that. I have tried postBuilds, start files, config.jsons and overrides.jsons, I had mybinder move those files to various locations at start-up - none of it worked. Through the binder logs, I know that the postBuild file executes alright and the folders I need are created resp. the config or overrides file moved or copied to the right places as well, but it’s still not working. Either mybinder is building the container successfully but then never starting the server, or it starts eventually but then jupyter-ai isn’t even there. My latest approach now has is me using a start file with the following content:
#!/bin/bash
# Start JupyterLab with a custom configuration
exec jupyter lab --AiExtension.default_language_model=openai-chat:gpt-4
and a postBuild looking like this:
#!/bin/bash
# Make the start script executable
chmod +x binder/start
which at least isn’t messing everything up - the server starts and jupyter-ai shows up and is available. BUT: It still has done nothing to pre-select an LLM.
I am sure it’s probably actually really simple once you know which command or conig-file needs to go exactly where, but I feel like I’ve tried every possibility and it’s just not working. Can anyone help??
In 2022 it was jupyter_config.json in the root of the repo, see here. (I wonder if you could also put it in the binder directory if you have one? I haven’t tested that or any of this recently.)
Thank you, I tried this but it didn’t do anything, unfortunately. But might also be that my config-file isn’t entirely correct, it currently looks like this:
Thank you, I’ve tried the overrides.json apprach again as well but it didn’t work either. I can tell that it something, though, as it made the jupyter-ai widget disappear completely instead of setting a default LLM, so maybe this is one step into the right direction…
#!/usr/bin/env bash
set -eux
# Create the directory
mkdir -p ${NB_PYTHON_PREFIX}/share/jupyter/lab/settings
if [[ $? -eq 0 ]]; then
echo "Successfully created the directory ${NB_PYTHON_PREFIX}/share/jupyter/lab/settings"
else
echo "Failed to create the directory ${NB_PYTHON_PREFIX}/share/jupyter/lab/settings" >&2
exit 1
fi
# Copy the overrides.json file
cp overrides.json ${NB_PYTHON_PREFIX}/share/jupyter/lab/settings
if [[ $? -eq 0 ]]; then
echo "Successfully copied overrides.json to ${NB_PYTHON_PREFIX}/share/jupyter/lab/settings"
else
echo "Failed to copy overrides.json to ${NB_PYTHON_PREFIX}/share/jupyter/lab/settings" >&2
exit 1
fi
I had them both in a binder-folder and added the echo messages to see if the postBuild was correctly addressed and able to do it’s job and this part seems to work alright (the log messages say that the folder was created successfully and the file copied as well). However, after copying the overrides.json into the settings folder the jupyter-ai extension disappeared completely from my mybinder-image.
I also tried copying the file to this folder: mkdir -p ${HOME}/.jupyter/lab/user-settings/@jupyter-ai/ai-extension, which I found as an alternative, but the result was exactly the same: instead of setting a default LLM, jupyter-ai disappeared entirely.
Any idea what I am doing wrong here?
I still have to try and reproduce the mybinder-build with repo2docker as suggested, but not sure how quickly I’ll be able to do that. I haven’t quite wrapped my head around repo2docker yet, but I will try this as well.
If anyone has any other ideas, I’d be more than happy to try them, I just can’t imagine that this is something that can’t be solved.
So I had a look at what happens with my local installation and it seems that starting jupyter lab once with the long option --AiExtension.default_language_model=openai-chat:gpt-4 seems to create a config.json in my home-folder under .local/share/jupyter/jupyter_ai, which looks like this:
So I tried to my mimic this and while I haven’t succeeded so far in simply including the long option somehwere in my binder-build, I have created the config.json and used the postBuild file to create a folder .local/share/jupyter/jupyter_ai and copy the config.json into it. Using the terminal in my mybiner build, I can see that this works, the folder is created and the config.json in place, but: Once again jupyter-ai has completely dissapeared from the build, there’s no widget at all.
I also tried using a start-file instead but this keeps the server from starting entirely.
Using a Dockerfile let’s the server start properly but then jupyter-ai disappears again entirely. This is slowly driving me insane…