jxnl / instructor

structured outputs for llms
https://python.useinstructor.com/
MIT License
6.52k stars 514 forks source link

Add explicit check for jsonref dep in vertexai client import guard #797

Closed lemontheme closed 2 days ago

lemontheme commented 4 days ago

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.


: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:


Generated with :heart: by ellipsis.dev