Skip to contents

Sends the chat to the engine and adds the response to the chat object

Usage

perform_chat(chat_obj, dry_run = FALSE)

Arguments

chat_obj

A chat object created from `create_chat()`

dry_run

A logical indicating whether to return the prepared `httr2` request without actually sending out the request to the vendor. Defaults to FALSE.

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.

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.