jupyterlab / jupyter-ai

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

Frontend Problem not able to select a provider #911

Closed Yuvraj-Dhepe closed 2 months ago

Yuvraj-Dhepe commented 4 months ago

Description

I installed the jupyter ai extension in a mamba environment using pip install jupyter-ai, I got jupyter lab installed automatically with this command. However, when I loaded the jupyter lab, I get image

In the terminal I get the following errors when I start the jupyter lab jupyter lab --no-browser

jupyter lab --no-browser
[W 2024-07-26 03:07:25.130 ServerApp] jupyter_ai | error adding extension (enabled: True): unhashable type: 'list'
    Traceback (most recent call last):
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 323, in add_extension
        extpkg = ExtensionPackage(name=extension_name, enabled=enabled)
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 187, in __init__
        self._load_metadata()
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/jupyter_server/extension/manager.py", line 196, in _load_metadata
        self.module, self.metadata = get_metadata(name, logger=self.log)
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/jupyter_server/extension/utils.py", line 65, in get_metadata
        module = importlib.import_module(package_name)
      File "~/micromamba/envs/audio_dl/lib/python3.9/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 790, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/jupyter_ai/__init__.py", line 10, in <module>
        from .extension import AiExtension
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/jupyter_ai/extension.py", line 6, in <module>
        from dask.distributed import Client as DaskClient
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/dask/distributed.py", line 13, in <module>
        from distributed import *
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/distributed/__init__.py", line 23, in <module>
        from distributed.actor import Actor, ActorFuture, BaseActorFuture
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/distributed/actor.py", line 13, in <module>
        from distributed.client import Future
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/distributed/client.py", line 132, in <module>
        from distributed.worker import get_client, get_worker, secede
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/distributed/worker.py", line 119, in <module>
        from distributed.worker_memory import (
      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/distributed/worker_memory.py", line 56, in <module>
        WorkerDataParameter: TypeAlias = Union[
      File "~/micromamba/envs/audio_dl/lib/python3.9/typing.py", line 243, in inner
        return func(*args, **kwds)
      File "~/micromamba/envs/audio_dl/lib/python3.9/typing.py", line 316, in __getitem__
        return self._getitem(self, parameters)
      File "~/micromamba/envs/audio_dl/lib/python3.9/typing.py", line 421, in Union
        parameters = _remove_dups_flatten(parameters)
      File "~/micromamba/envs/audio_dl/lib/python3.9/typing.py", line 215, in _remove_dups_flatten
        all_params = set(params)
    TypeError: unhashable type: 'list'

P.S. Filepaths were in format /home//micromamba/... to avoid user_name here, I replaced it with ~/micromamba/...

Reproduce

1) Create a simple mamba environment: mamba create -f environment.yaml

Contents of yaml file

name: audio_dl
channels:
- conda-forge
dependencies:
- python=3.9.0

2) Install requirements of the env, which I had as following:

gensim==4.3.0
h5py==3.7.0
huggingface-hub==0.12.1
librosa==0.9.2
mutagen==1.46.0
nltk==3.7
numpy==1.23.5
pandas==1.5.2
ray==1.13.0
sentence-transformers==2.2.2
six==1.16.0
soundfile==0.12.1
transformers==4.24.0
IProgress
datasets[audio]
ipykernel

3) Install the jupyter ai package: pip install jupyter-ai

4) Start the jupyter lab server: jupyter lab --no-browser

5) Later open the chat widget to see if the chat works

Expected behavior

Context

Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
You may want to sanitize the paths in the output.

$PATH: /home//micromamba/envs/audio_dl/bin /home//.local/bin /home//.bun/bin /home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/sbin /home//micromamba/condabin /usr/local/cuda-12.4/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games /usr/lib/wsl/lib /mnt/c/Program Files/Microsoft MPI/Bin/ /mnt/c/WINDOWS/system32 /mnt/c/WINDOWS /mnt/c/WINDOWS/System32/Wbem /mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/ /mnt/c/WINDOWS/System32/OpenSSH/ /mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common /mnt/c/Program Files/NVIDIA Corporation/NVIDIA App/NvDLISR /mnt/c/Program Files/usbipd-win/ /mnt/d/WSL/work/Git/cmd /mnt/c/Program Files/PowerShell/7/ /mnt/c/Users//AppData/Local/Microsoft/WindowsApps /mnt/c/Users//AppData/Local/Programs/Microsoft VS Code/bin /mnt/c/Users//AppData/Local/Programs/oh-my-posh/bin /mnt/c/Users//AppData/Local/GitHubDesktop/bin /mnt/c/Users//AppData/Local/Programs/Ollama /mnt/d/WSL/work/micromamba /snap/bin

