View source: R/answer_as_list.R
answer_as_list | R Documentation |
Make LLM answer as a list of items
answer_as_list(
prompt,
item_name = "item",
item_explanation = NULL,
n_unique_items = NULL,
list_mode = c("bullet", "comma")
)
prompt |
A single string or a |
item_name |
(optional) Name of the items in the list |
item_explanation |
(optional) Additional explanation of what an item should be. Item explanation should be a single string. It will be appended after the list instruction |
n_unique_items |
(optional) Number of unique items required in the list |
list_mode |
(optional) Mode of the list. Either "bullet" or "comma". "bullet mode expects items to be listed with "ā" before each item, with a new line for each item (e.g., "ā item1\nā item2\nā item3"). "comma" mode expects items to be listed with a number and a period before (e.g., "1. item1, 2. item2, 3. item3"). "comma" mode may be easier for smaller LLMs to use |
A tidyprompt()
with an added prompt_wrap()
which
will ensure that the LLM response is a list of items
answer_as_named_list()
Other pre_built_prompt_wraps:
add_text()
,
answer_as_boolean()
,
answer_as_integer()
,
answer_as_json()
,
answer_as_named_list()
,
answer_as_regex_match()
,
answer_as_text()
,
answer_by_chain_of_thought()
,
answer_by_react()
,
answer_using_r()
,
answer_using_sql()
,
answer_using_tools()
,
prompt_wrap()
,
quit_if()
,
set_system_prompt()
Other answer_as_prompt_wraps:
answer_as_boolean()
,
answer_as_integer()
,
answer_as_json()
,
answer_as_named_list()
,
answer_as_regex_match()
,
answer_as_text()
## Not run:
"What are some delicious fruits?" |>
answer_as_list(item_name = "fruit", n_unique_items = 5) |>
send_prompt()
# --- Sending request to LLM provider (llama3.1:8b): ---
# What are some delicious fruits?
#
# Respond with a list, like so:
# -- <<fruit 1>>
# -- <<fruit 2>>
# etc.
# The list should contain 5 unique items.
# --- Receiving response from LLM provider: ---
# Here's the list of delicious fruits:
# -- Strawberries
# -- Pineapples
# -- Mangoes
# -- Blueberries
# -- Pomegranates
# [[1]]
# [1] "Strawberries"
#
# [[2]]
# [1] "Pineapples"
#
# [[3]]
# [1] "Mangoes"
#
# [[4]]
# [1] "Blueberries"
#
# [[5]]
# [1] "Pomegranates"
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.