Skip to content

Commit

Permalink
Merge pull request #1219 from facebookresearch/update-cli-help
Browse files Browse the repository at this point in the history
Update help for mephisto CLI command
  • Loading branch information
meta-paul authored Jul 26, 2024
2 parents 94b38fc + c3a2fb9 commit 63aa92c
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ An example of a remote procedure that gets called during the initial form loadin
The below command auto-generates config token values that presign themselves during rendering of the Task page:

```
mephisto form_composer_config --update-file-location-values "https://s3.amazonaws.com/..." --use_presigned_urls
mephisto form_composer config --update-file-location-values "https://s3.amazonaws.com/..." --use_presigned_urls
```

This is how URL pre-signing works:
Expand All @@ -30,7 +30,7 @@ This is how URL pre-signing works:

Presigned S3 URLs use the following environment variables:
- Required: valid AWS credentials: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_DEFAULT_REGION`
form_composer_config` command)
(`form_composer config` command)
- Optional: URL expiration time `S3_URL_EXPIRATION_MINUTES` (if missing the default value is 60 minutes)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
sidebar_position: 3
---

# `form_composer_config` command
# `form_composer config` command

The `form_composer_config` utility command helps auto-generate FormComposer config. It supports several options:
The `form_composer config` utility command helps auto-generate FormComposer config. It supports several options:

```shell
# Sample launching commands
mephisto form_composer_config --update-file-location-values "https://s3.amazonaws.com/..." --use_presigned_urls
mephisto form_composer_config --update-file-location-values "https://s3.amazonaws.com/..."
mephisto form_composer_config --permutate-separate-tokens
mephisto form_composer_config --extrapolate-token-sets
mephisto form_composer_config --verify
mephisto form_composer config --update-file-location-values "https://s3.amazonaws.com/..." --use_presigned_urls
mephisto form_composer config --update-file-location-values "https://s3.amazonaws.com/..."
mephisto form_composer config --permutate-separate-tokens
mephisto form_composer config --extrapolate-token-sets
mephisto form_composer config --verify
# Parameters that work together
mephisto form_composer_config --directory /my/own/path/to/data/ --verify
mephisto form_composer_config --directory /my/own/path/to/data/ --extrapolate-token-sets
mephisto form_composer_config --update-file-location-values "https://s3.amazonaws.com/..."
mephisto form_composer config --directory /my/own/path/to/data/ --verify
mephisto form_composer config --directory /my/own/path/to/data/ --extrapolate-token-sets
mephisto form_composer config --update-file-location-values "https://s3.amazonaws.com/..."
```

