Learn R Programming

tidyllm (version 0.2.0)

llm_message: Create or Update Large Language Model Message Object

Description

This function allows the creation of a new LLMMessage object or the updating of an existing one. It can handle the addition of text prompts and various media types such as images, PDFs, text files, or plots. The function includes input validation to ensure that all provided parameters are in the correct format.

Usage

llm_message(
  .llm = NULL,
  .prompt = NULL,
  .role = "user",
  .system_prompt = "You are a helpful assistant",
  .imagefile = NULL,
  .pdf = NULL,
  .textfile = NULL,
  .capture_plot = FALSE,
  .f = NULL
)

Value

Returns an updated or new LLMMessage object.

Arguments

.llm

An existing LLMMessage object or an initial text prompt.

.prompt

Text prompt to add to the message history.

.role

The role of the message sender, typically "user" or "assistant".

.system_prompt

Default system prompt if a new LLMMessage needs to be created.

.imagefile

Path to an image file to be attached (optional).

.pdf

Path to a PDF file to be attached (optional). Can be a character vector of length one (file path), or a list with filename, start_page, and end_page.

.textfile

Path to a text file to be read and attached (optional).

.capture_plot

Boolean to indicate whether a plot should be captured and attached as an image (optional).

.f

An R function or an object coercible to a function via rlang::as_function, whose output should be captured and attached (optional).