View source: R/answer_as_named_list.R
| answer_as_named_list | R Documentation |
Get a named list from LLM response with optional item instructions and validations.
answer_as_named_list(
prompt,
item_names,
item_instructions = NULL,
item_validations = NULL
)
prompt |
A single string or a |
item_names |
A character vector specifying the expected item names |
item_instructions |
An optional named list of additional instructions for each item |
item_validations |
An optional named list of validation functions for each item.
Like validation functions for a |
A tidyprompt() with an added prompt_wrap() that ensures
the LLM response is a named list with the specified item names, optional
instructions, and validations.
answer_as_list() llm_feedback()
Other pre_built_prompt_wraps:
add_text(),
answer_as_boolean(),
answer_as_category(),
answer_as_integer(),
answer_as_json(),
answer_as_list(),
answer_as_multi_category(),
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_category(),
answer_as_integer(),
answer_as_json(),
answer_as_list(),
answer_as_multi_category(),
answer_as_regex_match(),
answer_as_text()
## Not run:
persona <- "Create a persona for me, please." |>
answer_as_named_list(
item_names = c("name", "age", "occupation"),
item_instructions = list(
name = "The name of the persona",
age = "The age of the persona",
occupation = "The occupation of the persona"
)
) |> send_prompt(llm_provider_ollama())
# --- Sending request to LLM provider (llama3.1:8b): ---
# Create a persona for me, please.
#
# Respond with a named list like so:
# -- name: <<value>> (The name of the persona)
# -- age: <<value>> (The age of the persona)
# -- occupation: <<value>> (The occupation of the persona)
# Each name must correspond to: name, age, occupation
# --- Receiving response from LLM provider: ---
# Here is your persona:
#
# -- name: Astrid Welles
# -- age: 32
# -- occupation: Museum Curator
persona$name
# [1] "Astrid Welles"
persona$age
# [1] "32"
persona$occupation
# [1] "Museum Curator"
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.