Convert object into a messages list
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 thecall
argument ofabort()
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")
}