@@ -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()) {
0 commit comments