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

Provide non-UI way to specify API keys and other essential config fields for Jupyter AI chat #505

Open
andrii-i opened this issue Dec 5, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@andrii-i
Copy link
Collaborator

andrii-i commented Dec 5, 2023

Problem

Currently only way for the user to specify an API key for Jupyter AI chat is to use chat settings UI or edit config.json directly (and we don't want users to edit config.json directly). Specifying API key through env variables would only work for AI magics.

Relevant discussion: #503.

Proposed Solution

Provide non-UI way to specify API keys and other essential config fields for Jupyter AI chat. For example, making chat pick up API env variable would be a good start.

@andrii-i andrii-i added the enhancement New feature or request label Dec 5, 2023
@andrii-i andrii-i changed the title Provide non-UI way to specify API keys and other essential config fields for Jupyter AI chat. Provide non-UI way to specify API keys and other essential config fields for Jupyter AI chat Dec 5, 2023
@atnjqt
Copy link

atnjqt commented Mar 8, 2024

@andrii-i if you want your vendor specific API key available to all single user notebook instances, you can set this as an environment variable in /opt/jupyterhub/etc/jupyterhub/jupyterhub_config.py

Below is an example using c.Spawner environment vars, notably I am using openai. This is referenced here for jupyter-ai env vars.
)

c.Spawner.environment = {
        'PROVIDER_API_KEY':'YOUR_API_KEY_HERE',
        'OPENAI_API_KEY': 'sk-.............'
}

Don't forget to make sure the file is secured with chmod 600 && chown root:root given the secret api keys are in plain text.

OH wait I thought that would work for the UI lab extension but it does not!

@eazuman
Copy link

eazuman commented Mar 10, 2024

Hello,

Can you please verify if it's correct that setting the provider API_KEY (OPENAI_API_KEY) as an environment variable for Jupyter AI chat is not supported?

This pertains to #685.

Specifically, my goal is to configure provider details through the jupyter_jupyter_ai_config.json without including the API key in the configuration file but setting the API KEY as an environment variable.

Our enterprise prefers managing sensitive information through a secret manager, either within 'jupyter_jupyter_ai_config.json' or as an environment variable. what would be the recommended approach to achieve this?

Thank you!

@wakkadojo
Copy link

i have a similar question -- the environment variable seems to apply to the magic command and not the chat? is there a way to have the chat sidebar rely on environment variables to set API keys?

@ctcjab
Copy link
Contributor

ctcjab commented Aug 26, 2024

I just left a relevant comment in a related issue (context: this should also work with a config file outside the home directory for interoperability with JupyterHub on Kubernetes). Excerpting here for visibility:

I am using /opt/conda/share/jupyter/lab/settings/overrides.json to accomplish this with all the other extensions whose settings I need to provide custom defaults for for my users[1], and it works great – users get all these extensions configured out-of-the-box, but if they need to customize their settings further, they can do so (including through the JupyterLab settings UI), and their customizations get persisted in their PV-backed home directory on Kubernetes, which takes precedence over my overrides.json. If jupyter-ai could look in overrides.json like these other extensions, that would make things simpler and more consistent for users and for administrators like me. What do you think?

[1] Here are all the other extensions that this approach works with, in case it's helpful:

❯ grep '@' overrides.json
  "@jupyterlab-contrib/spellchecker:plugin": {
  "@jupyterlab/apputils-extension:notification": {
  "@jupyterlab/completer-extension:inline-completer": {
      "@jupyterlab/inline-completer:history": {
      "@jupyterlab/jupyter-ai": {
  "@jupyterlab/completer-extension:manager": {
  "@jupyterlab/console-extension:tracker": {
  "@jupyterlab/extensionmanager-extension:plugin": {
  "@jupyterlab/filebrowser-extension:browser": {
  "@jupyterlab/fileeditor-extension:plugin": {
  "@jupyterlab/notebook-extension:tracker": {
  "@jupyterlab/shortcuts-extension:shortcuts": {
  "@jupyterlab/terminal-extension:plugin": {

@mthiboust
Copy link

I am having the same issue. I would be great if the chat UI could be configured using the API keys from env variables (like the AI magics command)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants