diff --git a/R/stream-copilot.R b/R/stream-copilot.R index c399a69..cb7ac64 100644 --- a/R/stream-copilot.R +++ b/R/stream-copilot.R @@ -16,10 +16,14 @@ chat_copilot <- function() { req_body_json( data = list( messages = list( - list(role = "user", - content = "Tell me a joke about the R language.") + list( + role = "user", + content = "Tell me a joke about the R language." + ) ), - model = "copilot")) |> + model = "copilot" + ) + ) |> req_perform() |> resp_chat_openai(stream = FALSE) } diff --git a/R/stream-openai.R b/R/stream-openai.R index 20960d8..66c7d0c 100644 --- a/R/stream-openai.R +++ b/R/stream-openai.R @@ -3,7 +3,6 @@ chat_openai <- function(prompt = "Tell me a joke about the R language.", history = NULL, temperature = NULL, stream = FALSE) { - prompt <- prompt |> add_history(history) response <- @@ -15,13 +14,14 @@ chat_openai <- function(prompt = "Tell me a joke about the R language.", ) |> resp_chat_openai(stream = is_true(stream)) - response <- c(prompt, - list(list(role = response$role, content = response$content))) + response <- c( + prompt, + list(list(role = response$role, content = response$content)) + ) class(response) <- c("chat_list", class(response)) response - } #' @export @@ -34,9 +34,9 @@ print.chat_list <- function(x, ...) { print_role <- rule(stringr::str_to_title(x[[i]]$role)) print_role <- switch(x[[i]]$role, - "assistant" = col_green(print_role), - "system" = col_silver(print_role), - "user" = col_blue(print_role) + "assistant" = col_green(print_role), + "system" = col_silver(print_role), + "user" = col_blue(print_role) ) writeLines(print_role) writeLines(x[[i]]$content)