Title: | A Convenient R Interface with the OpenAI 'ChatGPT' API |
---|---|
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! |
Authors: | Wanjun Gu [aut, cre] |
Maintainer: | Wanjun Gu <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.6.0 |
Built: | 2024-10-25 04:31:31 UTC |
Source: | https://github.com/broccolito/gptr |
This function takes a dataframe as input and converts it to a text representation.
dataframe_to_text(dataframe)
dataframe_to_text(dataframe)
dataframe |
A dataframe to be converted. |
A character vector representing the dataframe in text format.
dataframe <- data.frame( Name = c("John", "Alice", "Bob"), Age = c(25, 30, 22), Score = c(95, 88, 75) ) dataframe_to_text(dataframe)
dataframe <- data.frame( Name = c("John", "Alice", "Bob"), Age = c(25, 30, 22), Score = c(95, 88, 75) ) dataframe_to_text(dataframe)
This function sends a user input to the OpenAI Chat API and retrieves a response.
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 )
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 )
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. |
A list containing the response from the OpenAI Chat API.
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")
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")