Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions docs/sdk/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ plugin_folder
|__ helper.py
```

The plugin you are going to upload has to contain a `class PluginHandler(PluginCore)` (in the case of the module type plugin it has to be inside `main.py`) that implements two methods for the different types of events:

- `on_submit`
- `on_review`
> **Note**: `on_submit` and `on_review` handlers are deprecated. Please use `on_event` instead. If your plugin was already uploaded with thoses handlers, it will still work. If you want the same behavior as `on_submit` and `on_review`, when you upload your plugin, you can use `event_matcher=["labels.created.submit"]` for `on_submit` and `event_matcher=["labels.created.review"]` for `on_review` events.

These methods have a predefined set of parameters:

- the `label` submitted (a dictionary containing the fields of the GraphQL type [Label](https://api-docs.kili-technology.com/types/objects/label/))
- the `asset_id` of the asset labeled
The plugin you are going to upload has to contain a `class PluginHandler(PluginCore)` (in the case of the module type plugin it has to be inside `main.py`) that implements one method for the different types of events:

- `on_event`

These methods have a predefined set of parameter:

- the `payload` submitted (a dictionary containing the fields for your plugins)
- `payload.event` the name of the event (ex: for submit : `labels.created.submit`, for review `labels.created.review`)
- `payload.label` the label containing the fields of the GraphQL type [Label](https://api-docs.kili-technology.com/types/objects/label/)

You can add custom methods in your class as well.

Expand All @@ -53,12 +57,18 @@ class PluginHandler(PluginCore):
def custom_method(self):
# Do something...

def on_review(self, label: Dict, asset_id: str) -> None:
def on_event(self, payload: dict) -> None: # This can replace on_review method
"""Dedicated handler for Review action"""
event = payload.get("event")

if event == 'labels.created.review':
# Do something...

def on_submit(self, label: Dict, asset_id: str) -> None:
def on_event(self, payload: dict) -> None: # This can replace on_submit method
"""Dedicated handler for Submit action"""
event = payload.get("event")

if event == 'labels.created.submit':
# Do something...
```

Expand All @@ -85,15 +95,22 @@ def custom_function(label: Dict, logger: Logger):
class PluginHandler(PluginCore):
"""Custom plugin"""

def on_submit(self, label: Dict, asset_id: str) -> None:
def on_event(self, payload: dict) -> None:
"""Dedicated handler for Submit action"""
self.logger.info("On Submit called")
custom_function(label, self.logger)
event = payload.get("event")
if event == 'labels.created.submit':
self.logger.info("On Submit called")
label = payload["label"]
custom_function(label, self.logger)
```

## Model for Plugins

::: kili.services.plugins.model.PluginCore
options:
filters:
- "!^on_review$"
- "!^on_submit$"

## Queries

Expand Down
281 changes: 0 additions & 281 deletions docs/sdk/tutorials/plugins_development.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/sdk/tutorials/plugins_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ This project has one job of bounding box creation with two categories.

With our plugin, we want to make sure that the labelers don't create more than one bounding box of category A.

To iterate on the plugin code, you can refer to the plugins_development.ipynb notebook.

## Step 3: Write the plugin

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/tutorials/plugins_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

In this section you can find multiple examples of use-cases where our system of plugins can help you in the Kili projects.

You can also refer to our [tutorial](./plugins_development.md) to develop your plugin and iterate on it locally, before uploading the final version to Kili.
You can also refer to our [tutorial](./plugins_example.md) to develop your plugin and iterate on it locally, before uploading the final version to Kili.

For further information concerning the Kili plugins, refer to the [Reference page](../plugins.md)

Expand Down
5 changes: 2 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ nav:
- PDF Assets: sdk/tutorials/importing_pdf_assets.md
- Rich Text Assets: sdk/tutorials/import_text_assets.md
- Multi-Layer Geospatial Assets: sdk/tutorials/importing_multilayer_geospatial_assets.md
- LLM Static Assets : sdk/tutorials/llm_static.md
- LLM Static Assets: sdk/tutorials/llm_static.md
- Importing Labels:
- Importing Labels: sdk/tutorials/importing_labels.md
- OpenAI NER Pre-annotations: sdk/tutorials/ner_pre_annotations_openai.md
Expand All @@ -64,8 +64,7 @@ nav:
- Parsing Labels: sdk/tutorials/label_parsing.md
- LLM Dynamic Projects: sdk/tutorials/llm_dynamic.md
- Setting Up Plugins:
- Developing Plugins: sdk/tutorials/plugins_development.md
- Plugin Example - Programmatic QA: sdk/tutorials/plugins_example.md
- Developing Plugins: sdk/tutorials/plugins_example.md
- Plugins Library: sdk/tutorials/plugins_library.md
- Webhooks: sdk/tutorials/webhooks_example.md
- Integrations:
Expand Down
Loading