jupyterlab / jupyter-ai

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

Error when trying to use huggingface models with older version of `huggingface-hub` #801

Open krassowski opened 1 month ago

krassowski commented 1 month ago

Description

https://github.com/jupyterlab/jupyter-ai/pull/784 was released yesterday but it does not work out of the box on existing installations. When trying to get a reply I get:

[E 2024-05-22 10:26:26.680 AiExtension] InferenceClient.post() got an unexpected keyword argument 'stream'

I would wager that this is because a specific version of huggingface_hub is needed, but there is no pin on version as of now: huggingface_hub

https://github.com/jupyterlab/jupyter-ai/blob/465d9913d8f6679dcf79c4f6d9111b18daac08b9/packages/jupyter-ai-magics/pyproject.toml#L41

Reproduce

huggingface-hub               0.15.1
jupyter_ai                    2.16.0

Upgrading huggingface-hub to 0.23.1 fixes the problem.

Expected behavior

dlqqq commented 1 month ago

@krassowski Thank you for documenting this! The huggingface_hub dependency is listed in the [all] optional dependency group, as we keep all of our model provider dependencies optional to minimize conflicts with a user's environment.

To install & upgrade all optional dependencies, you should be able to run:

pip install -U "jupyter_ai[all]"

I agree that we should both 1) add version ranges to each provider's declared dependencies, and 2) somehow check in the backend both a) whether the package is installed, and b) whether the package meets the version range, if specified.

2.a) is tracked in #680. Most ImportErrors raised by LangChain are caught and returned as an error message in the chat, but there seem to be edge cases that require further investigation. 1) and 2.b) are not implemented. I had explored this route, but ran into difficulties reliably getting the version of a package.