R/nameIt.R

Defines functions nameIt

Documented in nameIt

#' 'Groq': Create a Function or Variable Name
#'
#' @param code The code for which to give a variable name to its result.
#' If not provided, it will use what's copied on the clipboard.
#' @param namingConvention Defaults to "camelCase".
#' @param ... Following arguments can be set manually or in .Renviron:
#'            `GROQ_API_KEY`is the 'Groq API' key.
#'            `model` Model choice. Default is mistral-7b-instruct.
#'            `systemRole` System role; Default is: "You are a helpful assistant
#'            with extensive knowledge of R programming."
#'            `maxTokens` The maximum integer of completion tokens returned.
#'            `temperature` The amount of randomness in the response,
#'            valued between 0 inclusive and 2 exclusive. Higher values are more
#'            random, and lower values are more deterministic.
#'            `top_p` Nucleus sampling threshold, valued between 0 and 1.
#'            `proxy` Default value is NULL.
#'
#'
#' @examples
#' \dontrun{
#' cat(nameIt("sapply(1:10, function(i) i ** 2)"))
#' }
#'
#' @importFrom clipr read_clip
#'
#' @return A character value with the response generated by 'Groq'.
#'
#' @export
#'
nameIt <- function(code = NULL, namingConvention = "camelCase", ...) {
  if (is.null(code)) code <- clipr::read_clip(allow_non_interactive = TRUE)
  # Replace all double strings with single string
  code <- gsub('"', "'", code)
  # Collapse the modified 'code' into a character vector
  code <- paste(code, collapse = "\n")
  # Create a prompt string by concatenating the input code
  prompt <- paste0(
    'Return a good, memorizable, short variable name to
    the result of the following code: "',
    code, '" Consider the following programming naming convention: ',
    namingConvention
  )





  return(APIcall(prompt, ...))
}

Try the groqR package in your browser

Any scripts or data that you put into this service are public.

groqR documentation built on April 12, 2025, 1:36 a.m.