Skip to contents

Make LLM answer as a list of items

Usage

answer_as_list(
  prompt,
  item_name = "item",
  item_explanation = NULL,
  n_unique_items = NULL
)

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

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"
} # }