Learn R Programming

chatAI4R (version 0.3.6)

chat4R_history: chat4R_history: Use chat history for interacting with GPT.

Description

This function use the chat history with the the specified GPT model, and chat the AI model.

Usage

chat4R_history(
  history,
  api_key = Sys.getenv("OPENAI_API_KEY"),
  Model = "gpt-4o-mini",
  temperature = 1
)

Value

A data frame containing the parsed response from the Web API server.

Arguments

history

A list of message objects. Each object should have a 'role' that can be 'system', 'user', or 'assistant', and 'content' which is the content of the message from that role.

api_key

A string. Input your OpenAI API key. Defaults to the value of the environment variable "OPENAI_API_KEY".

Model

A string. The model to use for the chat completion. Default is "gpt-4o-mini".

temperature

The temperature to use for the chat completion. Default is 1.

Author

Satoshi Kume

Details

Chat History for R

Examples

Run this code
if (FALSE) {
Sys.setenv(OPENAI_API_KEY = "Your API key")

history <- list(list('role' = 'system', 'content' = 'You are a helpful assistant.'),
                list('role' = 'user', 'content' = 'Who won the world series in 2020?'))

chat4R_history(history)
}

Run the code above in your browser using DataLab