Skip to content

Commit

Permalink
Integrated WorkerOpinion feature to TaskReview app; Added example of …
Browse files Browse the repository at this point in the history
…WorkerOpinion implementation
  • Loading branch information
meta-paul committed Jul 23, 2024
1 parent bcfcd00 commit 847647d
Show file tree
Hide file tree
Showing 46 changed files with 2,568 additions and 1,847 deletions.
48 changes: 47 additions & 1 deletion docs/web/docs/guides/how_to_use/review_app/server_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Assemble stats with results for a Task.

---

### `GET /api/tasks/{id}/charts`
### `GET /api/tasks/{id}/timeline`

Check if Grafana server is available and redirect or return error.

Expand All @@ -128,6 +128,51 @@ Check if Grafana server is available and redirect or return error.

---

### `GET /api/tasks/{id}/worker-opinions`

Returns all Worker Opinions related to a Task.

```
{
"task_name": <str>,
"worker_opinions": [
{
"data": {
"attachments": [
{
"destination": <str>,
"encoding": <str>,
"fieldname": <str>,
"filename": <str>,
"mimetype": <str>,
"originalname": <str>,
"path": <str>,
"size": <int>
},
... // more attachments
],
"questions": [
{
"answer": <str>,
"id": <str>,
"question": <str>,
"reviewed": <bool>,
"toxicity": <str> | null
},
... // more questions
]
},
"unit_data_folder": <str>,
"unit_id": <str>,
"worker_id": <str>
},
... // more worker opinions
]
}
```

---

### `GET /api/tasks/{id}/worker-units-ids`

Get full, unpaginated list of unit IDs within a task (for subsequent client-side grouping by worker_id and `GET /task-units` pagination)
Expand Down Expand Up @@ -264,6 +309,7 @@ Get full input for specified workers results (`units_ids` parameter is mandatory
"has_task_source_review": <bool>,
"id": <int>,
"inputs": <json object>, // instructions for worker
"metadata": <json object>, // any metadata (e.g. Worker Opinion)
"outputs": <json object>, // response from worker
"prepared_inputs": <json object>, // prepared instructions from worker
"unit_data_folder": <str>}, // path to data dir in file system
Expand Down
77 changes: 77 additions & 0 deletions examples/form_composer_demo/run_task_with_worker_opinion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python3

# Copyright (c) Meta Platforms and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import os

from omegaconf import DictConfig

from mephisto.operations.operator import Operator
from mephisto.tools.scripts import build_custom_bundle
from mephisto.tools.scripts import task_script


@task_script(default_config_file="example_local_mock")
def main(operator: Operator, cfg: DictConfig) -> None:
os.environ["REACT_APP__WITH_WORKER_OPINION"] = "true"

# Build packages
_build_custom_bundles(cfg)

operator.launch_task_run(cfg.mephisto)
operator.wait_for_runs_then_shutdown(skip_input=True, log_rate=30)


def _build_custom_bundles(cfg: DictConfig) -> None:
"""Locally build bundles that are not available on npm repository"""
mephisto_packages_dir = os.path.join(
# Root project directory
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
"packages",
)

# Build `mephisto-task-multipart` React package
build_custom_bundle(
mephisto_packages_dir,
force_rebuild=cfg.mephisto.task.force_rebuild,
webapp_name="mephisto-task-multipart",
build_command="build",
)

# Build `mephisto-task-addons` React package
build_custom_bundle(
mephisto_packages_dir,
force_rebuild=cfg.mephisto.task.force_rebuild,
webapp_name="mephisto-task-addons",
build_command="build",
)

# Build `react-form-composer` React package
build_custom_bundle(
mephisto_packages_dir,
force_rebuild=cfg.mephisto.task.force_rebuild,
webapp_name="react-form-composer",
build_command="build",
)

# Build Review UI for the application
build_custom_bundle(
cfg.task_dir,
force_rebuild=cfg.mephisto.task.force_rebuild,
webapp_name="webapp",
build_command="build:simple:review",
)

# Build Task UI for the application
build_custom_bundle(
cfg.task_dir,
force_rebuild=cfg.mephisto.task.force_rebuild,
post_install_script=cfg.mephisto.task.post_install_script,
build_command="dev:simple",
)


if __name__ == "__main__":
main()
Loading

0 comments on commit 847647d

Please sign in to comment.