Make LLM answer as a list of items
Arguments
- prompt
A single string or a
tidyprompt()
object- 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
Value
A tidyprompt()
with an added prompt_wrap()
which
will ensure that the LLM response is a list of items
See also
Other pre_built_prompt_wraps:
add_text()
,
add_tools()
,
answer_as_boolean()
,
answer_as_code()
,
answer_as_integer()
,
answer_as_named_list()
,
answer_as_regex()
,
answer_by_chain_of_thought()
,
answer_by_react()
,
prompt_wrap()
,
quit_if()
,
set_system_prompt()
Other answer_as_prompt_wraps:
answer_as_boolean()
,
answer_as_code()
,
answer_as_integer()
,
answer_as_named_list()
,
answer_as_regex()
Examples
if (FALSE) { # \dontrun{
"What are some delicious fruits?" |>
answer_as_list(item_name = "fruit", n_unique_items = 5) |>
send_prompt(llm_provider_ollama())
# --- 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 a list of delicious fruits:
#
# -- Strawberries
# -- Pineapples
# -- Mangoes
# -- Papayas
# -- Kiwis
# [1] "Strawberries" "Pineapples" "Mangoes" "Papayas" "Kiwis"
} # }