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

Chat window works, but IPython magics do not #1103

Open
sg-s opened this issue Nov 12, 2024 · 3 comments
Open

Chat window works, but IPython magics do not #1103

sg-s opened this issue Nov 12, 2024 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@sg-s
Copy link

sg-s commented Nov 12, 2024

Description

I installed jupyter, jupyterai and langchain-openai in a clean environment (using pixi). I entered my openAI api key and the chat window seems to work. however, using the %%ai magic in the notebook doesn't work

Reproduce

screenshot showing that the chat window works

Screenshot 2024-11-11 at 7 11 16 PM

screenshot showing that it knows about my openAI key:

Screenshot 2024-11-11 at 7 12 01 PM

error:

AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-QoS0U***************************************KCxR. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

Expected behavior

it to not throw an authenticationerror

Context

jupyter = ">=1.1.1,<2"
jupyterlab = ">=4.2.5,<5"
jupyter-ai = ">=2.28.1,<3"
langchain-openai = ">=0.1.25,<0.2"

@sg-s sg-s added the bug Something isn't working label Nov 12, 2024
@sg-s
Copy link
Author

sg-s commented Nov 12, 2024

i found workaround: i had to manually specify my key in the notebook using:

env OPENAI_API_KEY = <my key>

the clue was that

'Incorrect API key provided: sk-QoS0U***************************************KCxR.

is not my key

no idea why it decides to use some randomn key instead of the one i entered in the notebook

@dlqqq
Copy link
Member

dlqqq commented Nov 12, 2024

@sg-s Jupyter AI magic commands can't read API keys from the chat settings in the UI. They only read from the set of environment variables. This is a known issue, and is due to a technical difficulty with passing data between the notebook kernel and the server.

What likely happened is that OPENAI_API_KEY was set to an outdated API key or an incomplete API key (e.g. perhaps you only copied the first 30 characters of the API key).

If you want to use both chat & magics simultaneously, we recommend setting the API key with both the environment variable OPENAI_API_KEY and through the chat settings for now.

This is definitely a usability issue that we should address in v3.0.0. I'll add it to our roadmap.

@dlqqq dlqqq changed the title Chat window works, but %%ai magic in notebook cell does not Chat window works, but IPython magics do not Nov 12, 2024
@dlqqq dlqqq added this to the v3.0.0 milestone Nov 12, 2024
@sg-s
Copy link
Author

sg-s commented Nov 12, 2024

thanks for the response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants