lang_use: Specifies the LLM provider and model to use during the R...

View source: R/lang-use.R

lang_useR Documentation

Specifies the LLM provider and model to use during the R session

Description

Specifies the back-end provider and model to use during the current R session. The target language is not processed by the function, as in converting "english" to "en" for example. The value is passed directly to the LLM, and it lets the LLM interpret the target language.

Usage

lang_use(
  backend = NULL,
  model = NULL,
  .cache = NULL,
  .lang = NULL,
  .context_size = NULL,
  .silent = FALSE,
  ...
)

Arguments

backend

"ollama" or an ellmer Chat object. If using "ollama", lang provides built-in support via the ollamar package. Defaults to "ollama".

model

The name of model supported by the back-end provider

.cache

Character path where translations are cached. Set to "" to disable caching. When NULL, the current session value is kept unchanged. Defaults to a temporary folder.

.lang

Target language to translate to. This will override values found in the LANG and LANGUAGE environment variables.

.context_size

Maximum number of words for the context summary included with each translation request. Set to 0 to disable context-aware translation. Defaults to 100.

.silent

Boolean flag that controls whether there is output to the console. Defaults to FALSE.

...

Additional arguments that this function will pass down to the integrating function. In the case of Ollama, it will pass those arguments to ollamar::chat().

Value

Invisibly returns NULL. Prints the current configuration to the console.

Examples

## Not run: 
# Requires an interactive session with Ollama or another LLM provider
library(lang)

# Using an `ellmer` chat object
lang_use(ellmer::chat_openai(model = "gpt-4o"))

# Using Ollama directly
lang_use("ollama", "llama3.2", seed = 100)

# Turn off cache by setting `.cache` to ""
lang_use("ollama", "llama3.2", seed = 100, .cache = "")

# Use `.lang` to set the target language to translate to,
# it will be set for the current R session
lang_use("ollama", "llama3.2", .lang = "spanish")

# Use `.silent` to avoid console output
lang_use("ollama", "llama3.2", .lang = "spanish", .silent = TRUE)

# To see current settings, simply call the function
lang_use()

## End(Not run)


lang documentation built on June 5, 2026, 5:08 p.m.