sys.path: /home//micromamba/envs/audio_dl/bin /home//micromamba/envs/audio_dl/lib/python39.zip /home//micromamba/envs/audio_dl/lib/python3.9 /home//micromamba/envs/audio_dl/lib/python3.9/lib-dynload /home//micromamba/envs/audio_dl/lib/python3.9/site-packages

sys.executable: /home//micromamba/envs/audio_dl/bin/python3.9

sys.version: 3.9.0 | packaged by conda-forge | (default, Nov 26 2020, 07:57:39) [GCC 9.3.0]

platform.platform(): Linux-5.15.150.1-microsoft-standard-WSL2+-x86_64-with-glibc2.35

which -a jupyter: /home//micromamba/envs/audio_dl/bin/jupyter

pip list: Package Version


ai21                          2.9.2
ai21-tokenizer                0.11.2
aiohttp                       3.9.5
aiolimiter                    1.1.0
aiosignal                     1.3.1
aiosqlite                     0.20.0
annotated-types               0.7.0
anthropic                     0.31.2
anyio                         4.4.0
argon2-cffi                   23.1.0
argon2-cffi-bindings          21.2.0
arrow                         1.3.0
arxiv                         2.1.3
asttokens                     2.4.1
async-lru                     2.0.4
async-timeout                 4.0.3
attrs                         23.2.0
audioread                     3.0.1
Babel                         2.15.0
bce-python-sdk                0.9.17
beautifulsoup4                4.12.3
bleach                        6.1.0
boto3                         1.34.149
botocore                      1.34.149
cachetools                    5.4.0
certifi                       2024.7.4
cffi                          1.16.0
charset-normalizer            3.3.2
click                         8.1.7
cloudpickle                   3.0.0
cohere                        5.6.2
comm                          0.2.2
contourpy                     1.2.1
cycler                        0.12.1
dask                          2024.7.1
dataclasses-json              0.6.7
datasets                      2.20.0
debugpy                       1.8.2
decorator                     5.1.1
deepmerge                     1.1.1
defusedxml                    0.7.1
dill                          0.3.8
diskcache                     5.6.3
distributed                   2024.7.1
distro                        1.9.0
eval_type_backport            0.2.0
exceptiongroup                1.2.2
executing                     2.0.1
faiss-cpu                     1.8.0
fastavro                      1.9.5
fastjsonschema                2.20.0
feedparser                    6.0.11
filelock                      3.15.4
fonttools                     4.53.1
fqdn                          1.5.1
frozenlist                    1.4.1
fsspec                        2024.5.0
fst-pso                       1.8.1
future                        1.0.0
FuzzyTM                       2.0.9
gensim                        4.3.0
google-ai-generativelanguage  0.6.6
google-api-core               2.19.1
google-api-python-client      2.138.0
google-auth                   2.32.0
google-auth-httplib2          0.2.0
google-generativeai           0.7.2
googleapis-common-protos      1.63.2
gpt4all                       2.7.0
greenlet                      3.0.3
grpcio                        1.65.1
grpcio-status                 1.62.2
h11                           0.14.0
h5py                          3.7.0
httpcore                      1.0.5
httplib2                      0.22.0
httpx                         0.27.0
httpx-sse                     0.4.0
huggingface-hub               0.24.2
idna                          3.7
importlib_metadata            8.0.0
importlib_resources           6.4.0
IProgress                     0.4
ipykernel                     6.29.5
ipython                       8.18.1
ipywidgets                    8.1.3
isoduration                   20.11.0
jedi                          0.19.1
Jinja2                        3.1.4
jiter                         0.5.0
jmespath                      1.0.1
joblib                        1.4.2
json5                         0.9.25
jsonpatch                     1.33
jsonpath-ng                   1.6.1
jsonpointer                   3.0.0
jsonschema                    4.23.0
jsonschema-specifications     2023.12.1
jupyter_ai                    2.19.1
jupyter_ai_magics             2.19.1
jupyter_client                8.6.2
jupyter_core                  5.7.2
jupyter-events                0.10.0
jupyter-lsp                   2.2.5
jupyter_server                2.14.2
jupyter_server_terminals      0.5.3
jupyterlab                    4.2.4
jupyterlab_pygments           0.3.0
jupyterlab_server             2.27.3
jupyterlab_widgets            3.0.11
kiwisolver                    1.4.5
langchain                     0.2.11
langchain-anthropic           0.1.20
langchain-cohere              0.1.9
langchain-community           0.2.10
langchain-core                0.2.23
langchain-experimental        0.0.63
langchain-google-genai        1.0.8
langchain-mistralai           0.1.10
langchain-nvidia-ai-endpoints 0.2.0
langchain-openai              0.1.17
langchain-text-splitters      0.2.2
langsmith                     0.1.93
lazy_loader                   0.4
librosa                       0.10.2.post1
llvmlite                      0.43.0
locket                        1.0.0
markdown-it-py                3.0.0
MarkupSafe                    2.1.5
marshmallow                   3.21.3
matplotlib                    3.9.1
matplotlib-inline             0.1.7
mdurl                         0.1.2
miniful                       0.0.6
mistune                       3.0.2
mpmath                        1.3.0
msgpack                       1.0.8
multidict                     6.0.5
multiprocess                  0.70.16
mutagen                       1.46.0
mypy-extensions               1.0.0
nbclient                      0.10.0
nbconvert                     7.16.4
nbformat                      5.10.4
nest-asyncio                  1.6.0
networkx                      3.2.1
nltk                          3.7
notebook_shim                 0.2.4
numba                         0.60.0
numpy                         1.24.4
nvidia-cublas-cu12            12.1.3.1
nvidia-cuda-cupti-cu12        12.1.105
nvidia-cuda-nvrtc-cu12        12.1.105
nvidia-cuda-runtime-cu12      12.1.105
nvidia-cudnn-cu12             8.9.2.26
nvidia-cufft-cu12             11.0.2.54
nvidia-curand-cu12            10.3.2.106
nvidia-cusolver-cu12          11.4.5.107
nvidia-cusparse-cu12          12.1.0.106
nvidia-nccl-cu12              2.20.5
nvidia-nvjitlink-cu12         12.5.82
nvidia-nvtx-cu12              12.1.105
openai                        1.37.1
orjson                        3.10.6
overrides                     7.7.0
packaging                     24.1
pandas                        1.5.3
pandocfilters                 1.5.1
parameterized                 0.9.0
parso                         0.8.4
partd                         1.4.2
pexpect                       4.9.0
pillow                        10.4.0
pip                           24.0
pip-autoremove                0.10.0
platformdirs                  4.2.2
ply                           3.11
pooch                         1.8.2
prometheus_client             0.20.0
prompt_toolkit                3.0.47
proto-plus                    1.24.0
protobuf                      4.25.4
psutil                        6.0.0
ptyprocess                    0.7.0
pure-eval                     0.2.2
pyarrow                       17.0.0
pyarrow-hotfix                0.6
pyasn1                        0.6.0
pyasn1_modules                0.4.0
pycparser                     2.22
pycryptodome                  3.20.0
pydantic                      2.8.2
pydantic_core                 2.20.1
pyFUME                        0.3.4
Pygments                      2.18.0
pyparsing                     3.1.2
pypdf                         4.3.1
python-dateutil               2.9.0.post0
python-dotenv                 1.0.1
python-json-logger            2.0.7
pytz                          2024.1
PyYAML                        6.0.1
pyzmq                         26.0.3
qianfan                       0.4.2
referencing                   0.35.1
regex                         2024.5.15
requests                      2.32.3
resampy                       0.4.3
rfc3339-validator             0.1.4
rfc3986-validator             0.1.1
rich                          13.7.1
rpds-py                       0.19.1
rsa                           4.9
s3transfer                    0.10.2
scikit-learn                  1.5.1
scipy                         1.10.1
Send2Trash                    1.8.3
sentence-transformers         2.2.2
sentencepiece                 0.2.0
setuptools                    71.0.4
sgmllib3k                     1.0.0
shellingham                   1.5.4
simpful                       2.12.0
six                           1.16.0
smart-open                    7.0.4
sniffio                       1.3.1
sortedcontainers              2.4.0
soundfile                     0.12.1
soupsieve                     2.5
soxr                          0.3.7
SQLAlchemy                    2.0.31
stack-data                    0.6.3
sympy                         1.13.1
tabulate                      0.9.0
tblib                         3.0.0
tenacity                      8.5.0
terminado                     0.18.1
threadpoolctl                 3.5.0
tiktoken                      0.7.0
tinycss2                      1.3.0
together                      1.2.3
tokenizers                    0.19.1
tomli                         2.0.1
toolz                         0.12.1
torch                         2.3.1
torchvision                   0.18.1
tornado                       6.4.1
tqdm                          4.66.4
traitlets                     5.14.3
transformers                  4.24.0
triton                        2.3.1
typer                         0.12.3
types-python-dateutil         2.9.0.20240316
types-requests                2.31.0.6
types-urllib3                 1.26.25.14
typing_extensions             4.12.2
typing-inspect                0.9.0
uri-template                  1.3.0
uritemplate                   4.1.1
urllib3                       1.26.19
wcwidth                       0.2.13
webcolors                     24.6.0
webencodings                  0.5.1
websocket-client              1.8.0
wheel                         0.43.0
widgetsnbextension            4.0.11
wrapt                         1.16.0
xxhash                        3.4.1
yarl                          1.9.4
zict                          3.0.0
zipp                          3.19.2
Command Line Output
Paste the output from your command line running `jupyter lab` here, use `--debug` if possible.
Browser Output
Paste the output from your browser Javascript console here, if applicable.

