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

feat: add watsonx support #620

Merged
merged 8 commits into from
Apr 29, 2024
Merged

feat: add watsonx support #620

merged 8 commits into from
Apr 29, 2024

Conversation

h0rv
Copy link
Contributor

@h0rv h0rv commented Apr 21, 2024

#619


🚀 This description was created by Ellipsis for commit 8853244

Summary:

This PR introduces IBM Watson AI support in the instructor library, including a new example, updates to the instructor package and utils, and a new optional dependency.

Key points:

  • Added IBM Watson AI support in the instructor library.
  • Created a new example file watsonx.py in the examples/watsonx directory.
  • Updated instructor package to include Watson AI support if ibm_watsonx_ai is installed.
  • Added a new file client_watsonx.py in the instructor package, which contains the function from_watsonx.
  • Updated the Provider enum in utils.py to include WATSONX.
  • Updated pyproject.toml to include ibm-watsonx-ai as an optional dependency.
  • Created a new md file in docs.

Generated with ❤️ by ellipsis.dev

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Apr 21, 2024
@h0rv h0rv marked this pull request as draft April 21, 2024 23:03
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.

❌ Changes requested.

  • Reviewed the entire pull request up to 52131d0
  • Looked at 173 lines of code in 5 files
  • Took 1 minute and 20 seconds to review
More info
  • Skipped 1 files when reviewing.
  • Skipped posting 9 additional comments because they didn't meet confidence threshold of 85%.
1. examples/watsonx/watsonx.py:9:
  • Assessed confidence : 80%
  • Comment:
    Consider using a configuration file or a secrets manager to handle sensitive data like API keys instead of directly fetching them from environment variables.
  • Reasoning:
    The API key and project ID are being fetched from the environment variables directly in the code. This could be a potential security risk if the environment variables are not properly managed. It would be better to use a configuration file or a secrets manager to handle sensitive data like API keys.
2. examples/watsonx/watsonx.py:14:
  • Assessed confidence : 80%
  • Comment:
    Consider fetching the model_id from a configuration file or an environment variable instead of hardcoding it.
  • Reasoning:
    The Watsonx client is being instantiated with a hardcoded model_id. This could limit the flexibility of the code. It would be better to fetch the model_id from a configuration file or an environment variable.
3. examples/watsonx/watsonx.py:18:
  • Assessed confidence : 80%
  • Comment:
    Consider fetching the parameters from a configuration file or an environment variable instead of hardcoding them.
  • Reasoning:
    The Watsonx client is being instantiated with hardcoded parameters. This could limit the flexibility of the code. It would be better to fetch these parameters from a configuration file or an environment variable.
4. instructor/__init__.py:70:
  • Assessed confidence : 80%
  • Comment:
    Consider handling the import failure and providing a clear error message.
  • Reasoning:
    The Watsonx client is being imported conditionally. This could lead to potential issues if the import fails. It would be better to handle the import failure and provide a clear error message.
5. instructor/utils.py:28:
  • Assessed confidence : 0%
  • Comment:
    Good practice of adding Watsonx to the Provider enum for easy addition of new providers in the future.
  • Reasoning:
    The Watsonx provider is being added to the Provider enum. This is a good practice as it allows for easy addition of new providers in the future.
6. instructor/utils.py:47:
  • Assessed confidence : 0%
  • Comment:
    Good practice of identifying the Watsonx provider based on the base_url.
  • Reasoning:
    The Watsonx provider is being identified based on the base_url. This is a good practice as it allows for easy identification of the provider.
7. pyproject.toml:35:
  • Assessed confidence : 0%
  • Comment:
    Good practice of adding Watsonx dependency to the poetry configuration file for easy management of dependencies.
  • Reasoning:
    The Watsonx dependency is being added to the poetry configuration file. This is a good practice as it allows for easy management of dependencies.
8. instructor/client_watsonx.py:10:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    Consider having different signatures for overloaded functions to avoid confusion and potential bugs.
  • Reasoning:
    The from_watsonx function is overloaded but both versions have the same signature. This could lead to confusion and potential bugs. It would be better to have different signatures for overloaded functions.
9. instructor/client_watsonx.py:39:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    Consider implementing the missing functionality or providing a clear explanation of why it is not implemented.
  • Reasoning:
    The from_watsonx function has a TODO comment about adding Watsonx async. This indicates that the function is not fully implemented and could lead to potential issues. It would be better to implement the missing functionality or provide a clear explanation of why it is not implemented.

