zenml icon indicating copy to clipboard operation
zenml copied to clipboard

Update Argilla integration for v2.x SDK

Open sdiazlor opened this issue 1 year ago • 7 comments

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:

  • [x] I have read the CONTRIBUTING.md document.
  • [x] If my change requires a change to docs, I have updated the documentation accordingly.
  • [ ] I have added tests to cover my changes.
  • [x] 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)
  • [x] 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.

sdiazlor avatar Aug 07 '24 19:08 sdiazlor

[!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

🐰 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.

coderabbitai[bot] avatar Aug 07 '24 19:08 coderabbitai[bot]

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()
    

sdiazlor avatar Aug 07 '24 19:08 sdiazlor

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

strickvl avatar Aug 08 '24 04:08 strickvl

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

sdiazlor avatar Aug 08 '24 07:08 sdiazlor

@coderabbitai review

strickvl avatar Aug 09 '24 07:08 strickvl

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.

coderabbitai[bot] avatar Aug 09 '24 07:08 coderabbitai[bot]

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

strickvl avatar Aug 09 '24 07:08 strickvl

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

AlexejPenner avatar Oct 24 '24 11:10 AlexejPenner