Add explicit check for jsonref dep in vertexai client import guard #797
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.
b8ceaf6 introduced a dependency on jsonref in client_vertexai.py. This dependency is not present in a standard vertexai installation. The top-level __init__.py tries to export client_vertex.ai regardless of whether jsonref is installed, triggering an import error (#772).
This can be quite puzzling for users who may have vertexai installed in their environment for different reasons.
I ran into this issue as well because I'm using the AnthropicVertex client from Anthropic's SDK. The Anthropic docs say to pip install both anthropic[vertex] and google-cloud-aiplatform. The second package adds vertexai to my environment. As a result, even though I don't want to use Instructor's Vertex AI client, Instructor will try to import it.
The proposed solution is a tiny tweak to the import guard so that it explicitly checks whether jsonref is installed. When instructor is installed with the 'vertexai' extra, this check is guaranteed to pass. In other cases, unless a different depedency has happened to install jsonref, it will fail.
Summary:
Add explicit check for
jsonref
dependency invertexai
import guard ininstructor/__init__.py
.Key points:
instructor/__init__.py
to check for bothvertexai
andjsonref
before importingfrom_vertexai
.jsonref
is not installed butvertexai
is present.from_vertexai
is only added to__all__
if both dependencies are available.Generated with ❤️ by ellipsis.dev