Skip to content

Commit

Permalink
Merge pull request #15 from edgararuiz/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
edgararuiz authored Sep 23, 2024
2 parents 6d08870 + 75a0bfd commit dc2734c
Show file tree
Hide file tree
Showing 48 changed files with 612 additions and 114 deletions.
2 changes: 1 addition & 1 deletion R/llm-classify.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#' c("urgent", "not urgent")
#' )
#'
#' #' # For character vectors, instead of a data frame, use this function
#' # To preview the first call that will be made to the downstream R function
#' llm_vec_classify(
#' c("this is important!", "just whenever"),
#' c("urgent", "not urgent"),
Expand Down
23 changes: 23 additions & 0 deletions R/llm-custom.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@
#' @param valid_resps If the response from the LLM is not open, but
#' deterministic, provide the options in a vector. This function will set to
#' `NA` any response not in the options
#' @examples
#' \dontrun{
#' library(mall)
#'
#' llm_use("ollama", "llama3.1", seed = 100, .silent = TRUE)
#'
#' reviews <- data.frame(review = c(
#' "This has been the best TV I've ever used. Great screen, and sound.",
#' "I regret buying this laptop. It is too slow and the keyboard is too noisy",
#' "Not sure how to feel about my new washing machine. Great color, but hard to figure"
#' ))
#'
#' my_prompt <- paste(
#' "Answer a question.",
#' "Return only the answer, no explanation",
#' "Acceptable answers are 'yes', 'no'",
#' "Answer this about the following text, is this a happy customer?:"
#' )
#'
#' reviews |>
#' llm_custom(review, my_prompt)
#'
#' }
#' @returns `llm_custom` returns a `data.frame` or `tbl` object.
#' `llm_vec_custom` returns a vector that is the same length as `x`.
#' @export
Expand Down
43 changes: 43 additions & 0 deletions R/llm-extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,49 @@
#' `labels` is a named vector, this function will use those names as the
#' new column names, if not, the function will use a sanitized version of
#' the content as the name.
#' @examples
#' \dontrun{
#' library(mall)
#'
#' llm_use("ollama", "llama3.1", seed = 100, .silent = TRUE)
#'
#' reviews <- data.frame(review = c(
#' "This has been the best TV I've ever used. Great screen, and sound.",
#' "I regret buying this laptop. It is too slow and the keyboard is too noisy",
#' "Not sure how to feel about my new washing machine. Great color, but hard to figure"
#' ))
#'
#' # Use 'labels' to let the function know what to extract
#' llm_extract(reviews, review, labels = "product")
#'
#' # Use 'pred_name' to customize the new column's name
#' llm_extract(reviews, review, "product", pred_name = "prod")
#'
#' # Pass a vector to request multiple things, the results will be pipe delimeted
#' # in a single column
#' llm_extract(reviews, review, c("product", "feelings"))
#'
#' # To get multiple columns, use 'expand_cols'
#' llm_extract(reviews, review, c("product", "feelings"), expand_cols = TRUE)
#'
#' # Pass a named vector to set the resulting column names
#' llm_extract(
#' .data = reviews,
#' col = review,
#' labels = c(prod = "product", feels = "feelings"),
#' expand_cols = TRUE
#' )
#'
#' # For character vectors, instead of a data frame, use this function
#' llm_vec_extract("bob smith, 123 3rd street", c("name", "address"))
#'
#' # To preview the first call that will be made to the downstream R function
#' llm_vec_extract(
#' "bob smith, 123 3rd street",
#' c("name", "address"),
#' preview = TRUE
#' )
#' }
#' @returns `llm_extract` returns a `data.frame` or `tbl` object.
#' `llm_vec_extract` returns a vector that is the same length as `x`.
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/llm-sentiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' # For character vectors, instead of a data frame, use this function
#' llm_vec_sentiment(c("I am happy", "I am sad"))
#'
#' #' # For character vectors, instead of a data frame, use this function
#' # To preview the first call that will be made to the downstream R function
#' llm_vec_sentiment(c("I am happy", "I am sad"), preview = TRUE)
#'
#' }
Expand Down
31 changes: 31 additions & 0 deletions R/llm-summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@
#' @inheritParams llm_classify
#' @param max_words The maximum number of words that the LLM should use in the
#' summary. Defaults to 10.
#' @examples
#' \dontrun{
#' library(mall)
#'
#' llm_use("ollama", "llama3.1", seed = 100, .silent = TRUE)
#'
#' reviews <- data.frame(review = c(
#' "This has been the best TV I've ever used. Great screen, and sound.",
#' "I regret buying this laptop. It is too slow and the keyboard is too noisy",
#' "Not sure how to feel about my new washing machine. Great color, but hard to figure"
#' ))
#'
#' # Use max_words to set the maximum number of words to use for the summary
#' llm_summarize(reviews, review, max_words = 5)
#'
#' # Use 'pred_name' to customize the new column's name
#' llm_summarize(reviews, review, 5, pred_name = "review_summary")
#'
#' # For character vectors, instead of a data frame, use this function
#' llm_vec_summarize(
#' "This has been the best TV I've ever used. Great screen, and sound.",
#' max_words = 5
#' )
#'
#' # To preview the first call that will be made to the downstream R function
#' llm_vec_summarize(
#' "This has been the best TV I've ever used. Great screen, and sound.",
#' max_words = 5,
#' preview = TRUE
#' )
#' }
#' @returns `llm_summarize` returns a `data.frame` or `tbl` object.
#' `llm_vec_summarize` returns a vector that is the same length as `x`.
#' @export
Expand Down
16 changes: 16 additions & 0 deletions R/llm-translate.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
#'
#' @inheritParams llm_classify
#' @param language Target language to translate the text to
#' @examples
#' \dontrun{
#' library(mall)
#'
#' llm_use("ollama", "llama3.1", seed = 100, .silent = TRUE)
#'
#' reviews <- data.frame(review = c(
#' "This has been the best TV I've ever used. Great screen, and sound.",
#' "I regret buying this laptop. It is too slow and the keyboard is too noisy",
#' "Not sure how to feel about my new washing machine. Great color, but hard to figure"
#' ))
#'
#' # Pass the desired language to translate to
#' llm_translate(reviews, review, "spanish")
#'
#' }
#' @returns `llm_translate` returns a `data.frame` or `tbl` object.
#' `llm_vec_translate` returns a vector that is the same length as `x`.
#' @export
Expand Down
25 changes: 24 additions & 1 deletion R/llm-use.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,30 @@
#' the same operation is ran again. To turn off, set this argument to an empty
#' character: `""`. 'It defaults to '_mall_cache'. If this argument is left
#' `NULL` when calling this function, no changes to the path will be made.
#'
#' @examples
#' \dontrun{
#' library(mall)
#'
#' llm_use("ollama", "llama3.1")
#'
#' # Additional arguments will be passed 'as-is' to the
#' # downstream R function in this example, to ollama::chat()
#' llm_use("ollama", "llama3.1", seed = 100, temp = 0.1)
#'
#' # During the R session, you can change any argument
#' # individually and it will retain all of previous
#' # arguments used
#' llm_use(temp = 0.3)
#'
#' # Use .cache to modify the target folder for caching
#' llm_use(.cache = "_my_cache")
#'
#' # Leave .cache empty to turn off this functionality
#' llm_use(.cache = "")
#'
#' # Use .silent to avoid the print out
#' llm_use(.silent = TRUE)
#' }
#' @returns A `mall_session` object
#'
#' @export
Expand Down
6 changes: 3 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ library(dplyr)
library(dbplyr)
library(tictoc)
library(DBI)
source("utils/knitr-print.R")
mall::llm_use("ollama", "llama3.1", seed = 100, .cache = "_readme_cache")
```

# mall

<img src="man/figures/favicon/apple-touch-icon-180x180.png" style="float:right" />

<!-- badges: start -->
[![R-CMD-check](https://github.com/edgararuiz/mall/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/edgararuiz/mall/actions/workflows/R-CMD-check.yaml)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![Codecov test coverage](https://codecov.io/gh/edgararuiz/mall/branch/main/graph/badge.svg)](https://app.codecov.io/gh/edgararuiz/mall?branch=main)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->

## Intro
Expand Down
Loading

0 comments on commit dc2734c

Please sign in to comment.