Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion r/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mall
Title: Run Multiple Large Language Model Predictions Against a Table, or
Vectors
Version: 0.2.0
Version: 0.2.0.9000
Authors@R: c(
person("Edgar", "Ruiz", , "edgar@posit.co", role = c("aut", "cre")),
person(given = "Posit Software, PBC", role = c("cph", "fnd"))
Expand Down
4 changes: 4 additions & 0 deletions r/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# mall (dev)

* Fix for missing content when using custom prompt with Ollama directly (#62)

# mall 0.2.0

* Adds integration with `ellmer` `Chat` objects
Expand Down
2 changes: 2 additions & 0 deletions r/R/llm-custom.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ llm_custom.data.frame <- function(.data,
llm_vec_custom <- function(x, prompt = "", valid_resps = NULL) {
m_vec_prompt(
x = x,
prompt_label = "custom",
prompt = prompt,
custom_prompt = prompt,
valid_resps = valid_resps
)
}
12 changes: 12 additions & 0 deletions r/R/m-backend-prompt.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ m_backend_prompt.mall_ollama <- function(backend, additional = "") {
additional,
"The answer is based on the following text:\n{{x}}"
))
next_method$custom <- function(custom_prompt) {
glue(paste(
"{custom_prompt}",
"{additional}"
))
}
next_method
}

Expand All @@ -22,6 +28,12 @@ m_backend_prompt.mall_ellmer <- function(backend, additional = "") {
"The answer will be based on each individual prompt.",
"Treat each prompt as unique when deciding the answer."
))
next_method$custom <- function(custom_prompt) {
glue(paste(
"{custom_prompt}",
"{additional}"
))
}
next_method
}

Expand Down
19 changes: 10 additions & 9 deletions r/R/m-vec-prompt.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ m_vec_prompt <- function(x,
...) {
# Initializes session LLM
backend <- llm_use(.silent = TRUE, .force = FALSE)
# If there is no 'prompt', then assumes that we're looking for a
# prompt label (sentiment, classify, etc) to set 'prompt'
if (is.null(prompt)) {
defaults <- m_backend_prompt(
backend = backend,
additional = additional_prompt
)
fn <- defaults[[prompt_label]]
prompt <- fn(...)

# Builds the prompt and will be sent to the LLM
defaults <- m_backend_prompt(
backend = backend,
additional = additional_prompt
)
fn <- defaults[[prompt_label]]
if(!is.null(fn)) {
prompt <- fn(...)
}

# Submits final prompt to the LLM
resp <- m_backend_submit(
backend = backend,
Expand Down
2 changes: 1 addition & 1 deletion r/tests/testthat/_snaps/llm-custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
2 I regret buying this laptop. It is too slow and the keyboard is too noisy
3 Not sure how to feel about my new washing machine. Great color, but hard to figure
.pred
1 No
1 Yes
2 No
3 No