Learn R Programming

openaiRtools (version 0.2.2)

create_thread: Create a Thread (Convenience Function)

Description

Shortcut that creates an OpenAI client from the OPENAI_API_KEY environment variable and creates a new thread.

Usage

create_thread(...)

Value

A thread object with $id (save this for subsequent calls).

Arguments

...

Parameters passed to ThreadsClient$create(): messages (list of initial messages), tool_resources, metadata.

Examples

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

thread <- create_thread()
cat("Thread ID:", thread$id)

# With an initial message
thread <- create_thread(
  messages = list(list(role = "user", content = "Hello!"))
)
}

Run the code above in your browser using DataLab