Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only import cohere when using cohere functionality #876

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

avyfain
Copy link
Contributor

@avyfain avyfain commented Jul 24, 2024

https://github.com/jxnl/instructor/pull/866/files breaks non-cohere users. This PR should solve that issue.

Will separately open a ticket to have tests run on clean installs.


🚀 This description was created by Ellipsis for commit 8e8bf8b

Summary:

Import cohere only when using its functionality to avoid breaking non-cohere users in instructor/function_calls.py.

Key points:

  • File: instructor/function_calls.py
  • Class: OpenAISchema
  • Method: parse_cohere_json_schema
  • Change: Moved the import of NonStreamedChatResponse from cohere inside the parse_cohere_json_schema method to avoid breaking non-cohere users.

Generated with ❤️ by ellipsis.dev

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to 8e8bf8b in 25.965249 seconds

More details
  • Looked at 28 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. instructor/function_calls.py:282
  • Draft comment:
    The change to conditionally import NonStreamedChatResponse within parse_cohere_json_schema is a good practice to avoid issues for users who do not use Cohere. This approach minimizes the impact on users who do not have the cohere package installed.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The PR aims to fix an issue for non-Cohere users by conditionally importing the NonStreamedChatResponse from the cohere package only within the method that requires it. This is a common practice to avoid unnecessary imports that might cause issues for users who do not have certain dependencies installed. The change is localized to the parse_cohere_json_schema method where the NonStreamedChatResponse is specifically needed. The use of assert isinstance(completion, NonStreamedChatResponse) right after the import ensures that the completion object is of the expected type, which is a good practice for type checking especially when dynamic imports are used.

Workflow ID: wflow_Eq502eGFjzeCMXeP


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant