Skip to content

Commit

Permalink
Merge pull request #13 from edgararuiz/updates
Browse files Browse the repository at this point in the history
Converts site to quarto
  • Loading branch information
edgararuiz committed Sep 20, 2024
2 parents d99a4ea + 9badf2b commit 1499b5c
Show file tree
Hide file tree
Showing 57 changed files with 17,506 additions and 180 deletions.
7 changes: 7 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ utils/
^_mall_cache/
^_readme_cache/
^_prompt_cache/
^_freeze/
^_quarto.yml
^articles/
^index.qmd
^reference/
^.*\.scss$
^.quarto
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ vignettes/*.pdf
# R Environment Variables
.Renviron

# pkgdown site
docs/

# translation temp files
po/*~

# RStudio Connect folder
rsconnect/
docs

/.quarto/

_freeze/

61 changes: 1 addition & 60 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
eval = TRUE
out.width = "100%"
)
library(dplyr)
library(dbplyr)
Expand All @@ -28,29 +27,6 @@ mall::llm_use("ollama", "llama3.1", seed = 100, .cache = "_readme_cache")
[![Codecov test coverage](https://codecov.io/gh/edgararuiz/mall/branch/main/graph/badge.svg)](https://app.codecov.io/gh/edgararuiz/mall?branch=main)
<!-- badges: end -->

```{r, eval = FALSE, echo = FALSE}
source("utils/table_of_contents.R")
table_of_contents()
```


<!-- toc: start -->
- [Motivation](#motivation)
- [LLM functions](#llm-functions)
- [Sentiment](#sentiment)
- [Summarize](#summarize)
- [Classify](#classify)
- [Extract ](#extract)
- [Translate](#translate)
- [Custom prompt](#custom-prompt)
- [Initialize session](#initialize-session)
- [Key considerations](#key-considerations)
- [Performance](#performance)
- [Vector functions](#vector-functions)
- [Databricks](#databricks)

<!-- toc: end -->

## Intro

Run multiple LLM predictions against a table. The predictions run row-wise
Expand Down Expand Up @@ -347,38 +323,3 @@ llm_vec_sentiment("I am happy")
```{r}
llm_vec_translate("Este es el mejor dia!", "english")
```

## Databricks

This brief example shows how seamless it is to use the same `llm_` functions,
but against a remote connection:

```{r}
library(DBI)
con <- dbConnect(
odbc::databricks(),
HTTPPath = Sys.getenv("DATABRICKS_PATH")
)
tbl_reviews <- copy_to(con, reviews)
```
As mentioned above, using `llm_sentiment()` in Databricks will call that vendor's
SQL AI function directly:

```{r}
tbl_reviews |>
llm_sentiment(review)
```

There are some differences in the arguments, and output of the LLM's. Notice
that instead of "neutral", the prediction is "mixed". The AI Sentiment function
does not allow to change the possible options.

Next, we will try `llm_summarize()`. The `max_words` argument maps to the same
argument in the AI Summarize function:

```{r}
tbl_reviews |>
llm_summarize(review, max_words = 5)
```
68 changes: 0 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@ experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](h
coverage](https://codecov.io/gh/edgararuiz/mall/branch/main/graph/badge.svg)](https://app.codecov.io/gh/edgararuiz/mall?branch=main)
<!-- badges: end -->

<!-- toc: start -->

- [Motivation](#motivation)
- [LLM functions](#llm-functions)
- [Sentiment](#sentiment)
- [Summarize](#summarize)
- [Classify](#classify)
- [Extract](#extract)
- [Translate](#translate)
- [Custom prompt](#custom-prompt)
- [Initialize session](#initialize-session)
- [Key considerations](#key-considerations)
- [Performance](#performance)
- [Vector functions](#vector-functions)
- [Databricks](#databricks)

<!-- toc: end -->

## Intro

Run multiple LLM predictions against a table. The predictions run
Expand Down Expand Up @@ -390,53 +372,3 @@ llm_vec_sentiment("I am happy")
llm_vec_translate("Este es el mejor dia!", "english")
#> [1] "This is the best day!"
```

## Databricks

This brief example shows how seamless it is to use the same `llm_`
functions, but against a remote connection:

``` r
library(DBI)

con <- dbConnect(
odbc::databricks(),
HTTPPath = Sys.getenv("DATABRICKS_PATH")
)

tbl_reviews <- copy_to(con, reviews)
```

As mentioned above, using `llm_sentiment()` in Databricks will call that
vendor’s SQL AI function directly:

``` r
tbl_reviews |>
llm_sentiment(review)
#> # Source: SQL [3 x 2]
#> # Database: Spark SQL 3.1.1[token@Spark SQL/hive_metastore]
#> review .sentiment
#> <chr> <chr>
#> 1 This has been the best TV Ive ever used. Great screen, and sound. positive
#> 2 I regret buying this laptop. It is too slow and the keyboard is to… negative
#> 3 Not sure how to feel about my new washing machine. Great color, bu… mixed
```

There are some differences in the arguments, and output of the LLM’s.
Notice that instead of “neutral”, the prediction is “mixed”. The AI
Sentiment function does not allow to change the possible options.

Next, we will try `llm_summarize()`. The `max_words` argument maps to
the same argument in the AI Summarize function:

``` r
tbl_reviews |>
llm_summarize(review, max_words = 5)
#> # Source: SQL [3 x 2]
#> # Database: Spark SQL 3.1.1[token@Spark SQL/hive_metastore]
#> review .summary
#> <chr> <chr>
#> 1 This has been the best TV Ive ever used. Great screen, and sound. Superio…
#> 2 I regret buying this laptop. It is too slow and the keyboard is too … Slow, n…
#> 3 Not sure how to feel about my new washing machine. Great color, but … Initial…
```
39 changes: 39 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
project:
type: website
output-dir: docs

execute:
freeze: true

website:
title: mall
navbar:
left:
- sidebar:articles
- href: reference/index.qmd
text: Reference
sidebar:
- id: articles
title: "Articles"
style: "docked"
background: light
collapse-level: 2
contents:
- text: "Databricks"
href: articles/databricks.qmd

format:
html:
toc: true
code-copy: true
code-overflow: wrap
code-toos: true
eval: false
theme:
light: [cosmo, theme.scss]
dark: [cosmo, theme-dark.scss]

knitr:
opts_chunk:
collapse: true
comment: "#>"
64 changes: 64 additions & 0 deletions articles/databricks.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: "Databricks"
---


```{r, include = FALSE}
packageStartupMessage(library(dplyr))
```

This brief example shows how seamless it is to use the same functions,
but against a remote database connection. Today, it works with the following
functions:

- `llm_sentiment()` / `llm_vec_sentiment()`
- `llm_summarize()` / `llm_vec_summarize()`

## Examples

We will start by connecting to the Databricks Warehouse

```{r}
library(mall)
library(DBI)
con <- dbConnect(
odbc::databricks(),
HTTPPath = Sys.getenv("DATABRICKS_PATH")
)
```

Next, we will create a small reviews table

```{r}
library(dplyr)
reviews <- tribble(
~review,
"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"
)
tbl_reviews <- copy_to(con, reviews)
```

Using `llm_sentiment()` in Databricks will call that vendor's SQL AI function
directly:

```{r}
tbl_reviews |>
llm_sentiment(review)
```

There are some differences in the arguments, and output of the LLM's. Notice
that instead of "neutral", the prediction is "mixed". The AI Sentiment function
does not allow to change the possible options.

Next, we will try `llm_summarize()`. The `max_words` argument maps to the same
argument in the AI Summarize function:

```{r}
tbl_reviews |>
llm_summarize(review, max_words = 5)
```
Loading

0 comments on commit 1499b5c

Please sign in to comment.