Skip to content

Use these functions if you're writing a package that extends ellmer and need to customise methods for various types of content. For normal use, see content_image_url() and friends.

ellmer abstracts away differences in the way that different Providers represent various types of content, allowing you to more easily write code that works with any chatbot. This set of classes represents types of content that can be either sent to and received from a provider:

  • ContentText: simple text (often in markdown format). This is the only type of content that can be streamed live as it's received.

  • ContentImageRemote and ContentImageInline: images, either as a pointer to a remote URL or included inline in the object. See content_image_file() and friends for convenient ways to construct these objects.

  • ContentToolRequest: a request to perform a tool call (sent by the assistant).

  • ContentToolResult: the result of calling the tool (sent by the user).

Usage

Content()

ContentText(text = stop("Required"))

ContentImage()

ContentImageRemote(url = stop("Required"), detail = "")

ContentImageInline(type = stop("Required"), data = NULL)

ContentToolRequest(
  id = stop("Required"),
  name = stop("Required"),
  arguments = list()
)

ContentToolResult(id = stop("Required"), value = NULL, error = NULL)

Arguments

text

A single string.

url

URL to a remote image.

detail

Not currently used.

type

MIME type of the image.

data

Base64 encoded image data.

id

Tool call id (used to associate a request and a result)

name

Function name

arguments

Named list of arguments to call the function with.

value, error

Either the results of calling the function if it succeeded, otherwise the error message, as a string. One of value and error will always be NULL.

Value

S7 objects that all inherit from Content

Examples

Content()
#> <ellmer::Content>
ContentText("Tell me a joke")
#> <ellmer::ContentText>
#>  @ text: chr "Tell me a joke"
ContentImageRemote("https://www.r-project.org/Rlogo.png")
#> <ellmer::ContentImageRemote>
#>  @ url   : chr "https://www.r-project.org/Rlogo.png"
#>  @ detail: chr ""
ContentToolRequest(id = "abc", name = "mean", arguments = list(x = 1:5))
#> <ellmer::ContentToolRequest>
#>  @ id       : chr "abc"
#>  @ name     : chr "mean"
#>  @ arguments:List of 1
#>  .. $ x: int [1:5] 1 2 3 4 5