Skip to contents

Delete a message using positive or negative positions/indices. Negative positions/indices can be used to refer to elements/messages from the end of the sequence.

Usage

delete_message(x, position = -1)

Arguments

x

A list of messages.

position

The position of the message to delete.

Value

A list of messages with the message at the specified position removed.

Examples

messages <- list(
    list(role = "system", content = "Be friendly"),
    list(role = "user", content = "How are you?")
)
delete_message(messages, 1) # delete first message
#> [[1]]
#> [[1]]$role
#> [1] "user"
#> 
#> [[1]]$content
#> [1] "How are you?"
#> 
#> 
delete_message(messages, -2) # same as above (delete first message)
#> [[1]]
#> [[1]]$role
#> [1] "user"
#> 
#> [[1]]$content
#> [1] "How are you?"
#> 
#> 
delete_message(messages, 2) # delete second message
#> [[1]]
#> [[1]]$role
#> [1] "system"
#> 
#> [[1]]$content
#> [1] "Be friendly"
#> 
#> 
delete_message(messages, -1) # same as above (delete second message)
#> [[1]]
#> [[1]]$role
#> [1] "system"
#> 
#> [[1]]$content
#> [1] "Be friendly"
#> 
#>