View source: R/format_prompt.R
format_prompt | R Documentation |
Format a text prompt for a Large Language Model. Particularly useful for few-shot text classification tasks. Note that if you are planning to use one of OpenAI's chat models, like ChatGPT or GPT-4, you will want to use the format_chat()
function instead.
format_prompt(
text,
instructions = "",
examples = data.frame(),
template = "Text: {text}\nClassification: {label}",
prompt_template = "{instructions}{examples}{input}",
separator = "\n\n"
)
text |
The text to be classified. Can be a character vector or a single string. |
instructions |
Instructions to be included in the prompt (format them like you would format instructions to a human research assistant). |
examples |
A dataframe of "few-shot" examples. Must include one column called 'text' with the example text(s) and another column called "label" with the correct label(s). |
template |
The template for how examples and completions should be formatted, in |
prompt_template |
The template for the entire prompt. Defaults to instructions, followed by few-shot examples, followed by the input to be classified. |
separator |
A character that separates examples. Defaults to two carriage returns. |
Returns a formatted prompt that can be used as input for complete_prompt()
or openai::create_completion()
.
data(scotus_tweets_examples)
format_prompt(text = "I am disappointed with this ruling.",
instructions = "Decide if the sentiment of this statement is Positive or Negative.",
examples = scotus_tweets_examples,
template = "Statement: {text}\nSentiment: {label}")
format_prompt(text = 'I am sad about the Supreme Court',
examples = scotus_tweets_examples,
template = '"{text}" is a {label} statement',
separator = '\n')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.