Type: | Package |
Title: | A Convenient R Interface with the OpenAI 'ChatGPT' API |
Version: | 0.7.0 |
Description: | A convenient interface with the OpenAI 'ChatGPT' API https://openai.com/api. 'gptr' allows you to interact with 'ChatGPT', a powerful language model, for various natural language processing tasks. The 'gptr' R package makes talking to 'ChatGPT' in R super easy. It helps researchers and data folks by simplifying the complicated stuff, like asking questions and getting answers. With 'gptr', you can use 'ChatGPT' in R without any hassle, making it simpler for everyone to do cool things with language! |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.1 |
Imports: | jsonlite, RCurl |
NeedsCompilation: | no |
Packaged: | 2025-04-04 18:12:53 UTC; wanjun |
Author: | Wanjun Gu |
Maintainer: | Wanjun Gu <wanjun.gu@ucsf.edu> |
Repository: | CRAN |
Date/Publication: | 2025-04-05 11:20:14 UTC |
Convert data.frams to text interpretable by ChatGPT
Description
This function takes a dataframe as input and converts it to a text representation.
Usage
dataframe_to_text(dataframe)
Arguments
dataframe |
A dataframe to be converted. |
Value
A character vector representing the dataframe in text format.
Examples
dataframe <- data.frame(
Name = c("John", "Alice", "Bob"),
Age = c(25, 30, 22),
Score = c(95, 88, 75)
)
dataframe_to_text(dataframe)
Get Response from OpenAI Chat API
Description
This function sends a user input to the OpenAI Chat API and retrieves a response.
Usage
get_response(
user_input = "what is a p-value in statistics?",
system_specification = "You are a helpful assistant.",
model = "gpt-3.5-turbo",
api_key = Sys.getenv("OPENAI_API_KEY"),
print_response = TRUE
)
Arguments
user_input |
The user's input for the chat interaction. Default is "what is a p-value in statistics?". |
system_specification |
The system's role and content for the chat interaction. Default is "You are a helpful assistant.". |
model |
The OpenAI language model to use. Default is "gpt-3.5-turbo". |
api_key |
The API key for accessing the OpenAI API. Defaults to the value of the "OPENAI_API_KEY" environment variable. |
print_response |
Logical, indicating whether to print the response. Default is TRUE. |
Value
A list containing the response from the OpenAI Chat API.
Examples
response1 = get_response(user_input = "How to calculate the bonforoni corrected p values?")
response2 = get_response(user_input = paste0("Based on this data.frame in R: \n\n",
dataframe_to_text(mtcars),
"\n\n which variables are correlated?"))
response3 = get_response(user_input = "What are redox reactions?",
system_specification = "You are a knowledgeable and helpful chemist \n
who will answer any questions in German")