diff --git a/NAMESPACE b/NAMESPACE index 7d183576e..69f15bf34 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,14 +23,6 @@ export(cache_exists) export(cache_read) export(cache_write) export(categ_reducer) -export(chatgpt_ask) -export(chatgpt_classify) -export(chatgpt_convert) -export(chatgpt_extract) -export(chatgpt_format) -export(chatgpt_table) -export(chatgpt_tag) -export(chatgpt_translate) export(check_attr) export(check_opts) export(ci_lower) @@ -95,6 +87,14 @@ export(gg_fill_customs) export(gg_text_customs) export(gg_vals) export(glued) +export(gpt_ask) +export(gpt_classify) +export(gpt_convert) +export(gpt_extract) +export(gpt_format) +export(gpt_table) +export(gpt_tag) +export(gpt_translate) export(grepl_letters) export(grepm) export(gtrends_related) diff --git a/R/chatgpt.R b/R/chatgpt.R index ca88c25ff..25cc773a0 100644 --- a/R/chatgpt.R +++ b/R/chatgpt.R @@ -18,40 +18,40 @@ #' \dontrun{ #' api_key <- get_credentials()$openai$secret_key #' # Open question: -#' chatgpt_ask("Can you write an R function to plot a dummy histogram?", api_key) +#' gpt_ask("Can you write an R function to plot a dummy histogram?", api_key) #' #' ##### The following examples return dataframes: #' # Classify each element based on categories: -#' chatgpt_classify(1:10, c("odd", "even")) +#' gpt_classify(1:10, c("odd", "even")) #' #' # Add all tags that apply to each element based on tags: -#' chatgpt_tag( +#' gpt_tag( #' c("I love chocolate", "I hate chocolate", "I like Coke"), #' c("food", "positive", "negative", "beverage")) #' #' # Extract specific information: -#' chatgpt_extract( +#' gpt_extract( #' c("My mail is 123@@test.com", "30 Main Street, Brooklyn, NY, USA", "+82 2-312-3456", "$1.5M"), #' c("email", "full state name", "country of phone number", "amount as number")) #' #' # Format values -#' chatgpt_format( +#' gpt_format( #' c("March 27th, 2021", "12-25-2023 3:45PM", "01.01.2000", "29 Feb 92"), #' format = "ISO Date getting rid of timestamps") #' #' # Convert units -#' chatgpt_convert(c("50C", "300K"), "Fahrenheit") +#' gpt_convert(c("50C", "300K"), "Fahrenheit") #' #' # Create a table with data -#' chatgpt_table("5 random people's address in South America, email, phone, age between 18-30") +#' gpt_table("5 random people's address in South America, email, phone, age between 18-30") #' #' # Translate text to any language -#' chatgpt_translate( +#' gpt_translate( #' rep("I love you with all my heart", 5), #' language = c("spanish", "chinese", "japanese", "russian", "german")) #' } #' @export -chatgpt_ask <- function(ask, +gpt_ask <- function(ask, secret_key = get_credentials()$openai$secret_key, url = "https://api.openai.com/v1/chat/completions", model = "gpt-3.5-turbo", @@ -79,20 +79,20 @@ chatgpt_ask <- function(ask, #' @param x Vector. List items you wish to process #' @param categories,tags Vector. List of possible categories/tags to consider. -#' @rdname chatgpt_ask +#' @rdname gpt_ask #' @export -chatgpt_classify <- function(x, categories, quiet = TRUE, ...) { +gpt_classify <- function(x, categories, quiet = TRUE, ...) { prompt <- gpt_prompt_builder("category", x = x, y = categories) - resp <- chatgpt_ask(prompt, quiet = quiet, ...) + resp <- gpt_ask(prompt, quiet = quiet, ...) df <- gpt_markdown2df(resp) return(df) } -#' @rdname chatgpt_ask +#' @rdname gpt_ask #' @export -chatgpt_tag <- function(x, tags, quiet = TRUE, ...) { +gpt_tag <- function(x, tags, quiet = TRUE, ...) { prompt <- gpt_prompt_builder("tags", x = x, y = tags) - resp <- chatgpt_ask(prompt, quiet = quiet, ...) + resp <- gpt_ask(prompt, quiet = quiet, ...) df <- gpt_markdown2df(resp) return(df) } @@ -100,52 +100,52 @@ chatgpt_tag <- function(x, tags, quiet = TRUE, ...) { #' @param extract,format,unit Character. Length 1 or same as x to extract/format/unit #' information from x. For example: email, country of phone number, country, amount as number, #' currency ISO code, ISO, Fahrenheit, etc. -#' @rdname chatgpt_ask +#' @rdname gpt_ask #' @export -chatgpt_extract <- function(x, extract, quiet = TRUE, ...) { +gpt_extract <- function(x, extract, quiet = TRUE, ...) { stopifnot(length(extract) %in% c(1, length(x))) prompt <- gpt_prompt_builder("extract", x = x, y = extract, cols = c("item", "extract", "value")) - resp <- chatgpt_ask(prompt, quiet = quiet, ...) + resp <- gpt_ask(prompt, quiet = quiet, ...) df <- gpt_markdown2df(resp) return(df) } -#' @rdname chatgpt_ask +#' @rdname gpt_ask #' @export -chatgpt_format <- function(x, format, quiet = TRUE, ...) { +gpt_format <- function(x, format, quiet = TRUE, ...) { stopifnot(length(format) %in% c(1, length(x))) prompt <- gpt_prompt_builder("format", x = x, y = format) - resp <- chatgpt_ask(prompt, quiet = quiet, ...) + resp <- gpt_ask(prompt, quiet = quiet, ...) df <- gpt_markdown2df(resp) return(df) } -#' @rdname chatgpt_ask +#' @rdname gpt_ask #' @export -chatgpt_convert <- function(x, unit, quiet = TRUE, ...) { +gpt_convert <- function(x, unit, quiet = TRUE, ...) { stopifnot(length(unit) %in% c(1, length(x))) prompt <- gpt_prompt_builder("value", x = x, y = unit) - resp <- chatgpt_ask(prompt, quiet = quiet, ...) + resp <- gpt_ask(prompt, quiet = quiet, ...) df <- gpt_markdown2df(resp) return(df) } -#' @rdname chatgpt_ask +#' @rdname gpt_ask #' @export -chatgpt_table <- function(ask, quiet = TRUE, ...) { +gpt_table <- function(ask, quiet = TRUE, ...) { prompt <- paste("Return a markdown table for:", ask, ". If you don't know any item, replace with NA") - resp <- chatgpt_ask(prompt, quiet = quiet, ...) + resp <- gpt_ask(prompt, quiet = quiet, ...) df <- gpt_markdown2df(resp) return(df) } #' @param language Character. Language to translate to -#' @rdname chatgpt_ask +#' @rdname gpt_ask #' @export -chatgpt_translate <- function(x, language, quiet = TRUE, ...) { +gpt_translate <- function(x, language, quiet = TRUE, ...) { stopifnot(length(language) %in% c(1, length(x))) prompt <- gpt_prompt_builder("translate", x = x, y = language, cols = c("item", "language", "translation")) - resp <- chatgpt_ask(prompt, quiet = quiet, ...) + resp <- gpt_ask(prompt, quiet = quiet, ...) df <- gpt_markdown2df(resp) return(df) } diff --git a/man/bring_api.Rd b/man/bring_api.Rd index 76adb2866..6c775ca0c 100644 --- a/man/bring_api.Rd +++ b/man/bring_api.Rd @@ -56,7 +56,6 @@ Other Tools: \code{\link{what_size}()} Other API: -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, @@ -65,6 +64,7 @@ Other API: \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}, diff --git a/man/fb_accounts.Rd b/man/fb_accounts.Rd index db71db980..34e759864 100644 --- a/man/fb_accounts.Rd +++ b/man/fb_accounts.Rd @@ -45,7 +45,6 @@ accounts <- fb_accounts(YOURTOKEN, YOURBUSINESS) \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, \code{\link{fb_insights}()}, @@ -53,6 +52,7 @@ Other API: \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}, diff --git a/man/fb_ads.Rd b/man/fb_ads.Rd index dc1ffe1ba..422f147e1 100644 --- a/man/fb_ads.Rd +++ b/man/fb_ads.Rd @@ -60,7 +60,6 @@ ads <- fb_ads(token, account, start_date = Sys.Date() - 10) \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_creatives}()}, \code{\link{fb_insights}()}, @@ -68,6 +67,7 @@ Other API: \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}, diff --git a/man/fb_creatives.Rd b/man/fb_creatives.Rd index cee4c469c..a88b6a92a 100644 --- a/man/fb_creatives.Rd +++ b/man/fb_creatives.Rd @@ -40,7 +40,6 @@ creatives <- fb_creatives(token, account) \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_insights}()}, @@ -48,6 +47,7 @@ Other API: \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}, diff --git a/man/fb_insights.Rd b/man/fb_insights.Rd index 3fe88f25c..004a2f457 100644 --- a/man/fb_insights.Rd +++ b/man/fb_insights.Rd @@ -120,7 +120,6 @@ insights_adset <- fb_insights( \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, @@ -128,6 +127,7 @@ Other API: \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}, diff --git a/man/fb_process.Rd b/man/fb_process.Rd index 69fc9b5f7..35e6f4711 100644 --- a/man/fb_process.Rd +++ b/man/fb_process.Rd @@ -30,7 +30,6 @@ querying the API with \code{httr::GET} or by passing an API link. \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, @@ -38,6 +37,7 @@ Other API: \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}, diff --git a/man/fb_report_check.Rd b/man/fb_report_check.Rd index e6540a528..a0d11439d 100644 --- a/man/fb_report_check.Rd +++ b/man/fb_report_check.Rd @@ -48,7 +48,6 @@ fb_report_check(token, report_run_id, live = TRUE, quiet = FALSE) \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, @@ -56,6 +55,7 @@ Other API: \code{\link{fb_process}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}, diff --git a/man/fb_rf.Rd b/man/fb_rf.Rd index 3f9732f1a..17a222be4 100644 --- a/man/fb_rf.Rd +++ b/man/fb_rf.Rd @@ -126,7 +126,6 @@ advanced <- fb_rf(token, account_id, \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, @@ -134,6 +133,7 @@ Other API: \code{\link{fb_process}()}, \code{\link{fb_report_check}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}, diff --git a/man/fb_token.Rd b/man/fb_token.Rd index c4423b4d2..193fe9d95 100644 --- a/man/fb_token.Rd +++ b/man/fb_token.Rd @@ -31,7 +31,6 @@ More info: \href{https://developers.facebook.com/docs/facebook-login/guides/acce \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, @@ -39,6 +38,7 @@ Other API: \code{\link{fb_process}()}, \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}, diff --git a/man/chatgpt_ask.Rd b/man/gpt_ask.Rd similarity index 75% rename from man/chatgpt_ask.Rd rename to man/gpt_ask.Rd index c43fd300d..fbde36140 100644 --- a/man/chatgpt_ask.Rd +++ b/man/gpt_ask.Rd @@ -1,17 +1,17 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/chatgpt.R -\name{chatgpt_ask} -\alias{chatgpt_ask} -\alias{chatgpt_classify} -\alias{chatgpt_tag} -\alias{chatgpt_extract} -\alias{chatgpt_format} -\alias{chatgpt_convert} -\alias{chatgpt_table} -\alias{chatgpt_translate} +\name{gpt_ask} +\alias{gpt_ask} +\alias{gpt_classify} +\alias{gpt_tag} +\alias{gpt_extract} +\alias{gpt_format} +\alias{gpt_convert} +\alias{gpt_table} +\alias{gpt_translate} \title{ChatGPT API Interaction with R} \usage{ -chatgpt_ask( +gpt_ask( ask, secret_key = get_credentials()$openai$secret_key, url = "https://api.openai.com/v1/chat/completions", @@ -20,19 +20,19 @@ chatgpt_ask( ... ) -chatgpt_classify(x, categories, quiet = TRUE, ...) +gpt_classify(x, categories, quiet = TRUE, ...) -chatgpt_tag(x, tags, quiet = TRUE, ...) +gpt_tag(x, tags, quiet = TRUE, ...) -chatgpt_extract(x, extract, quiet = TRUE, ...) +gpt_extract(x, extract, quiet = TRUE, ...) -chatgpt_format(x, format, quiet = TRUE, ...) +gpt_format(x, format, quiet = TRUE, ...) -chatgpt_convert(x, unit, quiet = TRUE, ...) +gpt_convert(x, unit, quiet = TRUE, ...) -chatgpt_table(ask, quiet = TRUE, ...) +gpt_table(ask, quiet = TRUE, ...) -chatgpt_translate(x, language, quiet = TRUE, ...) +gpt_translate(x, language, quiet = TRUE, ...) } \arguments{ \item{ask}{Character. Redacted prompt to ask ChatGPT. If multiple asks are @@ -70,35 +70,35 @@ the rendered reply. \dontrun{ api_key <- get_credentials()$openai$secret_key # Open question: -chatgpt_ask("Can you write an R function to plot a dummy histogram?", api_key) +gpt_ask("Can you write an R function to plot a dummy histogram?", api_key) ##### The following examples return dataframes: # Classify each element based on categories: -chatgpt_classify(1:10, c("odd", "even")) +gpt_classify(1:10, c("odd", "even")) # Add all tags that apply to each element based on tags: -chatgpt_tag( +gpt_tag( c("I love chocolate", "I hate chocolate", "I like Coke"), c("food", "positive", "negative", "beverage")) # Extract specific information: -chatgpt_extract( +gpt_extract( c("My mail is 123@test.com", "30 Main Street, Brooklyn, NY, USA", "+82 2-312-3456", "$1.5M"), c("email", "full state name", "country of phone number", "amount as number")) # Format values -chatgpt_format( +gpt_format( c("March 27th, 2021", "12-25-2023 3:45PM", "01.01.2000", "29 Feb 92"), format = "ISO Date getting rid of timestamps") # Convert units -chatgpt_convert(c("50C", "300K"), "Fahrenheit") +gpt_convert(c("50C", "300K"), "Fahrenheit") # Create a table with data -chatgpt_table("5 random people's address in South America, email, phone, age between 18-30") +gpt_table("5 random people's address in South America, email, phone, age between 18-30") # Translate text to any language -chatgpt_translate( +gpt_translate( rep("I love you with all my heart", 5), language = c("spanish", "chinese", "japanese", "russian", "german")) } diff --git a/man/li_auth.Rd b/man/li_auth.Rd index b25ac03e6..5c2f214f0 100644 --- a/man/li_auth.Rd +++ b/man/li_auth.Rd @@ -23,7 +23,6 @@ API REST \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, @@ -32,6 +31,7 @@ Other API: \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}, \code{\link{slackSend}()} diff --git a/man/li_profile.Rd b/man/li_profile.Rd index d7dc03635..1faef1ac4 100644 --- a/man/li_profile.Rd +++ b/man/li_profile.Rd @@ -18,7 +18,6 @@ This function brings a list with your personal LinkedIn data \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, @@ -27,6 +26,7 @@ Other API: \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{queryGA}()}, \code{\link{slackSend}()} diff --git a/man/queryGA.Rd b/man/queryGA.Rd index 8684cbcaf..ee0f65098 100644 --- a/man/queryGA.Rd +++ b/man/queryGA.Rd @@ -62,7 +62,6 @@ Other Google: Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, @@ -71,6 +70,7 @@ Other API: \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{slackSend}()} diff --git a/man/slackSend.Rd b/man/slackSend.Rd index d22e228cb..0e0e5c69f 100644 --- a/man/slackSend.Rd +++ b/man/slackSend.Rd @@ -34,7 +34,6 @@ slackSend(text = "This is a message", title = "TEST", pretext = Sys.info()["user \seealso{ Other API: \code{\link{bring_api}()}, -\code{\link{chatgpt_ask}()}, \code{\link{fb_accounts}()}, \code{\link{fb_ads}()}, \code{\link{fb_creatives}()}, @@ -43,6 +42,7 @@ Other API: \code{\link{fb_report_check}()}, \code{\link{fb_rf}()}, \code{\link{fb_token}()}, +\code{\link{gpt_ask}()}, \code{\link{li_auth}()}, \code{\link{li_profile}()}, \code{\link{queryGA}()}