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 Webhook expanded events #5480

Merged

Conversation

jfcalvo
Copy link
Member

@jfcalvo jfcalvo commented Sep 11, 2024

Description

This is a PR exploring the possibility of expanding associated resources on webhook event messages.

The following changes has been added:

  • Add webhook event schemas for the following resources:
    • Response
    • Record
    • Dataset
    • Workspace
    • User
  • Webhook events associated to deletion of resources are sending now a simple {"id": "id-of-the-deleted-resource"} to avoid problems with missing resources deleted on cascade.
  • The model associations are loaded using awaitable_attrs to avoid replacing the original resource instance (and avoid a database refresh that could cause losing the state of the resource).

This is an example of a response.created event with the changes:

{
  "type": "response.created",
  "version": 1,
  "timestamp": "2024-09-12T11:52:15.083612Z",
  "data": {
    "id": "053a845a-02fd-4951-9884-2317a4a2be19",
    "values": {
      "int_score": {
        "value": 3
      }
    },
    "status": "submitted",
    "record": {
      "id": "60eadd2c-76ed-4216-870e-9d361ac0a894",
      "status": "pending",
      "fields": {
        "text": "a combination of one or more elementary reaction steps which start with the appropriate reactants and end with the appropriate product(s)\na description of the path, or sequence of steps, by which a reaction occurs\na description of the path that a reaction takes\na detailed description of how a chemical reaction occurs\na detailed description of the way a reaction occurs and is based on the known experimental data about the reaction\na detailed (theoretical) description of how we think the chemical reaction proceeds\na series of elementary reactions or elementary steps that lead from reactants to products\na set of steps at the molecular level\na step by step description of the separate steps that occur during a chemical reaction\na stepwise description of the reaction path\nmechanism. A list of all elementary reactions that occur in the course of an overall chemical reaction.\nIn chemistry, a reaction mechanism is the step by step sequence of elementary reactions by which overall chemical change occurs."
      },
      "metadata": {
        "dump": "CC-MAIN-2013-20",
        "url": "http://www.metaglossary.com/meanings/3337605/",
        "language": "en",
        "language_score": 0.9414262175559998,
        "token_count": 195,
        "score": 3.671875
      },
      "external_id": "<urn:uuid:7ae3a60b-341f-4a49-8f9d-b5b4588f2f8d>",
      "dataset": {
        "id": "408239b6-d100-4eff-b5d9-afcc8e99b9f1",
        "name": "fineweb-edu-min-submitted-big",
        "guidelines": null,
        "allow_extra_metadata": false,
        "status": "ready",
        "distribution": {
          "strategy": "overlap",
          "min_submitted": 1
        },
        "workspace": {
          "id": "350bc020-2cd2-4a67-8b23-37a15c4d8139",
          "name": "argilla",
          "inserted_at": "2024-09-05T11:39:20.377192",
          "updated_at": "2024-09-05T11:39:20.377192"
        },
        "questions": [
          {
            "id": "f6453e3a-5ed2-4853-a8c4-913d03bc1dfb",
            "name": "int_score",
            "title": "Rate the quality of the text",
            "description": null,
            "required": true,
            "settings": {
              "type": "rating",
              "options": [
                {
                  "value": 0
                },
                {
                  "value": 1
                },
                {
                  "value": 2
                },
                {
                  "value": 3
                },
                {
                  "value": 4
                },
                {
                  "value": 5
                }
              ]
            },
            "inserted_at": "2024-09-06T10:21:25.482006",
            "updated_at": "2024-09-06T10:21:25.482006"
          },
          {
            "id": "4d0b53e6-9b96-42da-a863-2c17d483be01",
            "name": "comments",
            "title": "Comments:",
            "description": null,
            "required": false,
            "settings": {
              "type": "text",
              "use_markdown": false
            },
            "inserted_at": "2024-09-06T10:21:25.493565",
            "updated_at": "2024-09-06T10:21:25.493565"
          }
        ],
        "fields": [
          {
            "id": "02ef122a-d989-4422-89ad-e29096a1acfd",
            "name": "text",
            "title": "text",
            "required": true,
            "settings": {
              "type": "text",
              "use_markdown": false
            },
            "inserted_at": "2024-09-06T10:21:25.468310",
            "updated_at": "2024-09-06T10:21:25.468310"
          }
        ],
        "metadata_properties": [
          {
            "id": "c79d1808-7551-4fb8-b673-b5bb0bec0532",
            "name": "dump",
            "title": "dump",
            "settings": {
              "type": "terms",
              "values": null
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.506303",
            "updated_at": "2024-09-06T10:21:25.506303"
          },
          {
            "id": "1195fc9b-0974-498f-8cff-6feddfd6e9a1",
            "name": "url",
            "title": "url",
            "settings": {
              "type": "terms",
              "values": null
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.516085",
            "updated_at": "2024-09-06T10:21:25.516085"
          },
          {
            "id": "28cc925c-fed6-48bf-a1df-ef43e884b33b",
            "name": "language",
            "title": "language",
            "settings": {
              "type": "terms",
              "values": null
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.523871",
            "updated_at": "2024-09-06T10:21:25.523871"
          },
          {
            "id": "9333a2c9-efaf-4b0e-88e7-b1ed24dfcbfa",
            "name": "language_score",
            "title": "language_score",
            "settings": {
              "min": null,
              "max": null,
              "type": "float"
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.532447",
            "updated_at": "2024-09-06T10:21:25.532447"
          },
          {
            "id": "9d56b399-3c53-4e98-9d4a-ebfb360ec293",
            "name": "token_count",
            "title": "token_count",
            "settings": {
              "min": null,
              "max": null,
              "type": "integer"
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.539531",
            "updated_at": "2024-09-06T10:21:25.539531"
          },
          {
            "id": "6c701f7b-de47-4224-b9b0-3629133282ed",
            "name": "score",
            "title": "score",
            "settings": {
              "min": null,
              "max": null,
              "type": "float"
            },
            "visible_for_annotators": true,
            "inserted_at": "2024-09-06T10:21:25.546505",
            "updated_at": "2024-09-06T10:21:25.546505"
          }
        ],
        "vectors_settings": [],
        "last_activity_at": "2024-09-12T11:52:15.030317",
        "inserted_at": "2024-09-06T10:21:25.443578",
        "updated_at": "2024-09-12T11:52:04.923388"
      },
      "inserted_at": "2024-09-06T10:21:27.790000",
      "updated_at": "2024-09-06T10:21:27.790000"
    },
    "user": {
      "id": "df114042-958d-42c6-9f03-ab49bd451c6c",
      "first_name": "",
      "last_name": null,
      "username": "argilla",
      "role": "owner",
      "inserted_at": "2024-09-05T11:39:20.376463",
      "updated_at": "2024-09-05T11:39:20.376463"
    },
    "inserted_at": "2024-09-12T11:52:15.029023",
    "updated_at": "2024-09-12T11:52:15.029023"
  }
}

There are still missing changes and solutions to explore:

  • Review some associations that we can still add to the events.
  • Review if some missing endpoints are necessary.
  • Should we truncate record field values that are too large?
    • For example truncate image field values. Something like afdsmk432mkfseiwer...(truncated)
  • Update CHANGELOG if necessary.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested

  • Manually test the new events on HF spaces.

Checklist

  • I added relevant documentation
  • I followed the style guidelines of this project
  • I did a self-review of my code
  • I made corresponding changes to the documentation
  • I confirm My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/)

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.34%. Comparing base (70a9b2e) to head (443d563).
Report is 1 commits behind head on feat/add-webhooks-feature-branch.

Additional details and impacted files
@@                         Coverage Diff                          @@
##           feat/add-webhooks-feature-branch    #5480      +/-   ##
====================================================================
+ Coverage                             91.18%   91.34%   +0.15%     
====================================================================
  Files                                   155      156       +1     
  Lines                                  6160     6273     +113     
====================================================================
+ Hits                                   5617     5730     +113     
  Misses                                  543      543              
Flag Coverage Δ
argilla-server 91.34% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jfcalvo jfcalvo merged commit a55e884 into feat/add-webhooks-feature-branch Sep 16, 2024
6 checks passed
@jfcalvo jfcalvo deleted the feat/add-webhook-expanded-events branch September 16, 2024 07:51
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.

2 participants