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

Update Argilla integration for v2.x SDK #2915

Merged
merged 23 commits into from
Oct 24, 2024

Conversation

sdiazlor
Copy link
Contributor

@sdiazlor sdiazlor commented Aug 7, 2024

Describe changes

I updated the Argilla integration with the new version Argilla 2.0.

NOTES:

  • I kept the convention using keyword arguments, but let me know if you prefer to specify the type hinting clearly.
  • I didn't find tests for annotator integrations. I can add some. In a comment, I leave some basic workflow of how to use it.

cc @strickvl

Pre-requisites

Please ensure you have done the following:

  • I have read the CONTRIBUTING.md document.
  • If my change requires a change to docs, I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have based my new branch on develop and the open PR is targeting develop. If your branch wasn't based on develop read Contribution guide on rebasing branch to develop.
  • If my changes require changes to the dashboard, these changes are communicated/requested.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Other (add details above)

Summary by CodeRabbit

  • Documentation Updates

    • Enhanced clarity in the documentation for available annotators and the Argilla tool.
    • Improved deployment instructions and updated the Argilla quickstart guide link.
    • Modifications to the Argilla settings for better usability, including port defaults and header naming.
  • New Features

    • Added workspace-specific operations for Argilla annotation integration.
    • Introduced error handling and logging improvements during operations.
  • Dependency Updates

    • Increased version requirement for the argilla package to >=2.0.0.

Copy link
Contributor

coderabbitai bot commented Aug 7, 2024

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The recent changes enhance the documentation and functionality of the ZenML framework, particularly around the Argilla integration. Documentation has been clarified to better represent tools and their usage, while code updates improve exception handling, workspace management, and usability. Key modifications include upgrading the Argilla package requirement and refining methods to support workspace-specific operations, streamlining dataset management, and improving user interaction with new client features.

Changes

Files Change Summary
docs/book/component-guide/annotators/*.md Documentation updates for annotators, enhancing clarity around integrations and Argilla usage, including improved deployment details.
docs/mocked_libs.json Removed specific Argilla SDK modules and added an exceptions API module, suggesting a restructuring of the library’s focus.
src/zenml/integrations/argilla/__init__.py Updated Argilla version requirement from <2 to >=2.0.0, indicating a major dependency change.
src/zenml/integrations/argilla/annotators/*.py Significant updates to support workspace-specific operations, improved error handling, and new methods for dataset management.
src/zenml/integrations/argilla/flavors/*.py Modifications to settings attributes, including renaming and default values, indicating a shift in workspace handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ArgillaAnnotator
    participant ArgillaAPI

    User->>ArgillaAnnotator: Launch Annotation Interface
    ArgillaAnnotator->>ArgillaAPI: Initialize Client
    ArgillaAnnotator->>ArgillaAPI: Get Datasets (with workspace)
    ArgillaAPI-->>ArgillaAnnotator: Return Datasets
    ArgillaAnnotator->>User: Display Datasets
Loading

🐰 In fields of green, I hop with glee,
New changes bloom, just wait and see!
With tools in hand and workspaces bright,
Data dances in the moonlight.
Let’s celebrate the joy we find,
With each update, we’re one of a kind! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sdiazlor
Copy link
Contributor Author

sdiazlor commented Aug 7, 2024

from typing import List

import argilla as rg
from zenml import step, pipeline
from zenml.client import Client
from zenml.logger import get_logger

logger = get_logger(__name__)


@step
def get_data() -> List[str]:
    """Random text data for annotation."""
    texts = [
        "The quick brown fox jumps over the lazy dog.",
        "ZenML is an extensible, open-source MLOps framework.",
        "Argilla helps in managing and annotating data.",
        "Machine learning models require good quality data.",
        "Annotation tools are essential for supervised learning.",
    ]
    
    return texts


@step
def upload_to_argilla(
    texts: List[str],
    dataset_name: str = "default_dataset",
):
    """Creates a dataset and loads the data to Argilla.

    Args:
        texts: List of text data.
        dataset_name: Name of the dataset in Argilla.
    """
    
    annotator = Client().active_stack.annotator
    
    from zenml.integrations.argilla.annotators.argilla_annotator import (
        ArgillaAnnotator,
    )

    if not isinstance(annotator, ArgillaAnnotator):
        raise TypeError(
            "This step can only be used with the Argilla annotator."
        )
    
    argilla = annotator._get_client()
    

    # Create or get the dataset in Argilla
    try:
        dataset = annotator.get_dataset(dataset_name=dataset_name)
        if dataset is None:
            settings = rg.Settings(
                guidelines="These are some guidelines.",
                fields=[
                    rg.TextField(
                        name="text",
                    ),
                ],
                questions=[
                    rg.LabelQuestion(
                        name="label",
                        labels=["label_1", "label_2", "label_3"]
                    ),
                ],
                metadata=[
                    rg.TermsMetadataProperty(
                        name="terms",
                        title="Annotation groups",
                    ),
                ],
            )
            dataset = annotator.add_dataset(dataset_name=dataset_name, settings=settings)

            records = [
                rg.Record(
                    fields={"text": text}
                )
                for text in texts
            ]

            annotator.add_records(dataset_name=dataset_name, records=records)
    except Exception as e:
        logger.error(f"Error: {e}")
        raise e
    
    print(dataset)

@pipeline
def data_pipeline():
    data = get_data()
    upload_to_argilla(data)


if __name__ == "__main__":
    data_pipeline()
    

@strickvl strickvl self-requested a review August 7, 2024 19:12
@strickvl strickvl added the enhancement New feature or request label Aug 7, 2024
Copy link
Contributor

@strickvl strickvl left a comment

Choose a reason for hiding this comment

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

Two quick things now, but I'll take a more thorough look in the morning. Thank you so much for making the updates! I'll also test it out.

docs/book/component-guide/annotators/argilla.md Outdated Show resolved Hide resolved
docs/book/component-guide/annotators/argilla.md Outdated Show resolved Hide resolved
@strickvl strickvl changed the title Update integration argilla 2.0 Update Argilla integration for v2.x SDK Aug 7, 2024
@strickvl
Copy link
Contributor

strickvl commented Aug 8, 2024

Also a few errors from CI: https://github.com/zenml-io/zenml/actions/runs/10290280476/job/28480088504?pr=2915#step:6:41 @sdiazlor

@sdiazlor
Copy link
Contributor Author

sdiazlor commented Aug 8, 2024

@strickvl Thank you! They should be fixed, I had missed those.

@strickvl
Copy link
Contributor

strickvl commented Aug 9, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Aug 9, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
docs/book/component-guide/annotators/argilla.md (1)

63-63: Add missing comma for clarity.

A comma is needed after the headers parameter to improve readability.

- `headers` parameter which would include a Hugging Face token.
+ `headers` parameter, which would include a Hugging Face token.
Tools
LanguageTool

[uncategorized] ~63-~63: Possible missing comma found.
Context: ...rivate, you must also set the headers parameter which would include a Hugging Face toke...

(AI_HYDRA_LEO_MISSING_COMMA)

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6e40939 and b0f5ee1.

Files selected for processing (6)
  • docs/book/component-guide/annotators/annotators.md (1 hunks)
  • docs/book/component-guide/annotators/argilla.md (4 hunks)
  • docs/mocked_libs.json (1 hunks)
  • src/zenml/integrations/argilla/init.py (1 hunks)
  • src/zenml/integrations/argilla/annotators/argilla_annotator.py (3 hunks)
  • src/zenml/integrations/argilla/flavors/argilla_annotator_flavor.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • docs/book/component-guide/annotators/annotators.md
Additional context used
Path-based instructions (4)
src/zenml/integrations/argilla/__init__.py (1)

Pattern src/zenml/**/*.py: Review the Python code for conformity with Python best practices.

