-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02be816
commit 3fe1b6e
Showing
5 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}') | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test_that("1 + 1", { | ||
expect_equal(1 + 1, 2) | ||
}) |