image

Yuvraj-Dhepe commented 4 months ago

cmd_line_opt.txt This is the cmd opt with debug option

jhgoebbert commented 3 months ago

This is an issue with your Dask/distributed version. Checking the backtrace

      File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/distributed/worker_memory.py", line 56, in <module>
        WorkerDataParameter: TypeAlias = Union[

and the code https://github.com/dask/distributed/blob/main/distributed/worker_memory.py#L56 you can find the issue here: https://github.com/dask/distributed/issues/8349

Upgrading to Python 3.9.2 seems to be the solution.

Yuvraj-Dhepe commented 3 months ago

Perfect Thanks @jhgoebbert It worked out.

Yuvraj-Dhepe commented 3 months ago

I was able to use the chat option, however the leanr option seems to throw errors.

 /learn chat handler resolved in 18 ms.
2024-07-27 22:13:28,026 - distributed.worker - WARNING - Compute Failed
Key:       embed_chunk-b36c3fe5-b881-4826-9ca9-d4ba836341a3
State:     executing
Function:  execute_task
args:      ((<function embed_chunk at 0x7f1439475ca0>, Document(metadata={'path': '~/work/Projects/Audio_DL/dcase2023-audio-retrieval/utils/data_utils.py', 'sha256': b'\xa9!\x9d\x88e\xef\x966R\xbc\xb0\x8d\x9bf\xfb$\x1am\xa9\xd3\xc1\xf8PJ\xa1\x84-\x82\xc7N\x10\x87', 'extension': '.py'}, page_content='import os\nimport pickle\nfrom ast import literal_eval\n\nimport h5py\nimport nltk\nimport numpy as np\nimport pandas as pd\nimport torch\nimport torch.nn.functional as F\nfrom torch.utils.data import Dataset\n\nstopwords = nltk.corpus.stopwords.words("english")\n\n\nclass Vocabulary(object):\n\n    def __init__(self):\n        self.key2vec = {}\n        self.key2id = {}\n        self.id = 0\n\n    def add_key(self, key, key_vector):\n        if key not in self.key2id:\n            self.key2vec[key] = key_vector\n            self.key2id[key] = self.id\n            self.id += 1\n\n    def __call__(self, key):\n        return self.key2id[key]\n\n    def __len__(self):\n        return len(self
kwargs:    {}
Exception: 'ValueError("Error raised by inference endpoint: HTTPConnectionPool(host=\'localhost\', port=11434): Max retries exceeded with url: /api/embeddings (Caused by NewConnectionError(\'<urllib3.connection.HTTPConnection object at 0x7f142a5f1b50>: Failed to establish a new connection: [Errno 111] Connection refused\'))")'
Traceback: '  File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/jupyter_ai/document_loaders/directory.py", line 165, in embed_chunk\n    embedding = em.embed_query(content)\n  File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/langchain_community/embeddings/ollama.py", line 224, in embed_query\n    embedding = self._embed([instruction_pair])[0]\n  File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/langchain_community/embeddings/ollama.py", line 199, in _embed\n    return [self._process_emb_response(prompt) for prompt in iter_]\n  File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/langchain_community/embeddings/ollama.py", line 199, in <listcomp>\n    return [self._process_emb_response(prompt) for prompt in iter_]\n  File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/langchain_community/embeddings/ollama.py", line 170, in _process_emb_response\n    raise ValueError(f"Error raised by inference endpoint: {e}")\n'

2024-07-27 22:13:28,026 - distributed.worker - WARNING - Compute Failed
Key:       embed_chunk-c20dc18c-5eac-4fc8-b0c8-8bc59710e107
State:     executing
Function:  execute_task
args:      ((<function embed_chunk at 0x7f1439475ca0>, Document(metadata={'path': '~/work/Projects/Audio_DL/dcase2023-audio-retrieval/utils/data_utils.py', 'sha256': b'\xa9!\x9d\x88e\xef\x966R\xbc\xb0\x8d\x9bf\xfb$\x1am\xa9\xd3\xc1\xf8PJ\xa1\x84-\x82\xc7N\x10\x87', 'extension': '.py'}, page_content='class AudioTextDataset(Dataset):\n\n    def __init__(self, **kwargs):\n        self.audio_data = kwargs["audio_data"]\n        self.text_data = kwargs["text_data"]\n        self.text_vocab = kwargs["text_vocab"]\n        self.text_level = kwargs["text_level"]\n\n    def __getitem__(self, index):\n        item = self.text_data.iloc[index]\n\n        audio_vec = torch.as_tensor(self.audio_data[item["fid"]][()])\n\n        text_vec = None\n\n        if self.text_level == "word":\n            text_vec = torch.as_tensor([self.text_vocab(key) for key in item["tokens"] if key not in stopwords])\n\n        elif self.text_level == "sentence":\n            text_vec = torch.as_tensor([self.text_vocab(
kwargs:    {}
Exception: 'ValueError("Error raised by inference endpoint: HTTPConnectionPool(host=\'localhost\', port=11434): Max retries exceeded with url: /api/embeddings (Caused by NewConnectionError(\'<urllib3.connection.HTTPConnection object at 0x7f142a5f3670>: Failed to establish a new connection: [Errno 111] Connection refused\'))")'
Traceback: '  File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/jupyter_ai/document_loaders/directory.py", line 165, in embed_chunk\n    embedding = em.embed_query(content)\n  File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/langchain_community/embeddings/ollama.py", line 224, in embed_query\n    embedding = self._embed([instruction_pair])[0]\n  File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/langchain_community/embeddings/ollama.py", line 199, in _embed\n    return [self._process_emb_response(prompt) for prompt in iter_]\n  File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/langchain_community/embeddings/ollama.py", line 199, in <listcomp>\n    return [self._process_emb_response(prompt) for prompt in iter_]\n  File "~/micromamba/envs/audio_dl/lib/python3.9/site-packages/langchain_community/embeddings/ollama.py", line 170, in _process_emb_response\n    raise ValueError(f"Error raised by inference endpoint: {e}")\n'

image This is my jupyter ai settings, I also do have the embeddings model running at the provided host and port.

jhgoebbert commented 3 months ago

If you check the stacktrace carefully you can see that this is more an issue belonging to langchain / docker. A quick look there will lead you for example to this: https://github.com/langchain-ai/langchain/issues/19074 """The issue is with the docker compose configuration."""

sdhdez commented 3 months ago

Hi,

I'm encountering a similar issue with Ollama running behind a reverse proxy. Interestingly, I haven't configured port 11434 at all and I'm still having this error:

ConnectionError: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fac48882d80>: Failed to establish a new connection: [Errno 111] Connection refused'))

It seems that jupyter-ai is ignoring the base_url specified in the interface settings. Instead, it's using the hardcoded base_url: str = "http://localhost:11434" :

~$ find . -type f -name "*.py" | xargs grep "localhost:1111434"  --color 
./.conda/pkgs/langchain-community-0.2.12-pyhd8ed1ab_0/site-packages/langchain_community/llms/ollama.py:    base_url: str = "http://localhost:11434"
./.conda/pkgs/langchain-community-0.2.12-pyhd8ed1ab_0/site-packages/langchain_community/embeddings/ollama.py:    base_url: str = "http://localhost:11434"
./.conda/envs/MyPyEnv/lib/python3.12/site-packages/langchain_community/llms/ollama.py:    base_url: str = "http://localhost:11434"
./.conda/envs/MyPyEnv/lib/python3.12/site-packages/langchain_community/embeddings/ollama.py:    base_url: str = "http://localhost:11434"

Update: It seems the issue is addressed here #902.

srdas commented 2 months ago

Issue #902 has raised this issue and it is fixed in PR #904 - closing this issue.