Workflow ID: wflow_rIKCcN8i1GIEOnbo


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. We'll respond in a few minutes. Learn more here.

examples/watsonx/watsonx.py Outdated Show resolved Hide resolved
@jxnl jxnl changed the title add watsonx feat: add watsonx support Apr 21, 2024
instructor/client_watsonx.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@h0rv
Copy link
Contributor Author

h0rv commented Apr 22, 2024

Yeah I think the easiest approach for this is to add LiteLLM support.

@mattzcarey
Copy link

Would be keen on the LiteLLM support. Then people who use Amazon Bedrock can get involved.

@h0rv
Copy link
Contributor Author

h0rv commented Apr 23, 2024

LiteLLM PR draft

@h0rv h0rv force-pushed the add-watsonx branch 3 times, most recently from 72d1921 to 8853244 Compare April 27, 2024 15:26
@h0rv h0rv marked this pull request as ready for review April 27, 2024 15:31
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 27, 2024
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 the entire pull request up to 8853244
  • Looked at 137 lines of code in 3 files
  • Took 46 seconds to review
More info
  • Skipped 1 files when reviewing.
  • Skipped posting 1 additional comments because they didn't meet confidence threshold of 85%.
1. pyproject.toml:80:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The PR description mentions adding ibm-watsonx-ai as an optional dependency, but it is not present in the pyproject.toml. Please add it to ensure the new functionality works as expected.
ibm-watsonx-ai = { version = "^0.1.0", optional = true }
  • Reasoning:
    The PR description mentions that ibm-watsonx-ai is added as an optional dependency in pyproject.toml, but the diff does not show this change. This could be an oversight or an error in updating the file. It's crucial for the functionality described in the PR to work, as the new client_watsonx.py likely depends on this package.

Workflow ID: wflow_Tom4hYW1GX5PGwfP


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

@h0rv
Copy link
Contributor Author

h0rv commented Apr 27, 2024

LiteLLM support has been added, so I updated the docs to show how to use watsonx with via LiteLLM, so no new code changes.

Should I create a from_watsonx still and wrap that functionality for ease of use, or would that be redundant? If not, its ready for review!

Copy link

hyperlint-ai bot commented Apr 27, 2024

It sounds like you have made updates to the documentation to include information on how to use WatsonX with LiteLLM. Since there are no new code changes, we can focus on reviewing the existing code and documentation.

I can assist with various types of reviews on this pull request, such as:

  • Readability
  • Content
  • SEO
  • Vale

If you would like, I can review specific files or sections based on your preference. Just let me know which type of review you would like to prioritize or if you have any specific files in mind for review.

Regarding the decision to create a from_watsonx function for ease of use, I recommend considering the necessity and potential benefits it would bring to the users. If you believe it would enhance the usability and clarity of the code, it might be worth implementing. However, if it would be redundant or unnecessary, it could be omitted.

Please let me know your preferences for the review or if you have any specific files you would like me to focus on.

@h0rv
Copy link
Contributor Author

h0rv commented Apr 27, 2024

Was waiting to test since my watsonx API key is on my work computer, but just tried it. I just updated LiteLLM to latest but it is still not out but it is on the docs. Likely will go out today so will bump the version when that happens

Copy link

hyperlint-ai bot commented Apr 27, 2024

Understood! It's great that you were able to test the WatsonX API key and that you have updated LiteLLM to the latest version. Since LiteLLM is not yet released but the documentation reflects the upcoming changes, it's a good idea to bump the version once LiteLLM is officially out.

If you need any assistance with updating the version or any other related tasks once LiteLLM is released, feel free to let me know. Additionally, if you would like to proceed with a review of the pull request before the version bump, just give me the go-ahead, and I can start the review process.

Feel free to reach out if you have any further questions or need assistance with anything else!

h0rv added 4 commits April 28, 2024 10:30
add files and start implementation

x

x

Revert "add/update dependencies"

This reverts commit 9787dd4.
Add example

Revert "add/update dependencies"

This reverts commit 9787dd4.

