Skip to contents

Prints all messages to the console and saves them invisibly

Usage

extract_chat(chat_obj, silent = FALSE)

Arguments

chat_obj

A chat object created from `create_chat()`

silent

A logical vector with one element. If TRUE, the messages are not printed to the console.

Value

A chat object with the responses added

Examples

if (FALSE) dotenv::load_dot_env()
chat_openai <- create_chat('openai', Sys.getenv('OAI_DEV_KEY'))|>
  add_model('gpt-3.5-turbo') |>
  add_params('temperature' = 0.5, 'max_tokens' = 100) |>
  add_message(
    role = 'system',
    message = 'You are a chatbot that completes texts.
    You do not return the full text.
    Just what you think completes the text.'
  ) |>
  add_message('2 + 2 is 4, minus 1 that\'s 3, ')
  chat_openai <- chat_openai |>
    perform_chat()
#> Error in httr2::req_perform(prepared_engine): HTTP 401 Unauthorized.
  msgs_openai <- chat_openai |> extract_chat()
#> System: You are a chatbot that completes texts.
#>     You do not return the full text.
#>     Just what you think completes the text. 
#> User: 2 + 2 is 4, minus 1 that's 3,  
#> 

chat_mistral <- create_chat('mistral', Sys.getenv('MISTRAL_DEV_KEY')) |>
  add_model('mistral-large-latest') |>
  add_params('temperature' = 0.5, 'max_tokens' = 100) |>
  add_message(
    role = 'system',
    message = 'You are a chatbot that completes texts.
    You do not return the full text.
    Just what you think completes the text.'
  ) |>
  add_message('2 + 2 is 4, minus 1 that\'s 3, ')
  chat_mistral <- chat_mistral |>
    perform_chat()
#> Error in httr2::req_perform(prepared_engine): HTTP 401 Unauthorized.
  msgs_mistral <- chat_mistral |> extract_chat()
#> System: You are a chatbot that completes texts.
#>     You do not return the full text.
#>     Just what you think completes the text. 
#> User: 2 + 2 is 4, minus 1 that's 3,  
#>