Skip to contents

Build prompt for categorizing a text into multiple categories For single category, see answer_as_category()

Usage

answer_as_multi_category(prompt, categories, descriptions = NULL)

Arguments

prompt

A single string or a tidyprompt() object

categories

A character vector of category names. Must not be empty and must not contain duplicates

descriptions

An optional character vector of descriptions, corresponding to each category. If provided, its length must match the length of categories. Defaults to NULL

Value

A tidyprompt() with an added prompt_wrap() which will ensure that the LLM response is a vector of fitting categories of a text

Examples

if (FALSE) { # \dontrun{
  "It is sunny, that makes me happy." |>
    answer_as_multi_category(
      categories = c("environment", "weather", "work", "positive", "negative")
    ) |>
    send_prompt()
  # --- Sending request to LLM provider (llama3.1:8b): ---
  #   You need to categorize a text.
  #
  # Text:
  #   'It is sunny, that makes me happy.'
  #
  # Possible categories:
  #   1. environment
  #   2. weather
  #   3. work
  #   4. positive
  #   5. negative
  #
  # Respond with the numbers of all categories that apply to this text, separated by commas.
  # (Use no other words or characters.)
  # --- Receiving response from LLM provider: ---
  #   2, 4
  # ["weather","positive"]
} # }