Skip to contents

This function is a custom print method for displaying a tidyprompt() object. A tidyprompt() typically contains a base prompt and may have additional prompt wrappers that modify it. This function applies the modifications specified in the wrapper functions and displays the resulting prompt in a structured and visually clear manner.

Usage

# S3 method for class 'tidyprompt'
print(x, ...)

Arguments

x

A tidyprompt() object. The object should contain:

base_prompt

A character string containing the base prompt text

prompt_wraps

A list containing wrapper functions that modify the base prompt

...

Additional arguments passed to print.tidyprompt (not used; needs to be present in line with guidelines for generic functions)

Value

This function is used for its side effect of printing the prompt to the console. It returns p invisibly

Details

The print.tidyprompt function displays the base prompt and, if applicable, the modified prompt after applying the wrapper functions. The output is formatted with line breaks preserved and with colored text to distinguish metadata from the prompt content. This is done using the cli package to enhance readability, similar to the printing of tibbles in the tidyverse

Examples

# Creating a simple tidyprompt object
prompt <- tidyprompt("What is the capital of France?")

# Print the prompt object
print(prompt)
#> <tidyprompt>
#> base prompt:
#> > What is the capital of France? 
#> Use '<tidyprompt>$base_prompt' to show the base prompt text.
#> Use '<tidyprompt> |> construct_prompt_text()' to get the full prompt text.
#> 

# Adding some wrapper functions
prompt <- prompt |>
  prompt_wrap(modify_fn = \(x) paste0("Answer concisely: ", x))

# Print the modified prompt object
print(prompt)
#> <tidyprompt>
#> The base prompt is modified by a prompt wrap, resulting in:
#> > Answer concisely: What is the capital of France? 
#> Use '<tidyprompt>$prompt_wraps' to show the prompt wraps.
#> Use '<tidyprompt>$base_prompt' to show the base prompt text.
#> Use '<tidyprompt> |> construct_prompt_text()' to get the full prompt text.
#>