Last modified: NA
Compiled: Mon Aug 21 22:37:22 2023

1 Load packages

library(chatAI4R)

2 Set the API key according to each Web API.

For example, to obtain an OpenAI API key, please register as a member on the OpenAI website (https://platform.openai.com/account/api-keys) and obtain your API key.

#Set your key for the OpenAI API
Sys.setenv(OPENAI_API_KEY = "Your API key")

#Set your key for the DreamStudio API
Sys.setenv(DreamStudio_API_KEY = "Your API key")

3 Simple usage

3.1 One-Shot Chatting

All runs using the chat4R function are One-Shot Chatting. Conversation history is not carried over to the next conversation.

#Set your API key
Sys.setenv(OPENAI_API_KEY = "Your API key")

#This function use the Web API; "https://api.openai.com/v1/chat/completions"
chat4R("What is the capital of France?")

#This function use the Web API; "https://api.openai.com/v1/completions"
completions4R("Hello")

3.2 Few-Shots/Chain-Shots Chatting

Executions using the conversation4R function will keep a history of conversations. The number of previous messages to keep in memory defaults to 2.

#First shot
conversation4R("Hello")

#Second shot
conversation4R("Hello")

4 Text to Image Generation (Legacy)

4.1 DALL·E 2 (Legacy)

Create an image generation prompt and generate an image using the DALL·E 2 model.

# Create a prompt
pr <- createImagePrompt(content = "A white cat. Brown cat. Fluffy. Round eyes. Round. Short hands. Sea. Photo. Facing forward.")

# Generate an image using DALL·E 2
img <- generateImage4R(pr)

# Display
Display(img)