fix: bullet list in README.md (instructor-ai#621)

fix: Update README.md (instructor-ai#625)

fix typo about Enum 'and' → 'an' (instructor-ai#626)

Fix anthropic usage and tools (instructor-ai#622)

Revert init changes
@h0rv
Copy link
Contributor Author

h0rv commented Apr 28, 2024

Updated LiteLLM - examples tested and working

Copy link

Choose a reason for hiding this comment

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

Review of the Content

👈(click to expand)

We classified this document as a tutorial and reviewed it accordingly. We rate this content quality as a 6/10.
To improve the writing quality to 8 or better, the document should focus on enhancing clarity and conciseness. Sentences should be restructured to use active voice consistently and ensure that technical terms are clearly defined. Additionally, the document should provide a smoother transition between sections to enhance the flow and coherence of the content.

Overall outline and structure feedback

In Structured Outputs with IBM watsonx.ai (medium Severity)

The title could be more descriptive and engaging. Try replacing it with Implementing Structured Outputs with IBM Watsonx.ai.

In watsonx.ai (medium Severity)

The heading is too generic and does not reflect the content beneath it. Try replacing it with Setting Up Your Watsonx.ai Credentials.

In Example (medium Severity)

The heading could be more specific to reflect the content of the code example. Try replacing it with Python Example: Using Watsonx.ai for Model Inference.

with respect to the content

In the section watsonx.ai, we identified 2 issues.
  • Unclear sentence structure (medium Severity) Clarify the sentence to specify where or how to obtain these credentials.
- You will need an API key and the project ID for your watsonx.ai. 
+ To use watsonx.ai, you will need an API key and a project ID, which can be obtained from your account settings on the IBM Watsonx website.
  • Missing context or link (medium Severity) Provide a brief description of what information can be found at the link.
- More information at <https://www.ibm.com/products/watsonx-ai>. 
+ For more detailed information about watsonx.ai features and setup, visit the IBM product page at <https://www.ibm.com/products/watsonx-ai>.
In the section Example, we identified 2 issues.
  • Unclear code comments (medium Severity) Explain why this setting is necessary in the context of the example.
- litellm.drop_params = True  # watsonx.ai doesn't support `json_mode` 
+ litellm.drop_params = True  # Set to True because watsonx.ai does not support `json_mode`, which affects how parameters are handled.
  • Grammatical error (medium Severity) Correct the grammatical structure in the comment.
- assert resp.name == "IBM" 
+ assert resp.name == "IBM"  # Ensure the 'name' attribute of the response is 'IBM'

Copy link

hyperlint-ai bot commented Apr 28, 2024

Review of the Content in docs/examples/watsonx.md

Overall Feedback:

We classified the document as a tutorial and rated the content quality as 6/10. To enhance the quality to 8 or better, focus on improving clarity, conciseness, and the use of active voice. Ensure technical terms are clearly defined and provide a smoother transition between sections for better coherence.

Specific Feedback:

  1. Structured Outputs with IBM watsonx.ai:

    • Consider making the title more descriptive and engaging, such as Implementing Structured Outputs with IBM Watsonx.ai.
  2. watsonx.ai:

    • The heading could be more specific, like Setting Up Your Watsonx.ai Credentials.
  3. Example:

    • The heading could be more specific to reflect the content of the code example, like Python Example: Using Watsonx.ai for Model Inference.

Content Issues:

  1. watsonx.ai Section:

    • Clarify the sentence structure to specify obtaining API key and project ID.
    • Provide context or a brief description for the link to IBM product page.
  2. Example Section:

    • Explain the necessity of the code setting in the context of the example.
    • Correct a grammatical error in the code comment.

Based on the content review of docs/examples/watsonx.md, there are some areas that can be improved for better clarity and coherence. Consider addressing the highlighted issues to enhance the overall quality of the document.

If you would like further assistance with revising the content or have any specific areas you would like to focus on, feel free to let me know. Once the necessary adjustments are made, the document will be in better shape for users.

Let me know how you would like to proceed or if you need any additional support!

messages=[
{
"role": "user",
"content": task,
Copy link
Collaborator

Choose a reason for hiding this comment

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

just set the string here no need to add indirection for no reason

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

docs/examples/watsonx.md Outdated Show resolved Hide resolved
@h0rv
Copy link
Contributor Author

h0rv commented Apr 28, 2024

Made those fixes

Copy link

hyperlint-ai bot commented Apr 28, 2024

Great job on making those fixes! It's important to ensure that the content is clear and accurate for users.

Since you have addressed the highlighted issues in the docs/examples/watsonx.md file, the document should now provide a better experience for readers.

If you would like, I can perform another content review to verify the changes and ensure that everything is in order. Just let me know if you would like to proceed with another review or if there are any specific areas you would like me to focus on.

Feel free to provide further instructions or requests for assistance!

@jxnl jxnl merged commit 5b453ee into instructor-ai:main Apr 29, 2024
@h0rv h0rv deleted the add-watsonx branch April 29, 2024 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants