Hi! I hope I understand your question and use case correctly – you want to customise what’s fetched from your stream, right?
In that case, using custom arguments in your custom recipe might be the most convenient solution? All arguments to the recipe function automatically become arguments on the command line. So you could do something like this:
@prodigy.recipe('custom-recipe')
def custom_recipe(dataset, msg_type, order_by): # <-- whatever you want
def stream():
while True:
# add the parameters to your request
params = {'type': msg_type, 'order_by': order_by}
url = 'http://localhost:8000/message'
yield requests.get(url, params=params).json()
# other stuff here
return {
'dataset': dataset,
'stream': stream
# etc.
}
You can then execute the recipe from the command line like this:
prodigy custom-recipe dataset_name comment date -F your_recipe.py
The @recipe
decorator also lets you define argument annotations in Plac’s argument annotations format. The descriptions will be shown when you run the recipe with --help
on the command line. You can also define the argument type (so values will be converted accordingly), and whether it’s positional, an option or a flag. For example, here are some random made-up parameters:
@prodigy.recipe('custom-recipe',
dataset=("The dataset to use", "positional", None, str),
msg_type=("The message type", "option", "t", str),
order_by=("Order stream by", "option", "o", str),
per_page=("Items per response", "option", "p", int),
include_title=("Include message titles", "flag", "i", bool)
)
def custom_recipe(dataset, msg_type=None, order_by='created',
per_page=10, include_title=False):
"""Custom recipe that integrates API."""
def stream():
while True:
params = { ... } # and so on
On the command line, you can then do the following to see the recipe description and arguments by typing --help
:
prodigy custom-recipe --help -F your_recipe.py
And usage could look like this:
prodigy custom-recipe your_dataset --msg-type comment --order-by date --per-page 20 --include-title
Or, shortcuts:
prodigy custom-recipe your_dataset -t comment -o date -p 20 -i