Skip to contents

Asks the model you set up (see morie_llm_detect_provider) through rmoriebricklayer. With docs = TRUE the model is given the help of rmorie, rmoriebricklayer and rmoriedata (rmorie's own thousands of pages are searched, the functions nearest the question listed) and tools to read it, so it can name the right function and its arguments. When no model is set up, or the automatic route fails, the answer is a short text saying how to set one up (with attr(, "fallback") TRUE); a route you named is an error instead.

Usage

morie_llm_ask(
  prompt,
  context = NULL,
  model = NULL,
  provider = NULL,
  system_prompt = NULL,
  timeout = 120,
  route = NULL,
  docs = TRUE
)

Arguments

prompt

User question or instruction.

context

Optional named list (or text) given with the question.

model

Optional model name; the route's model when NULL.

provider

Older name for route ("api" is "own").

system_prompt

Optional instructions added for the model.

timeout

Seconds to wait for each reply. Default 120.

route

NULL (the saved setting, else the automatic order), "auto", "own", "ollama" or a provider id such as "anthropic": a route other than auto is the only one asked.

docs

TRUE (default) to give the model the packages' help.

Value

Character scalar: the answer, or the fallback text.

Examples

old <- Sys.getenv(c("OLLAMA_HOST", "XDG_CONFIG_HOME"), unset = NA)
Sys.setenv(OLLAMA_HOST = "off", XDG_CONFIG_HOME = tempfile())
out <- morie_llm_ask("In one word, what is 2 + 2?")
isTRUE(attr(out, "fallback"))
#> [1] TRUE
for (v in names(old)) if (is.na(old[[v]])) Sys.unsetenv(v) else do.call(Sys.setenv, as.list(old[v]))
if (FALSE) { # \dontrun{
Sys.setenv(ANTHROPIC_API_KEY = "...")
morie_llm_ask("Which rmorie function fits a staggered difference-in-differences design?")
} # }