Skip to content

Commit 3d24c96

Browse files
authored
Merge pull request #45 from mlverse/updates
Fixes #43
2 parents 9997c10 + 8c18aca commit 3d24c96

9 files changed

Lines changed: 69 additions & 44 deletions

File tree

.gitignore

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,39 @@
11
# History files
22
.Rhistory
33
.Rapp.history
4-
54
# Session Data files
65
.RData
76
.RDataTmp
8-
97
# User-specific files
108
.Ruserdata
11-
129
# Example code in package build process
1310
*-Ex.R
14-
1511
# Output files from R CMD build
1612
/*.tar.gz
17-
1813
# Output files from R CMD check
1914
/*.Rcheck/
20-
2115
# RStudio files
2216
.Rproj.user/
23-
2417
# produced vignettes
2518
vignettes/*.html
2619
vignettes/*.pdf
27-
2820
# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
2921
.httr-oauth
30-
3122
# knitr and R markdown default cache directories
3223
*_cache/
3324
/cache/
34-
3525
# Temporary files created by R markdown
3626
*.utf8.md
3727
*.knit.md
38-
3928
# R Environment Variables
4029
.Renviron
41-
42-
4330
# translation temp files
4431
po/*~
45-
4632
rsconnect/
47-
4833
/.quarto/
49-
5034
docs/
51-
5235
python/mall/src/
5336
python/assets/style.css
54-
5537
python/README_files
5638
python/README.html
39+
mall.Rproj

r/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: mall
22
Title: Run Multiple Large Language Model Predictions Against a Table, or
33
Vectors
4-
Version: 0.1.9000
4+
Version: 0.1.9001
55
Authors@R: c(
66
person("Edgar", "Ruiz", , "edgar@posit.co", role = c("aut", "cre")),
77
person(given = "Posit Software, PBC", role = c("cph", "fnd"))

r/NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# mall (dev)
22

3-
* Adds new LLM Simulate mode for testing. With "text", you can pass a custom
4-
return message by using the `text` argument.
3+
* Returns a warning when there are over 4,096 tokens in one or many records
4+
sent to Ollama (#43)
55

66
# mall 0.1.0
77

r/R/m-backend-submit.R

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,25 @@ m_backend_submit.mall_ollama <- function(backend, x, prompt, preview = FALSE) {
2323
} else {
2424
map_here <- map_chr
2525
}
26-
map_here(
26+
warnings <- NULL
27+
out <- map_here(
2728
x,
2829
\(x) {
2930
.args <- c(
30-
messages = list(map(prompt, \(i) map(i, \(j) glue(j, x = x)))),
31+
messages = list(
32+
map(prompt, \(i)
33+
map(i, \(j) {
34+
out <- glue(j, x = x)
35+
ln <- length(unlist(strsplit(out, " ")))
36+
if (ln > warn_tokens()) {
37+
warnings <<- c(
38+
warnings,
39+
list(list(row = substr(x, 1, 20), len = ln))
40+
)
41+
}
42+
out
43+
}))
44+
),
3145
output = "text",
3246
m_defaults_args(backend)
3347
)
@@ -46,6 +60,27 @@ m_backend_submit.mall_ollama <- function(backend, x, prompt, preview = FALSE) {
4660
res
4761
}
4862
)
63+
if (!is.null(warnings)) {
64+
warn_len <- length(warnings)
65+
cli_alert_warning(c(
66+
"{warn_len} record{?s} may be over {warn_tokens()} tokens\n",
67+
"Ollama may have truncated what was sent to the model \n",
68+
"(https://github.com/ollama/ollama/issues/7043)"
69+
))
70+
limit <- 10
71+
limit <- ifelse(limit > warn_len, warn_len, limit)
72+
warn_text <- map(warnings[1:limit], \(x) paste0(x[["row"]], "..."))
73+
cli_bullets(set_names(warn_text, "*"))
74+
if (warn_len > limit) {
75+
cli_inform(c("i" = "{warn_len - limit} more record{?s}"))
76+
}
77+
}
78+
out
79+
}
80+
81+
# Using a function so that it can be mocked in testing
82+
warn_tokens <- function() {
83+
4096
4984
}
5085

5186
#' @export
@@ -61,8 +96,6 @@ m_backend_submit.mall_simulate_llm <- function(backend,
6196
out <- x
6297
} else if (args$model == "prompt") {
6398
out <- prompt
64-
} else if (args$model == "text") {
65-
out <- args$text
6699
}
67100
res <- NULL
68101
if (m_cache_use()) {

r/codecov.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Ollama code is covered
2+
3+
Code
4+
llm_vec_sentiment("I am happy")
5+
Message
6+
! 1 record may be over 10 tokens
7+
Ollama may have truncated what was sent to the model
8+
(https://github.com/ollama/ollama/issues/7043)
9+
* I am happy...
10+
Output
11+
[1] "positive"
12+

r/tests/testthat/helper-ollama.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ skip_if_no_ollama <- function() {
2727
seed = 100,
2828
.silent = TRUE,
2929
.force = TRUE,
30-
.cache = .mall_test$cache_ollama
30+
.cache = .mall_test$cache_ollama
3131
)
3232
}
3333
}

r/tests/testthat/test-m-backend-submit.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ test_that("Ollama code is covered", {
99
)
1010
})
1111

12+
test_that("Ollama code is covered", {
13+
local_mocked_bindings(
14+
warn_tokens = function() 10,
15+
chat = function(...) "positive"
16+
)
17+
llm_use("ollama", "llama3.2", .silent = TRUE, .force = TRUE)
18+
expect_snapshot(
19+
llm_vec_sentiment("I am happy")
20+
)
21+
})
22+
1223
test_that("No cache is saved if turned off", {
1324
llm_use("simulate_llm", "echo", .silent = TRUE, .force = TRUE, .cache = "")
1425
expect_equal(

r/tests/testthat/test-zzz-cache.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
test_that("Ollama cache exists and delete", {
22
skip_if_no_ollama()
3-
expect_equal(
4-
length(fs::dir_ls(.mall_test$cache_ollama , recurse = TRUE)),
5-
59
3+
expect_gt(
4+
length(fs::dir_ls(.mall_test$cache_ollama, recurse = TRUE)),
5+
30
66
)
7-
fs::dir_delete(.mall_test$cache_ollama )
7+
fs::dir_delete(.mall_test$cache_ollama)
88
})

0 commit comments

Comments
 (0)