From 3fe1b6ef9972b1089f8c896251c6d742350f5f5f Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Sat, 10 Feb 2024 17:52:28 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DESCRIPTION | 10 +++++--- NAMESPACE | 4 +++ R/roses.R | 51 ++++++++++++++++++++++++++++++++++++++ man/roses.Rd | 34 +++++++++++++++++++++++++ tests/testthat/test-love.R | 3 +++ 5 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 R/roses.R create mode 100644 man/roses.Rd create mode 100644 tests/testthat/test-love.R diff --git a/DESCRIPTION b/DESCRIPTION index 2d5ff1d..5565039 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,9 +1,8 @@ Package: valentine -Title: What the Package Does (One Line, Title Case) -Version: 0.0.0.9000 +Title: Spread the love for R packages with poetry +Version: 2014.2.14 Authors@R: - person("First", "Last", , "first.last@example.com", role = c("aut", "cre"), - comment = c(ORCID = "YOUR-ORCID-ID")) + person("Romain", "François", email = "romain@tada.science", role = c("aut", "cre")) Description: What the package does (one paragraph). License: MIT + file LICENSE Suggests: @@ -14,3 +13,6 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 URL: https://github.com/tadascience/valentine, http://tada.science/valentine/ BugReports: https://github.com/tadascience/valentine/issues +Imports: + glue, + openai diff --git a/NAMESPACE b/NAMESPACE index 6ae9268..cf723bd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(prompt) +export(roses) +importFrom(glue,glue) +importFrom(openai,create_chat_completion) diff --git a/R/roses.R b/R/roses.R new file mode 100644 index 0000000..7454498 --- /dev/null +++ b/R/roses.R @@ -0,0 +1,51 @@ +#' Make a roses are red poem +#' +#' Make a "roses are red ..." poem +#' about an R package. +#' +#' @param pkg A package +#' @param hint extra information to add to the prompt +#' @param emoji Should the poem include empojis. +#' @param ... Passed to [openai::create_chat_completion()] +#' +#' @return A poem generated by ChatGPT. +#' +#' @importFrom glue glue +#' @importFrom openai create_chat_completion +#' @examples +#' prompt("dplyr") +#' +#' \dontrun{ +#' roses("dplyr") +#' } +#' @export +roses <- function(pkg, hint = "", emoji = TRUE, ...) { + result <- create_chat_completion( + model = "gpt-3.5-turbo", + messages = list( + list( + "role" = "system", + "content" = "You are helpful assistant" + ), + list( + "role" = "user", + "content" = prompt(pkg, hint, emoji) + ) + ), + ... + )$choices$message.content + + writeLines(result) + invisible(result) +} + +#' @rdname roses +#' @export +prompt <- function(pkg, hint = "", emoji = TRUE) { + emoji_prompt <- if (isTRUE(emoji)) { + "Include a bunch of emojis" + } else { + "Don't include emojis" + } + glue('Make a 4 lines "roses are red ..." poem about the R package "{pkg}". {emoji_prompt}. {hint}') +} diff --git a/man/roses.Rd b/man/roses.Rd new file mode 100644 index 0000000..05a7d5b --- /dev/null +++ b/man/roses.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/roses.R +\name{roses} +\alias{roses} +\alias{prompt} +\title{Make a roses are red poem} +\usage{ +roses(pkg, hint = "", emoji = TRUE, ...) + +prompt(pkg, hint = "", emoji = TRUE) +} +\arguments{ +\item{pkg}{A package} + +\item{hint}{extra information to add to the prompt} + +\item{emoji}{Should the poem include empojis.} + +\item{...}{Passed to \code{\link[openai:create_chat_completion]{openai::create_chat_completion()}}} +} +\value{ +A poem generated by ChatGPT. +} +\description{ +Make a "roses are red ..." poem +about an R package. +} +\examples{ +prompt("dplyr") + +\dontrun{ + roses("dplyr") +} +} diff --git a/tests/testthat/test-love.R b/tests/testthat/test-love.R new file mode 100644 index 0000000..c300f40 --- /dev/null +++ b/tests/testthat/test-love.R @@ -0,0 +1,3 @@ +test_that("1 + 1", { + expect_equal(1 + 1, 2) +})