Skip to contents

Convert object into a messages list

Usage

as_messages(..., error_call = current_env())

Arguments

...

objects to convert to messages. Each element can be: a string or a result from chat().

error_call

The execution environment of a currently running function, e.g. caller_env(). The function will be mentioned in error messages as the source of the error. See the call argument of abort() for more information.

Examples

# unnamed string means user
as_messages("hello")
#> [[1]]
#> [[1]]$role
#> [1] "user"
#> 
#> [[1]]$content
#> [1] "hello"
#> 
#> 

# explicit names
as_messages(assistant = "hello", user = "hello")
#> [[1]]
#> [[1]]$role
#> [1] "assistant"
#> 
#> [[1]]$content
#> [1] "hello"
#> 
#> 
#> [[2]]
#> [[2]]$role
#> [1] "user"
#> 
#> [[2]]$content
#> [1] "hello"
#> 
#> 

if (FALSE) {
  res <- chat("hello")

  # add result from previous chat()
  as_messages(res, "hello")
}