Skip to content

Commit d438177

Browse files
committed
feat(lab-3584): remove legacy plugin handlers
1 parent 8a9168f commit d438177

File tree

12 files changed

+130
-343
lines changed

12 files changed

+130
-343
lines changed

docs/sdk/tutorials/plugins_example.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,33 @@ class PluginHandler(PluginCore):
125125
Custom plugin instance
126126
"""
127127

128-
def on_submit(self, label: Dict, asset_id: str) -> None:
128+
def on_event(self, payload: dict) -> None:
129129
"""
130130
Dedicated handler for Submit action
131131
"""
132-
self.logger.info("On submit called")
132+
event = payload.get("event")
133133

134-
issues_array = check_rules_on_label(label)
134+
if event == 'labels.created.submit':
135+
label = payload["label"]
136+
asset_id = label["assetId"]
137+
self.logger.info("On submit called")
135138

136-
project_id = self.project_id
139+
issues_array = check_rules_on_label(label)
137140

138-
if len(issues_array) > 0:
139-
print("Creating an issue...")
141+
project_id = self.project_id
140142

141-
self.kili.create_issues(
142-
project_id=project_id,
143-
label_id_array=[label['id']] * len(issues_array),
144-
text_array=issues_array,
145-
)
143+
if len(issues_array) > 0:
144+
print("Creating an issue...")
146145

147-
print("Issue created!")
146+
self.kili.create_issues(
147+
project_id=project_id,
148+
label_id_array=[label['id']] * len(issues_array),
149+
text_array=issues_array,
150+
)
148151

149-
self.kili.send_back_to_queue(asset_ids=[asset_id])
152+
print("Issue created!")
153+
154+
self.kili.send_back_to_queue(asset_ids=[asset_id])
150155

151156
```
152157

@@ -208,7 +213,7 @@ plugin_name = "Plugin bbox count"
208213
from kili.exceptions import GraphQLError
209214

210215
try:
211-
kili.upload_plugin(plugin_folder, plugin_name)
216+
kili.upload_plugin(plugin_folder, plugin_name, event_matcher=["labels.created.submit"])
212217
except GraphQLError as error:
213218
print(str(error))
214219
```
@@ -231,7 +236,9 @@ path_to_plugin = Path(plugin_folder) / "main.py"
231236
plugin_name_file = "Plugin bbox count - file"
232237

233238
try:
234-
kili.upload_plugin(str(path_to_plugin), plugin_name_file)
239+
kili.upload_plugin(
240+
str(path_to_plugin), plugin_name_file, event_matcher=["labels.created.submit"]
241+
)
235242
except GraphQLError as error:
236243
print(str(error))
237244
```

docs/sdk/tutorials/plugins_library.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Let's imagine a project where we want to process images and detect some objects.
2727
Let's imagine another project where we process invoices. The project has two jobs and several transcription tasks associated with them. One of the jobs is about payment information and must contain a proper IBAN number as well as currency. The IBAN must start with FR, and the currency should be one of: *EURO* or *DOLLAR*. Kili's interface customization options are powerful and flexible, but won't help us in this specific situation so we have to turn to Kili plugins for help. We'll set up our Kili plugin to check these two rules when labelers click *Submit*. If the annotations don't match our predefined rules, our QA bot will add issues to the asset and send the asset back to the labeling queue. At the end, our script will calculate labeling accuracy and insert the accuracy metric in the json_metadata of the asset. All that with no need to engage a human reviewer.
2828

2929
- Plugin file: [`plugin_document.py`](https://github.com/kili-technology/kili-python-sdk/blob/main/recipes/plugins_library/plugin_document.py){target=_blank}
30-
- End-to-end notebook showcasing this example: [`plugins_example_document.ipynb`](https://github.com/kili-technology/kili-python-sdk/blob/main/recipes/plugins_example_document.ipynb){target=_blank}
3130

3231
### 2. Consensus resolution
3332

recipes/plugins_example.ipynb

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -205,28 +205,33 @@
205205
" Custom plugin instance\n",
206206
" \"\"\"\n",
207207
"\n",
208-
" def on_submit(self, label: Dict, asset_id: str) -> None:\n",
208+
" def on_event(self, payload: dict) -> None:\n",
209209
" \"\"\"\n",
210210
" Dedicated handler for Submit action \n",
211211
" \"\"\"\n",
212-
" self.logger.info(\"On submit called\")\n",
212+
" event = payload.get(\"event\")\n",
213213
"\n",
214-
" issues_array = check_rules_on_label(label)\n",
214+
" if event == 'labels.created.submit':\n",
215+
" label = payload[\"label\"]\n",
216+
" asset_id = label[\"assetId\"]\n",
217+
" self.logger.info(\"On submit called\")\n",
215218
"\n",
216-
" project_id = self.project_id\n",
219+
" issues_array = check_rules_on_label(label)\n",
217220
"\n",
218-
" if len(issues_array) > 0:\n",
219-
" print(\"Creating an issue...\")\n",
221+
" project_id = self.project_id\n",
220222
"\n",
221-
" self.kili.create_issues(\n",
222-
" project_id=project_id,\n",
223-
" label_id_array=[label['id']] * len(issues_array),\n",
224-
" text_array=issues_array,\n",
225-
" )\n",
223+
" if len(issues_array) > 0:\n",
224+
" print(\"Creating an issue...\")\n",
226225
"\n",
227-
" print(\"Issue created!\")\n",
226+
" self.kili.create_issues(\n",
227+
" project_id=project_id,\n",
228+
" label_id_array=[label['id']] * len(issues_array),\n",
229+
" text_array=issues_array,\n",
230+
" )\n",
228231
"\n",
229-
" self.kili.send_back_to_queue(asset_ids=[asset_id])\n",
232+
" print(\"Issue created!\")\n",
233+
"\n",
234+
" self.kili.send_back_to_queue(asset_ids=[asset_id])\n",
230235
"\n",
231236
"```"
232237
]
@@ -319,7 +324,7 @@
319324
"from kili.exceptions import GraphQLError\n",
320325
"\n",
321326
"try:\n",
322-
" kili.upload_plugin(plugin_folder, plugin_name)\n",
327+
" kili.upload_plugin(plugin_folder, plugin_name, event_matcher=[\"labels.created.submit\"])\n",
323328
"except GraphQLError as error:\n",
324329
" print(str(error))"
325330
]
@@ -359,7 +364,9 @@
359364
"plugin_name_file = \"Plugin bbox count - file\"\n",
360365
"\n",
361366
"try:\n",
362-
" kili.upload_plugin(str(path_to_plugin), plugin_name_file)\n",
367+
" kili.upload_plugin(\n",
368+
" str(path_to_plugin), plugin_name_file, event_matcher=[\"labels.created.submit\"]\n",
369+
" )\n",
363370
"except GraphQLError as error:\n",
364371
" print(str(error))"
365372
]

0 commit comments

Comments
 (0)