src/zenml/integrations/argilla/flavors/argilla_annotator_flavor.py (1)

Pattern src/zenml/**/*.py: Review the Python code for conformity with Python best practices.

docs/book/component-guide/annotators/argilla.md (1)

Pattern docs/**/*.md: Review the documentation for readability and clarity.

src/zenml/integrations/argilla/annotators/argilla_annotator.py (1)

Pattern src/zenml/**/*.py: Review the Python code for conformity with Python best practices.

LanguageTool
docs/book/component-guide/annotators/argilla.md

[uncategorized] ~63-~63: Possible missing comma found.
Context: ...rivate, you must also set the headers parameter which would include a Hugging Face toke...

(AI_HYDRA_LEO_MISSING_COMMA)

Additional comments not posted (15)
src/zenml/integrations/argilla/__init__.py (1)

29-29: Verify compatibility with Argilla v2.0.0.

The update to require argilla>=2.0.0 may introduce breaking changes. Ensure that the rest of the codebase is compatible with this new version.

src/zenml/integrations/argilla/flavors/argilla_annotator_flavor.py (1)

47-54: Ensure backward compatibility for renamed attributes.

The extra_headers attribute has been renamed to headers. Verify that this change does not break existing configurations and consider using a deprecation utility if necessary.

docs/mocked_libs.json (1)

229-229: LGTM!

The changes to the mocked libraries reflect a shift towards using a specific exceptions module, which aligns with the updated Argilla integration. This seems intentional and appropriate.

src/zenml/integrations/argilla/annotators/argilla_annotator.py (12)

109-124: LGTM!

The method correctly incorporates **kwargs for workspace-specific operations, enhancing flexibility.


127-145: LGTM!

The changes effectively support workspace-specific dataset retrieval, improving functionality.


147-168: LGTM!

The method correctly implements workspace-specific logic for retrieving dataset names, enhancing its capabilities.


170-195: LGTM!

The new method _get_data_by_status is well-implemented, providing clear functionality to filter records by status within a workspace context.


197-227: LGTM!

The refactoring to use _get_data_by_status enhances clarity and maintainability in computing dataset statistics.


230-244: LGTM!

The launch method is a valuable addition, providing a user-friendly way to access the annotation interface with proper error handling.


246-296: LGTM!

The method improvements, including requiring settings and supporting workspace creation, enhance functionality and robustness.


299-335: LGTM!

The method correctly incorporates workspace context for adding records, with appropriate logging and error handling.


336-366: LGTM!

The method enhancements for workspace-specific dataset retrieval improve flexibility and error handling.


370-397: LGTM!

The method improvements for workspace-specific dataset deletion enhance functionality and error handling.


398-421: LGTM!

The refactoring to use _get_data_by_status enhances clarity and maintainability in retrieving labeled data.


422-443: LGTM!

The refactoring to use _get_data_by_status enhances clarity and maintainability in retrieving unlabeled data.

@strickvl
Copy link
Contributor

strickvl commented Aug 9, 2024

@schustmi we'll have to look into conditionally ignoring / not installing argilla on our Python 3.8 instances on slow CI.

@strickvl strickvl requested a review from schustmi August 9, 2024 11:07
@AlexejPenner AlexejPenner mentioned this pull request Oct 23, 2024
9 tasks
@AlexejPenner
Copy link
Contributor

🦭 - thanks so much @sdiazlor for your contribution, i tested this in action an everything works as expected.

@AlexejPenner AlexejPenner dismissed strickvl’s stale review October 24, 2024 11:16

Reviews have been adressed

@AlexejPenner AlexejPenner merged commit 00ad240 into zenml-io:develop Oct 24, 2024
67 of 70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request run-slow-ci
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants