Skip to content

Commit

Permalink
💜
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Feb 10, 2024
1 parent 02be816 commit 3fe1b6e
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 4 deletions.
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(prompt)
export(roses)
importFrom(glue,glue)
importFrom(openai,create_chat_completion)
51 changes: 51 additions & 0 deletions R/roses.R
Original file line number Diff line number Diff line change
@@ -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}')
}
34 changes: 34 additions & 0 deletions man/roses.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/testthat/test-love.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("1 + 1", {
expect_equal(1 + 1, 2)
})

0 comments on commit 3fe1b6e

Please sign in to comment.