Allow usage without NVIDIA partner package #622
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
#579 added a change that imports the partner package
langchain_nvidia_ai_endpoints
directly, which causes anImportError
to be raised when importingjupyter_ai
without the partner package installed in the same environment.PR description
This PR fixes that issue by defining the NVIDIA provider in an isolated module that is not imported by anything else in
jupyter_ai_magics
. This allows that module to import fromlangchain_nvidia_ai_endpoints
directly. This branch also catches anyImportError
raised while loading the entry points and prints a short helpful warning to the terminal:Reviewing this PR
You will need to re-install the package, then test both cases:
Callout for future work
One issue with this PR is that it breaks our provider convention where everything is re-exposed at the top-level package. That is, the statement
works for
AI21Provider
, but fails forChatNVIDIAProvider
.In the future, I actually would like to revert our convention of exposing all the providers at the package root. We only do so now because I thought that entry points could only be exposed from the package root, which is untrue. This effort would require first removing all of these imports from
packages/jupyter-ai-magics/jupyter_ai_magics/__init__.py
:Then, editing each entry point definition from:
To a definition that specifies the source module directly: