Skip to contents

Add messages to a chat object.

Usage

add_message(chat_obj, message, role = "user")

Arguments

chat_obj

A chat object created from `create_chat()`

message

A character vector with one element. The message to add to the chat.

role

A character vector with one element. The role of the message. Typically 'user' or 'system'.

Value

A chat object with the messages 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_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, ')