Inserts a message at a specified position in a list of messages. The role and content are converted to a list and inserted into the input list at the given position.
Examples
messages <- list(
list(role = "system", content = "Be friendly"),
list(role = "user", content = "How are you?")
)
insert_message("INSERT MESSAGE AT THE END", "user", messages)
#> [[1]]
#> [[1]]$role
#> [1] "system"
#>
#> [[1]]$content
#> [1] "Be friendly"
#>
#>
#> [[2]]
#> [[2]]$role
#> [1] "user"
#>
#> [[2]]$content
#> [1] "How are you?"
#>
#>
#> [[3]]
#> [[3]]$role
#> [1] "user"
#>
#> [[3]]$content
#> [1] "INSERT MESSAGE AT THE END"
#>
#>
insert_message("INSERT MESSAGE AT THE BEGINNING", "user", messages, 2)
#> [[1]]
#> [[1]]$role
#> [1] "system"
#>
#> [[1]]$content
#> [1] "Be friendly"
#>
#>
#> [[2]]
#> [[2]]$role
#> [1] "user"
#>
#> [[2]]$content
#> [1] "INSERT MESSAGE AT THE BEGINNING"
#>
#>
#> [[3]]
#> [[3]]$role
#> [1] "user"
#>
#> [[3]]$content
#> [1] "How are you?"
#>
#>