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.
:rocket:
This description was created by Ellipsis for commit 933cc8570b38476c05b7a16d2c113f4aa2cc3630
Summary:
Add explicit check for jsonref dependency in vertexai import guard in instructor/__init__.py.
Key points:
Update instructor/__init__.py to check for both vertexai and jsonref before importing from_vertexai.
Prevents import errors when jsonref is not installed but vertexai is present.
Ensures from_vertexai is only added to __all__ if both dependencies are available.
https://github.com/jxnl/instructor/commit/b8ceaf6e114cb6d67c2f92ebd16a0bbd43c95154 introduced a dependency on jsonref in clientvertexai.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 (https://github.com/jxnl/instructor/issues/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 :heart: by ellipsis.dev