Skip to content

Commit 22a9103

Browse files
authored
Merge pull request #2020 from kili-technology/revert-2011-feature/lab-3584-aakd-i-see-onsubmit-and-onreview-handlers-removed-from
Revert "feat(lab-3584): remove legacy plugin handlers"
2 parents 733b024 + 4689d78 commit 22a9103

12 files changed

Lines changed: 343 additions & 130 deletions

File tree

docs/sdk/tutorials/plugins_example.md

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

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

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

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

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

143-
if len(issues_array) > 0:
144-
print("Creating an issue...")
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+
)
145146

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-
)
147+
print("Issue created!")
151148

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

156151
```
157152

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

215210
try:
216-
kili.upload_plugin(plugin_folder, plugin_name, event_matcher=["labels.created.submit"])
211+
kili.upload_plugin(plugin_folder, plugin_name)
217212
except GraphQLError as error:
218213
print(str(error))
219214
```
@@ -236,9 +231,7 @@ path_to_plugin = Path(plugin_folder) / "main.py"
236231
plugin_name_file = "Plugin bbox count - file"
237232

238233
try:
239-
kili.upload_plugin(
240-
str(path_to_plugin), plugin_name_file, event_matcher=["labels.created.submit"]
241-
)
234+
kili.upload_plugin(str(path_to_plugin), plugin_name_file)
242235
except GraphQLError as error:
243236
print(str(error))
244237
```

docs/sdk/tutorials/plugins_library.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ 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}
3031

3132
### 2. Consensus resolution
3233

recipes/plugins_example.ipynb

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -205,33 +205,28 @@
205205
" Custom plugin instance\n",
206206
" \"\"\"\n",
207207
"\n",
208-
" def on_event(self, payload: dict) -> None:\n",
208+
" def on_submit(self, label: Dict, asset_id: str) -> None:\n",
209209
" \"\"\"\n",
210210
" Dedicated handler for Submit action \n",
211211
" \"\"\"\n",
212-
" event = payload.get(\"event\")\n",
212+
" self.logger.info(\"On submit called\")\n",
213213
"\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",
214+
" issues_array = check_rules_on_label(label)\n",
218215
"\n",
219-
" issues_array = check_rules_on_label(label)\n",
216+
" project_id = self.project_id\n",
220217
"\n",
221-
" project_id = self.project_id\n",
218+
" if len(issues_array) > 0:\n",
219+
" print(\"Creating an issue...\")\n",
222220
"\n",
223-
" if len(issues_array) > 0:\n",
224-
" print(\"Creating an issue...\")\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",
225226
"\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",
227+
" print(\"Issue created!\")\n",
231228
"\n",
232-
" print(\"Issue created!\")\n",
233-
"\n",
234-
" self.kili.send_back_to_queue(asset_ids=[asset_id])\n",
229+
" self.kili.send_back_to_queue(asset_ids=[asset_id])\n",
235230
"\n",
236231
"```"
237232
]
@@ -324,7 +319,7 @@
324319
"from kili.exceptions import GraphQLError\n",
325320
"\n",
326321
"try:\n",
327-
" kili.upload_plugin(plugin_folder, plugin_name, event_matcher=[\"labels.created.submit\"])\n",
322+
" kili.upload_plugin(plugin_folder, plugin_name)\n",
328323
"except GraphQLError as error:\n",
329324
" print(str(error))"
330325
]
@@ -364,9 +359,7 @@
364359
"plugin_name_file = \"Plugin bbox count - file\"\n",
365360
"\n",
366361
"try:\n",
367-
" kili.upload_plugin(\n",
368-
" str(path_to_plugin), plugin_name_file, event_matcher=[\"labels.created.submit\"]\n",
369-
" )\n",
362+
" kili.upload_plugin(str(path_to_plugin), plugin_name_file)\n",
370363
"except GraphQLError as error:\n",
371364
" print(str(error))"
372365
]

0 commit comments

Comments
 (0)