where
- `-d/--directory` - a **modifier** for all `form_composer_config` command options that specifies the directory where all form JSON config files are located (if missing the default is `mephisto/generators/form_composer/data` directory)
- `-d/--directory` - a **modifier** for all `form_composer config` command options that specifies the directory where all form JSON config files are located (if missing the default is `mephisto/generators/form_composer/data` directory)
- `-v/--verify` - if truthy, validates all JSON configs currently present in the form builder config directory
- `-p/--permutate-sepatate-tokens` - if truthy, generates token sets values as all possible combinations of values of individual tokens
- `-f/--update-file-location-values S3_FOLDER_URL` - generates token values based on file names found within the specified S3 folder (see a separate section about this mode of running FormComposer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FormComposer allows using custom code insertions in these scenarios:
- Define custom styles for the FormComposer UI in a CSS file

The inserted code must reside in separate files (called "insertion files") located in `insertions` subdirectory of your form config directory.
- _Remember that you can change default config directory path using `--directory` option of `form_composer_config` command_
- _Remember that you can change default config directory path using `--directory` option of `form_composer config` command_

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sidebar_position: 2
The simplest Task scenario is showing the same exact form to all of your workers. In that case you need to:

- Compose `task_data.json` file containing definition of a single form (and place it into FormComposer config folder)
- Optionally, verify your config: `mephisto form_composer_config --verify`
- Optionally, verify your config: `mephisto form_composer config --verify`
- Run FormComposer: `mephisto form_composer`

But suppose you wish to show a slightly different version of the form to your workers. You can do so by defining multiple form versions. FormComposer provides several ways of doing so.
Expand All @@ -23,7 +23,7 @@ But suppose you wish to show a slightly different version of the form to your wo
If your form versions vary considerably (e.g. showing different sets of fields), you should do the following steps:

- Populate these form versions into `task_data.json` file manually (it will be basically a JSON array of N individual form versions configs)
- Optionally, verify your config: `mephisto form_composer_config --verify`
- Optionally, verify your config: `mephisto form_composer config --verify`
- Run FormComposer: `mephisto form_composer`

_As a result, for each Task assignment Mephisto will automatically produce N units, each unit having a different form version. In total you will be collecting data from `N * units_per_assignment` workers._
Expand All @@ -37,8 +37,8 @@ If your form versions vary only slightly (e.g. same set of fields, but showing d
- Ensure you populate these files, and place them into your FormComposer config folder:
- `form_config.json`: tokenized form config - same as regular form config, except it will contain tokens within certain objects' attributes (see [Tokens extrapolation](#tokens-extrapolation))
- `token_sets_values_config.json`: file containing sets of token values, where each set is used to generate one version of the form (and each form version will be completed by `units_per_assignment` different workers).
- Optionally, verify your files: `mephisto form_composer_config --verify`
- Generate task data config: `mephisto form_composer_config --extrapolate-token-sets`
- Optionally, verify your files: `mephisto form_composer config --verify`
- Generate task data config: `mephisto form_composer config --extrapolate-token-sets`
- This will overwrite existing `task_data.json` file with auto-generated form versions, by extrapolating provided token sets values
- Run FormComposer: `mephisto form_composer`

Expand Down Expand Up @@ -72,8 +72,8 @@ If you wish to reuse the same token across different form attributes and levels,
In a special case when all of your tokens sets are simply permutations of several value lists, sets of token values can be easily auto-generated.

- Populate your lists of values for every separate token into `separate_token_values_config.json` file
- Optionally, verify your config: `mephisto form_composer_config --verify`
- Generate `token_sets_values_config.json` with command: `mephisto form_composer_config --permutate-separate-tokens`
- Optionally, verify your config: `mephisto form_composer config --verify`
- Generate `token_sets_values_config.json` with command: `mephisto form_composer config --permutate-separate-tokens`

_"Permutation" means all possible combinations of values. For example, permutations of amounts `2, 3`, sizes `big` and animals `cats, dogs` will produce result `2 big cats, 2 big dogs, 3 big cats, 3 big dogs`._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FormComposer tasks are fully defined by their configuration files. These files c
The structure and purpose of these files is detailed further in other sections:
- [Config files reference](/docs/guides/how_to_use/form_composer/configuration/config_files/)
- [Using multiple form versions](/docs/guides/how_to_use/form_composer/configuration/multiple_form_versions/)
- [form_composer_config command](/docs/guides/how_to_use/form_composer/configuration/form_composer_config_command/)
- [`form_composer config` command](/docs/guides/how_to_use/form_composer/configuration/form_composer_config_command/)
- [Using code insertions](/docs/guides/how_to_use/form_composer/configuration/insertions/)
- [Form rendering callbacks](/docs/guides/how_to_use/form_composer/configuration/form_callbacks/)

Expand Down
8 changes: 4 additions & 4 deletions docs/web/docs/guides/how_to_use/form_composer/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Once your Task launches, your console will display you URLs like this: `http://<

You can launch FormComposer inside a Docker container:

1. Prepare configs using [form_composer_config command](/docs/guides/how_to_use/form_composer/configuration/form_composer_config_command/):
1. Prepare configs using [`form_composer config` command](/docs/guides/how_to_use/form_composer/configuration/form_composer_config_command/):

```shell
docker-compose -f docker/docker-compose.dev.yml run \
--build \
--rm mephisto_dc \
mephisto form_composer_config --extrapolate-token-sets
mephisto form_composer config --extrapolate-token-sets
```

2. Run composer itself using `form_composer` command:
Expand All @@ -45,10 +45,10 @@ docker-compose -f docker/docker-compose.dev.yml run \
#### Without docker-compose

First ensure that mephisto package is installed locally - please refer to [Mephisto's main doc](https://mephisto.ai/docs/guides/quickstart/).
Once that is done, run [form_composer_config command](/docs/guides/how_to_use/form_composer/configuration/form_composer_config_command/) if needed, followed by `form_composer` command:
Once that is done, run [`form_composer config` command](/docs/guides/how_to_use/form_composer/configuration/form_composer_config_command/) if needed, followed by `form_composer` command:

```shell
mephisto form_composer_config --extrapolate-token-sets
mephisto form_composer config --extrapolate-token-sets
mephisto form_composer
mephisto form_composer --task-data-config-only
```
2 changes: 1 addition & 1 deletion docs/web/docs/guides/tutorials/form_composer.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If your task has questionnaire format, you can build it out-of-the box with no c
To launch a form-based Task from within a Docker container follow these steps:

1. Prepare and validate your config files as described in [FormComposer config files](/docs/guides/how_to_use/form_composer/configuration/setup/) and
[FormComposer config utils](/docs/guides/how_to_use/form_composer/running/#using-form_composer_config-utility) sections
[form_composer config command](/docs/guides/how_to_use/form_composer/configuration/form_composer_config_command/) sections

2. Launch your form-based Task (see details in [Running FormComposer task](/docs/guides/how_to_use/form_composer/running/)). For a lcal testing scenario, we will run:

Expand Down
14 changes: 7 additions & 7 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ This example builds further upon the Dynamic form example. Here we use presigned

- Set up environment variables (in file `docker/envs/env.dev`):
- Required: valid AWS credentials: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_DEFAULT_REGION`
- Required: a private S3 bucket with files that you will embed in the example form (either replace dummy URLs in the configs by hand, or automatically generate new ones with `mephisto form_composer_config` command)
- Required: a private S3 bucket with files that you will embed in the example form (either replace dummy URLs in the configs by hand, or automatically generate new ones with `mephisto form_composer config` command)
- Optional: `S3_URL_EXPIRATION_MINUTES` (default value is 60 minutes)
- Default config file: [dynamic_example_local_mock.yaml](/examples/form_composer_demo/hydra_configs/conf/dynamic_example_local_mock.yaml).
- Create config: see all options for `form_composer_config` command [here](/mephisto/generators/form_composer/README.md#using-formcomposerconfig-utility). Example command:
- Create config: see all options for `form_composer config` command [here](/mephisto/generators/form_composer/README.md#using-formcomposerconfig-utility). Example command:
```shell
docker-compose -f docker/docker-compose.dev.yml run \
--build \
--publish 3001:3000 \
--rm mephisto_dc \
mephisto form_composer_config --verify --directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls"
mephisto form_composer config --verify --directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls"
```
- Launch command after you generated all configs:
```shell
Expand Down Expand Up @@ -231,20 +231,20 @@ Putting it altogether, let's prepare and launch a task featuring a form containi
- SSH into the running container: `docker exec -it mephisto_dc bash`
- Generate your task data config with these commands:
```shell
mephisto form_composer_config \
mephisto form_composer config \
--directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls" \
--update-file-location-values "https://your-bucket.s3.amazonaws.com/..." \
--use-presigned-urls

mephisto form_composer_config \
mephisto form_composer config \
--directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls" \
--permutate-separate-tokens

mephisto form_composer_config \
mephisto form_composer config \
--directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls" \
--extrapolate-token-sets

mephisto form_composer_config \
mephisto form_composer config \
--directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls" \
--verify
```
Expand Down
4 changes: 2 additions & 2 deletions examples/form_composer_demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ These form-based questionnaires are example of FormComposer task generator.
2. For dynamic form configs you need two JSON files in `examples/form_composer_demo/data/dynamic` directory:
- Form configuration `form_config.json`
- Token sets values `token_sets_values_config.json`
- To generate extrapolated `task_data.json` config, run this command: `mephisto form_composer_config --extrapolate-token-sets True`
- To generate extrapolated `task_data.json` config, run this command: `mephisto form_composer config --extrapolate-token-sets True`
- Note that `task_data.json` file will be overwritten with the resulting config
3. To generate `token_sets_values_config.json` file from token values permutations in `separate_token_values_config.json`, run this command: `mephisto form_composer_config --permutate-separate-tokens`
3. To generate `token_sets_values_config.json` file from token values permutations in `separate_token_values_config.json`, run this command: `mephisto form_composer config --permutate-separate-tokens`
- Note that `token_sets_values_config.json` file will be overwriten with new sets of tokens values

---
Expand Down
6 changes: 2 additions & 4 deletions mephisto/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from rich_click import RichGroup

from mephisto.client.cli_db_commands import db_cli
from mephisto.client.cli_form_composer_commands import form_composer
from mephisto.client.cli_form_composer_commands import form_composer_config
from mephisto.client.cli_form_composer_commands import form_composer_cli
from mephisto.client.cli_metrics_commands import metrics_cli
from mephisto.client.cli_review_app_commands import review_app
from mephisto.client.cli_scripts_commands import run_script
Expand Down Expand Up @@ -179,8 +178,7 @@ def register_provider(args):
)
cli.command("wut", cls=RichCommand, context_settings={"ignore_unknown_options": True})(run_wut)
cli.command("review_app", cls=RichCommand)(review_app)
cli.command("form_composer", cls=RichCommand)(form_composer)
cli.command("form_composer_config", cls=RichCommand)(form_composer_config)
cli.add_command(form_composer_cli)
cli.add_command(metrics_cli)
cli.add_command(db_cli)

Expand Down
3 changes: 2 additions & 1 deletion mephisto/client/cli_db_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import click
from rich_click import RichCommand
from rich_click import RichGroup

from mephisto.tools.db_data_porter import DBDataPorter
from mephisto.tools.db_data_porter.constants import DEFAULT_CONFLICT_RESOLVER
Expand Down Expand Up @@ -36,7 +37,7 @@ def _print_used_options_for_running_command_message(ctx: click.Context, options:
logger.debug(message)


@click.group(name="db", context_settings=dict(help_option_names=["-h", "--help"]))
@click.group(name="db", context_settings=dict(help_option_names=["-h", "--help"]), cls=RichGroup)
def db_cli():
"""Operations with Mephisto DB and provider-specific datastores"""
pass
Expand Down
Loading

0 comments on commit 63aa92c

Please sign in to comment.