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.
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"
#>
#>