Skip to contents

The pal package provides a number of tools for working on system prompts. System prompts are what instruct pals on how to behave and provide information to live in the models' "short-term memory."

prompt_*() functions allow users to conveniently create, edit, remove, the prompts in pal's "prompt directory."

  • prompt_new() creates a new markdown file that will automatically create a pal with the specified role, prompt, and interface on package load. Specify a contents argument to prefill with contents from a markdown file on your computer or the web.

  • prompt_edit() and prompt_remove() open and delete, respectively, the file that defines the given role's system prompt.

Load the prompts you create with these functions using directory_load() (which is automatically called when the package loads).

Usage

prompt_new(role, interface, contents = NULL)

prompt_remove(role)

prompt_edit(role)

Arguments

role

A single string giving a descriptor of the pal's functionality. Cand only contain letters and numbers.

interface

One of "replace", "prefix", or "suffix", describing how the pal will interact with the selection. For example, the cli pal "replace"s the selection, while the roxygen pal "prefixes" the selected code with documentation.

contents

Optional. Path to a markdown file with contents that will "pre-fill" the file. Anything file ending in .md or .markdown that can be read with readLines() is fair game; this could be a local file, a "raw" URL to a GitHub Gist or file in a GitHub repository, etc.

Value

Each prompt_*() function returns the file path to the created, edited, or removed filepath, invisibly.

See also

The directory help-page for more on working with prompts in batch using directory_*() functions, and vignette("custom", package = "pal") for more on sharing pal prompts and using prompts from others.

Examples

if (FALSE) {
# create a new pal with role `"boop"` that replaces the selected text:
prompt_new("boop")

# after writing a prompt, register it with the pal package with:
directory_load()

# after closing the file, reopen with:
prompt_edit("boop")

# remove the prompt (next time the package is loaded) with:
prompt_remove("boop")

# pull prompts from files on local drives or the web with
# `prompt_new(contents)`. for example, here is a GitHub Gist:
# paste0(
#  "https://gist.githubusercontent.com/simonpcouch/",
#  "daaa6c4155918d6f3efd6706d022e584/raw/ed1da68b3f38a25b58dd9fdc8b9c258d",
#  "58c9b4da/summarize-prefix.md"
# )
#
# press "Raw" and then supply that URL as `contents` (you don't actually
# have to use the paste0() to write out the URL--we're just keeping
# the characters per line under 80):
prompt_new(
  role = "summarize",
  interface = "prefix",
  contents =
    paste0(
      "https://gist.githubusercontent.com/simonpcouch/",
      "daaa6c4155918d6f3efd6706d022e584/raw/ed1da68b3f38a25b58dd9fdc8b9c258d",
      "58c9b4da/summarize-prefix.md"
    )
)
}