chat.edit {GenAI}R Documentation

Chat Edit with New Text as the Input

Description

This function establishes a connection to a generative AI model through a generative AI object. It generates a chat response based on the new prompt and stores it in the chat history along with the generative AI object.

Usage

chat.edit(
  genai.object,
  prompt,
  message.to.edit,
  verbose = FALSE,
  config = list()
)

Arguments

genai.object

A generative AI object containing necessary and correct information.

prompt

A character string representing the query for chat generation.

message.to.edit

An integer representing the index of the message to be edited.

verbose

Optional. Default to FALSE. A boolean value determining whether or not to print out the details of the chat request.

config

Optional. Default to list(). A list of configuration parameters for chat generation.

Details

Providing accurate and valid information for each argument is crucial for successful chat generation by the generative AI model. If any parameter is incorrect, the function responds with an error message based on the API feedback. To view all supported generative AI models, use the function available.models.

In addition, this function modifies the chat history along with the generative AI object directly, meaning the chat history is mutable. You can print out the chat history using the function chat.history.print or simply use verbose = TRUE in this function. To reset the chat history along with the chat history along with the generative AI object, use the function chat.history.reset.

For Google Generative AI models, available configurations are as follows. For more detail, please refer to https://ai.google.dev/api/rest/v1/HarmCategory, https://ai.google.dev/api/rest/v1/SafetySetting, and https://ai.google.dev/api/rest/v1/GenerationConfig.

For Moonshot AI models, available configurations are as follows. For more detail, please refer to https://platform.moonshot.cn/api.html#chat-completion.

For OpenAI models, available configurations are as follows. For more detail, please refer to https://platform.openai.com/docs/api-reference/chat/create.

Value

If successful, the most recent chat response will be returned. If the API response indicates an error, the function halts execution and provides an error message.

See Also

GenAI - R Package "GenAI" Documentation

Live Demo in Colab

Examples

## Not run: 
# Assuming there is a GenAI object named 'genai.model' supporting this
# function, please refer to the "Live Demo in Colab" above for real
# examples. The following examples are just some basic guidelines.

# Method 1 (recommended): use the pipe operator "%>%"
genai.model %>%
  chat.edit(prompt = "What is XGBoost?",
            message.to.edit = 5,
            verbose = TRUE,
            config = parameters) %>%
  cat()

# Method 2: use the reference operator "$"
cat(genai.model$chat.edit(prompt = "What is CatBoost?",
                          message.to.edit = 3))

# Method 3: use the function chat.edit() directly
cat(chat.edit(genai.object = genai.model,
              prompt = "What is LightGBM?",
              message.to.edit = 1))

## End(Not run)


[Package GenAI version 0.2.0 Index]