jupyterlab / jupyter-ai

A generative AI extension for JupyterLab
https://jupyter-ai.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
3.25k stars 334 forks source link

Update README, docs to mention API keys / authentication in prerequisites #315

Closed theBigTao closed 1 year ago

theBigTao commented 1 year ago

Description

After installation, I typed %load_ext jupyter_ai %%ai chatgpt -f math Generate the 2D heat equation and get errors:

RateLimitError                            Traceback (most recent call last)

Reproduce

  1. jupyter lab
  2. type in cell 1: %load_ext jupyter_ai
  3. type in cell 2: %%ai chatgpt -f math Generate the 2D heat equation.
  4. See error below

    RateLimitError Traceback (most recent call last) Cell In[8], line 1 ----> 1 get_ipython().run_cell_magic('ai', 'chatgpt -f math', 'Generate the 2D heat equation.\n')

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/IPython/core/interactiveshell.py:2430, in InteractiveShell.run_cell_magic(self, magic_name, line, cell) 2428 with self.builtin_trap: 2429 args = (magic_arg_s, cell) -> 2430 result = fn(*args, **kwargs) 2432 # The code below prevents the output from being displayed 2433 # when using magics with decodator @output_can_be_silenced 2434 # when the last Python token in the expression is a ';'. 2435 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/jupyter_ai_magics/magics.py:603, in AiMagics.ai(self, line, cell) 600 ip = get_ipython() 601 prompt = prompt.format_map(FormatDict(ip.user_ns)) --> 603 return self.run_ai_cell(args, prompt)

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/jupyter_ai_magics/magics.py:545, in AiMagics.run_ai_cell(self, args, prompt) 542 provider = Provider(**provider_params) 544 # generate output from model via provider --> 545 result = provider.generate([prompt]) 546 output = result.generations[0][0].text 548 # if openai-chat, append exchange to transcript

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/langchain/llms/base.py:227, in BaseLLM.generate(self, prompts, stop, callbacks, tags, kwargs) 221 raise ValueError( 222 "Asked to cache, but no cache found at langchain.cache." 223 ) 224 run_managers = callback_manager.on_llm_start( 225 dumpd(self), prompts, invocation_params=params, options=options 226 ) --> 227 output = self._generate_helper( 228 prompts, stop, run_managers, bool(new_arg_supported), kwargs 229 ) 230 return output 231 if len(missing_prompts) > 0:

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/langchain/llms/base.py:178, in BaseLLM._generate_helper(self, prompts, stop, run_managers, new_arg_supported, **kwargs) 176 for run_manager in run_managers: 177 run_manager.on_llm_error(e) --> 178 raise e 179 flattened_outputs = output.flatten() 180 for manager, flattened_output in zip(run_managers, flattened_outputs):

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/langchain/llms/base.py:165, in BaseLLM._generate_helper(self, prompts, stop, run_managers, new_arg_supported, kwargs) 155 def _generate_helper( 156 self, 157 prompts: List[str], (...) 161 kwargs: Any, 162 ) -> LLMResult: 163 try: 164 output = ( --> 165 self._generate( 166 prompts, 167 stop=stop, 168 # TODO: support multiple run managers 169 run_manager=run_managers[0] if run_managers else None, 170 **kwargs, 171 ) 172 if new_arg_supported 173 else self._generate(prompts, stop=stop) 174 ) 175 except (KeyboardInterrupt, Exception) as e: 176 for run_manager in run_managers:

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/langchain/llms/openai.py:822, in OpenAIChat._generate(self, prompts, stop, run_manager, kwargs) 818 return LLMResult( 819 generations=[[Generation(text=response)]], 820 ) 821 else: --> 822 full_response = completion_with_retry(self, messages=messages, params) 823 llm_output = { 824 "token_usage": full_response["usage"], 825 "model_name": self.model_name, 826 } 827 return LLMResult( 828 generations=[ 829 [Generation(text=full_response["choices"][0]["message"]["content"])] 830 ], 831 llm_output=llm_output, 832 )

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/langchain/llms/openai.py:106, in completion_with_retry(llm, kwargs) 102 @retry_decorator 103 def _completion_with_retry(kwargs: Any) -> Any: 104 return llm.client.create(kwargs) --> 106 return _completion_with_retry(kwargs)

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/tenacity/init.py:289, in BaseRetrying.wraps..wrapped_f(*args, kw) 287 @functools.wraps(f) 288 def wrapped_f(*args: t.Any, *kw: t.Any) -> t.Any: --> 289 return self(f, args, kw)

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/tenacity/init.py:379, in Retrying.call(self, fn, *args, **kwargs) 377 retry_state = RetryCallState(retry_object=self, fn=fn, args=args, kwargs=kwargs) 378 while True: --> 379 do = self.iter(retry_state=retry_state) 380 if isinstance(do, DoAttempt): 381 try:

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/tenacity/init.py:325, in BaseRetrying.iter(self, retry_state) 323 retry_exc = self.retry_error_cls(fut) 324 if self.reraise: --> 325 raise retry_exc.reraise() 326 raise retry_exc from fut.exception() 328 if self.wait:

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/tenacity/init.py:158, in RetryError.reraise(self) 156 def reraise(self) -> t.NoReturn: 157 if self.last_attempt.failed: --> 158 raise self.last_attempt.result() 159 raise self

    File ~/.pyenv/versions/3.9.11/lib/python3.9/concurrent/futures/_base.py:439, in Future.result(self, timeout) 437 raise CancelledError() 438 elif self._state == FINISHED: --> 439 return self.__get_result() 441 self._condition.wait(timeout) 443 if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:

    File ~/.pyenv/versions/3.9.11/lib/python3.9/concurrent/futures/_base.py:391, in Future.__get_result(self) 389 if self._exception: 390 try: --> 391 raise self._exception 392 finally: 393 # Break a reference cycle with the exception in self._exception 394 self = None

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/tenacity/init.py:382, in Retrying.call(self, fn, *args, *kwargs) 380 if isinstance(do, DoAttempt): 381 try: --> 382 result = fn(args, **kwargs) 383 except BaseException: # noqa: B902 384 retry_state.set_exception(sys.exc_info()) # type: ignore[arg-type]

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/langchain/llms/openai.py:104, in completion_with_retry.._completion_with_retry(kwargs) 102 @retry_decorator 103 def _completion_with_retry(kwargs: Any) -> Any: --> 104 return llm.client.create(**kwargs)

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/openai/api_resources/chat_completion.py:25, in ChatCompletion.create(cls, *args, *kwargs) 23 while True: 24 try: ---> 25 return super().create(args, **kwargs) 26 except TryAgain as e: 27 if timeout is not None and time.time() > start + timeout:

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/openai/api_resources/abstract/engine_api_resource.py:153, in EngineAPIResource.create(cls, api_key, api_base, api_type, request_id, api_version, organization, params) 127 @classmethod 128 def create( 129 cls, (...) 136 params, 137 ): 138 ( 139 deployment_id, 140 engine, (...) 150 api_key, api_base, api_type, apiversion, organization, **params 151 ) --> 153 response, , api_key = requestor.request( 154 "post", 155 url, 156 params=params, 157 headers=headers, 158 stream=stream, 159 request_id=request_id, 160 request_timeout=request_timeout, 161 ) 163 if stream: 164 # must be an iterator 165 assert not isinstance(response, OpenAIResponse)

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/openai/api_requestor.py:230, in APIRequestor.request(self, method, url, params, headers, files, stream, request_id, request_timeout) 209 def request( 210 self, 211 method, (...) 218 request_timeout: Optional[Union[float, Tuple[float, float]]] = None, 219 ) -> Tuple[Union[OpenAIResponse, Iterator[OpenAIResponse]], bool, str]: 220 result = self.request_raw( 221 method.lower(), 222 url, (...) 228 request_timeout=request_timeout, 229 ) --> 230 resp, got_stream = self._interpret_response(result, stream) 231 return resp, got_stream, self.api_key

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/openai/api_requestor.py:624, in APIRequestor._interpret_response(self, result, stream) 616 return ( 617 self._interpret_response_line( 618 line, result.status_code, result.headers, stream=True 619 ) 620 for line in parse_stream(result.iter_lines()) 621 ), True 622 else: 623 return ( --> 624 self._interpret_response_line( 625 result.content.decode("utf-8"), 626 result.status_code, 627 result.headers, 628 stream=False, 629 ), 630 False, 631 )

    File ~/.pyenv/versions/3.9.11/lib/python3.9/site-packages/openai/api_requestor.py:687, in APIRequestor._interpret_response_line(self, rbody, rcode, rheaders, stream) 685 stream_error = stream and "error" in resp.data 686 if stream_error or not 200 <= rcode < 300: --> 687 raise self.handle_error_response( 688 rbody, rcode, resp.data, rheaders, stream_error=stream_error 689 ) 690 return resp

    RateLimitError: You exceeded your current quota, please check your plan and billing details.

Expected behavior

Succeeds in generating 2D heat equation.

Context

Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
PATH:
    /Users/username/.pyenv/versions/3.9.11/bin
    /opt/homebrew/Cellar/pyenv/2.3.12/libexec
    /opt/homebrew/Cellar/pyenv/2.3.12/plugins/python-build/bin
    /opt/homebrew/Cellar/pyenv-virtualenv/1.2.1/shims
    /Users/username/.pyenv/shims
    /Users/username/.pyenv/bin
    /Users/username/.composer/vendor/bin
    /Users/username/.local/bin
    /Users/username/tools/bin
    /opt/homebrew/bin
    /opt/local/bin
    /opt/local/bin
    /opt/local/sbin
    /opt/homebrew/bin
    /opt/homebrew/sbin
    /usr/local/bin
    /System/Cryptexes/App/usr/bin
    /usr/bin
    /bin
    /usr/sbin
    /sbin
    /opt/X11/bin
    /Library/Apple/usr/bin
    /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
    /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
    /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
    /Users/username/.cargo/bin

sys.path:
    /Users/username/.pyenv/versions/3.9.11/bin
    /Users/username/.pyenv/versions/3.9.11/lib/python39.zip
    /Users/username/.pyenv/versions/3.9.11/lib/python3.9
    /Users/username/.pyenv/versions/3.9.11/lib/python3.9/lib-dynload
    /Users/username/.pyenv/versions/3.9.11/lib/python3.9/site-packages
    /Users/username/Documents/2022Spring/ChIP/hic3defdr

sys.executable:
    /Users/username/.pyenv/versions/3.9.11/bin/python3.9

sys.version:
    3.9.11 (main, Apr 19 2022, 12:57:33)
    [Clang 13.1.6 (clang-1316.0.21.2.3)]

platform.platform():
    macOS-13.5-arm64-arm-64bit

which -a jupyter:
    /Users/username/.pyenv/versions/3.9.11/bin/jupyter
    /Users/username/.pyenv/shims/jupyter

pip list:
    Package                   Version          Editable project location
    ------------------------- ---------------- ---------------------------------------------------
    aiofiles                  23.1.0
    aiohttp                   3.8.4
    aiosignal                 1.3.1
    aiosqlite                 0.19.0
    altair                    5.0.0
    antlr4-python3-runtime    4.9.3
    anyio                     3.6.1
    appdirs                   1.4.4
    appnope                   0.1.3
    argon2-cffi               21.3.0
    argon2-cffi-bindings      21.2.0
    arrow                     1.2.3
    asttokens                 2.0.5
    async-lru                 2.0.4
    async-timeout             4.0.2
    attrs                     23.1.0
    audioread                 3.0.0
    Babel                     2.10.3
    backcall                  0.2.0
    beautifulsoup4            4.11.1
    bio                       1.3.9
    biopython                 1.79
    biothings-client          0.2.6
    bleach                    5.0.1
    Brotli                    1.0.9
    certifi                   2022.6.15
    cffi                      1.15.1
    charset-normalizer        2.0.12
    click                     8.1.3
    cloudpickle               2.2.1
    comm                      0.1.2
    contourpy                 1.0.7
    cycler                    0.11.0
    dask                      2023.7.1
    dataclasses-json          0.5.7
    debugpy                   1.6.2
    decorator                 5.1.1
    defusedxml                0.7.1
    Deprecated                1.2.14
    dill                      0.3.6
    distlib                   0.3.6
    distributed               2023.7.1
    docutils                  0.19
    entrypoints               0.4
    executing                 0.8.3
    faiss-cpu                 1.7.4
    fast-histogram            0.11
    fastapi                   0.95.2
    fastjsonschema            2.16.1
    ffmpy                     0.3.0
    filelock                  3.9.0
    fonttools                 4.34.4
    fqdn                      1.5.1
    frozenlist                1.3.3
    fsspec                    2023.5.0
    gradio                    3.32.0
    gradio_client             0.2.5
    h11                       0.14.0
    hic3defdr                 0.2.1+2.g7498ac4 /Users/username/Documents/2022Spring/ChIP/hic3defdr
    httpcore                  0.17.1
    httpx                     0.24.1
    huggingface-hub           0.14.1
    idna                      3.3
    importlib-metadata        5.2.0
    importlib-resources       5.12.0
    interlap                  0.2.7
    ipykernel                 6.15.1
    ipympl                    0.9.3
    ipython                   8.10.0
    ipython-genutils          0.2.0
    ipywidgets                8.0.4
    isoduration               20.11.0
    jedi                      0.18.1
    Jinja2                    3.1.2
    joblib                    1.2.0
    json5                     0.9.8
    jsonpath-ng               1.5.3
    jsonpointer               2.4
    jsonschema                4.18.6
    jsonschema-specifications 2023.7.1
    jupyter                   1.0.0
    jupyter_ai                2.0.0
    jupyter_ai_magics         2.0.0
    jupyter_client            8.0.3
    jupyter-console           6.5.0
    jupyter_core              5.2.0
    jupyter-events            0.7.0
    jupyter-lsp               2.2.0
    jupyter_server            2.7.0
    jupyter_server_terminals  0.4.4
    jupyterlab                4.0.3
    jupyterlab-pygments       0.2.2
    jupyterlab_server         2.24.0
    jupyterlab-widgets        3.0.5
    keyring                   23.4.1
    kiwisolver                1.4.4
    langchain                 0.0.220
    langchainplus-sdk         0.0.20
    lazy_loader               0.2
    lib5c                     0.6.1
    librosa                   0.10.0.post2
    linkify-it-py             2.0.2
    llvmlite                  0.40.0
    locket                    1.0.0
    lockfile                  0.12.2
    luigi                     3.2.0
    markdown-it-py            2.2.0
    MarkupSafe                2.1.1
    marshmallow               3.19.0
    marshmallow-enum          1.5.1
    matplotlib                3.5.2
    matplotlib-inline         0.1.3
    mdit-py-plugins           0.3.3
    mdurl                     0.1.2
    mistune                   0.8.4
    mpl-scatter-density       0.7
    mpmath                    1.2.1
    msgpack                   1.0.5
    multidict                 6.0.4
    mutagen                   1.46.0
    mygene                    3.2.2
    mypy-extensions           1.0.0
    nbclassic                 0.4.3
    nbclient                  0.6.6
    nbconvert                 6.5.0
    nbformat                  5.4.0
    nest-asyncio              1.5.5
    networkx                  3.1
    nodejs                    0.1.1
    notebook                  6.4.12
    notebook_shim             0.2.3
    numba                     0.57.0
    numexpr                   2.8.4
    numpy                     1.23.0
    omegaconf                 2.3.0
    openai                    0.27.6
    openapi-schema-pydantic   1.2.4
    optional-django           0.1.0
    orjson                    3.8.12
    overrides                 7.3.1
    packaging                 21.3
    pandas                    1.4.3
    pandocfilters             1.5.0
    parso                     0.8.3
    partd                     1.4.0
    patsy                     0.5.3
    pexpect                   4.8.0
    pickleshare               0.7.5
    Pillow                    9.2.0
    pip                       23.2.1
    pipenv                    2023.2.4
    platformdirs              2.6.2
    ply                       3.11
    pooch                     1.6.0
    powerlaw                  1.5
    prometheus-client         0.14.1
    prompt-toolkit            3.0.36
    psutil                    5.9.4
    ptyprocess                0.7.0
    pudb                      2022.1.1
    pure-eval                 0.2.2
    pycparser                 2.21
    pycryptodomex             3.17
    pydantic                  1.10.7
    pydub                     0.25.1
    Pygments                  2.12.0
    pyparsing                 3.0.9
    pyrsistent                0.18.1
    python-daemon             2.3.2
    python-dateutil           2.8.2
    python-dotenv             1.0.0
    python-json-logger        2.0.7
    python-multipart          0.0.6
    pytz                      2022.1
    PyYAML                    6.0
    pyzmq                     25.0.0
    qtconsole                 5.4.0
    QtPy                      2.3.0
    referencing               0.30.0
    regex                     2023.6.3
    requests                  2.28.0
    rfc3339-validator         0.1.4
    rfc3986-validator         0.1.1
    rpds-py                   0.9.2
    scikit-learn              1.2.1
    scipy                     1.10.0
    seaborn                   0.12.2
    semantic-version          2.10.0
    Send2Trash                1.8.0
    setuptools                58.1.0
    six                       1.16.0
    sniffio                   1.2.0
    sortedcontainers          2.4.0
    soundfile                 0.12.1
    soupsieve                 2.3.2.post1
    soxr                      0.3.5
    SQLAlchemy                2.0.15
    stack-data                0.3.0
    starlette                 0.27.0
    statsmodels               0.13.5
    sympy                     1.12
    synapseclient             2.7.2
    tblib                     2.0.0
    tenacity                  8.2.1
    terminado                 0.15.0
    threadpoolctl             3.1.0
    tiktoken                  0.4.0
    tinycss2                  1.1.1
    tk                        0.1.0
    tomli                     2.0.1
    toolz                     0.12.0
    torch                     2.0.1
    tornado                   6.2
    tqdm                      4.64.0
    traitlets                 5.9.0
    typing_extensions         4.5.0
    typing-inspect            0.8.0
    uc-micro-py               1.0.2
    uri-template              1.3.0
    urllib3                   1.26.9
    urwid                     2.1.2
    urwid-readline            0.13
    uvicorn                   0.22.0
    virtualenv                20.17.1
    virtualenv-clone          0.5.7
    wcwidth                   0.2.5
    webcolors                 1.13
    webencodings              0.5.1
    websocket-client          1.3.3
    websockets                11.0.2
    widgetsnbextension        4.0.5
    wrapt                     1.15.0
    yarl                      1.9.2
    youtube-dl                2021.12.17
    yt-dlp                    2023.3.4
    zict                      3.0.0
    zipp                      3.14.0
Command Line Output

Browser Output
Paste the output from your browser Javascript console here, if applicable.

welcome[bot] commented 1 year ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

theBigTao commented 1 year ago

The project description is kind of mis-leading. It does not say anything about setting up api keys and how:

here is the document: https://jupyter-ai.readthedocs.io/en/latest/users/index.html

JasonWeill commented 1 year ago

You can find information about configuring model providers here in the documentation: https://jupyter-ai.readthedocs.io/en/latest/users/index.html#model-providers

JasonWeill commented 1 year ago

The error you're seeing, "RateLimitError: You exceeded your current quota, please check your plan and billing details." suggests a problem with your OpenAI account. In your OpenAI account, you'll need to set up billing and usage limits. You can find more information about rate limits here: https://platform.openai.com/docs/guides/rate-limits/overview

I'm not affiliated with OpenAI, so you will need to contact the company for assistance with your account.

theBigTao commented 1 year ago

Please update the project description document to explicitly say that API key configuration is a must and how it can be done.

bharatr21 commented 1 year ago

Maybe just moving the section from https://jupyter-ai.readthedocs.io/en/latest/users/index.html#model-providers to https://jupyter-ai.readthedocs.io/en/latest/users/index.html#prerequisites or https://jupyter-ai.readthedocs.io/en/latest/users/index.html#installation should resolve such issues in future? (Or calling it setup/configuration)

bjornjorgensen commented 1 year ago

@theBigTao I have open https://github.com/jupyterlab/jupyter-ai/pull/330

JasonWeill commented 1 year ago

Fixed via #330, further addressed in #347.