Learn R Programming

openaiRtools (version 0.2.2)

create_message: Add a Message to a Thread (Convenience Function)

Description

Shortcut that creates an OpenAI client from the OPENAI_API_KEY environment variable and adds a message to a thread.

Usage

create_message(thread_id, role, content, ...)

Value

A message object with $id and $content.

Arguments

thread_id

Character. Required. The thread ID.

role

Character. Required. "user" or "assistant".

content

Character or list. Required. The message text, or a list of content parts for multimodal messages.

...

Additional parameters passed to MessagesClient$create(), such as attachments and metadata.

Examples

Run this code
if (FALSE) {
Sys.setenv(OPENAI_API_KEY = "sk-xxxxxx")

msg <- create_message(
  thread_id = "thread_abc123",
  role      = "user",
  content   = "What is the difference between FE and RE estimators?"
)
cat("Message ID:", msg$id)
}

Run the code above in your browser using DataLab