chatalot processes lots of large language model chats in R and is an extension of ellmer.
Easily setup sequential and parallel chat processors with support for tool calling, structured data extraction, uploaded content, persistent caching, and sound notifications.
From CRAN:
# install.packages("pak") pak::pak("chatalot")
Development version:
pak::pak("dylanpieper/chatalot")
API keys allow access to chat models and are stored as environmental variables. I recommend usethis
to setup API keys in your .Renviron
such as OPENAI_API_KEY=your-key
:
usethis::edit_r_environ(scope = c("user", "project"))
Process chats in sequence, or one at a time. Use this function to process prompts slowly, such as when providers don't allow parallel processing or have strict rate limits, or when you want to periodically check the responses.
library(chatalot) chat <- seq_chat("openai/gpt-4.1", system_prompt = "Reply concisely, one sentence") prompts <- c( "What roles do people have in a castle?", "Why are castles needed?", "When was the first castle built?", "Where are most castles located?" ) response <- chat$process(prompts)
Access the responses:
response$texts() #> [1] "In a castle, people served as rulers, warriors, administrators, #> craftsmen, and servants who managed its defense, governance, and daily upkeep." #> [2] "Castles have historically been built for defense and power consolidation, #> and today they serve as cultural landmarks that preserve our heritage #> and attract tourism." #> [3] "There isn’t a definitive \"first castle,\" but the earliest structures #> resembling castles emerged in medieval Europe around the 9th century." #> [4] "Most castles are located in Europe, particularly in historically #> turbulent regions like the United Kingdom, France, and Germany."
Parallel processing requests multiple chats at a time across multiple R processes using future workers:
chat <- future_chat("openai/gpt-4.1", system_prompt = "Reply concisely, one sentence")
Use this function to process lots of chat prompts simultaneously and quickly. You may want to limit the number of simultaneous requests to meet a provider's rate limits by decreasing the number of workers
(default is parallel::detectCores()
, which is 10 on my Mac Mini M4):
response <- chat$process(prompts, workers = 5)
Register and use tool calling to let the LLM use R functions:
weather <- data.frame( city = c("Chicago", "New York", "Lisbon"), raining = c("Heavy", "None", "Overcast"), temperature = c("Cool", "Hot", "Warm"), wind = c("Strong", "Weak", "Strong") ) get_weather <- tool( function(cities) weather[weather$city %in% cities, ], description = "Report on weather conditions.", arguments = list( cities = type_array(type_string(), "City names") ) ) chat$register_tool(get_weather) response <- chat$process(interpolate("Brief weather update for {{weather$city}}?")) response$texts() #> [1] "Chicago is experiencing heavy rain, cool temperatures, and strong winds." #> [2] "New York is experiencing hot conditions with no rain and light winds." #> [3] "In Lisbon, the weather is overcast with warm temperatures and strong winds."Structured Data Extraction
Extract structured data using type specifications:
prompts <- c( "I go by Alex. 42 years on this planet and counting.", "Pleased to meet you! I'm Jamal, age 27.", "They call me Li Wei. Nineteen years young.", "Fatima here. Just celebrated my 35th birthday last week.", "The name's Robert - 51 years old and proud of it.", "Kwame here - just hit the big 5-0 this year." ) response <- chat$process( prompts, type = type_object( name = type_string(), age = type_number() ) ) response$texts() #> name age #> 1 Alex 42 #> 2 Jamal 27 #> 3 Li Wei 19 #> 4 Fatima 35 #> 5 Robert 51 #> 6 Kwame 50
Process prompts with uploaded content (e.g., images and PDFs):
base_prompt <- "What do you see in the image?" img_prompts <- list( c(base_prompt, content_image_url("https://www.r-project.org/Rlogo.png")), c(base_prompt, content_image_file(system.file("httr2.png", package = "ellmer"))) ) response <- chat$process(img_prompts) response$texts() #> [[1]] #> [1] "The image shows the logo for R, a programming language and software environment #> used for statistical computing and graphics, featuring a stylized blue \"R\" #> inside a gray oval or ring." #> [[2]] #> [1] "The image shows a logo for \"httr2\" featuring a stylized red baseball batter #> silhouette on a dark blue hexagonal background."
If you interrupt chat processing or experience an error, you can call process()
again to resume from the last saved chat, which is cached in an .rds
file:
response <- chat$process(prompts, file = "chat.rds")
If file
is not defined, a temporary .rds
file will be created by default.
Toggle sound notifications on completion, interruption, and error:
response <- chat$process(prompts, beep = TRUE)
By default, the chat echo
is set to FALSE
to show a progress bar. However, you can still configure echo
by first setting progress
to FALSE
:
prompts <- c( "What is R?", "Explain base R versus tidyverse" ) response <- chat$process(prompts, progress = FALSE, echo = TRUE) #> R is a programming language and software environment used for #> statistical computing and graphics. #> Base R consists of the core functionalities built into R, #> while tidyverse is a collection of packages that offer a more #> consistent, readable, and streamlined approach to data manipulation, #> visualization, and analysis.
texts()
: Returns response texts in the same format as the input prompts (i.e., a list if prompts were provided as a list, or a vector if prompts were provided as a vector). When a type
is provided, returns a list with one element for each prompt. When type
is consistent, returns a data frame with one row for each prompt, and one column for each property.chats()
: Returns a list of chat objectsprogress()
: Returns processing statusThe following functions handle API rate limits differently:
workers
), exceeding rate limits will fall back on ellmer's retry strategyrpm
) and configuring the number of parallel connections (max_active
), exceeding rate limits will fall back on ellmer's retry strategyellmer's retry strategy includes the following options:
options(ellmer_max_tries)
: Retries requests up to 3 times by default and will retry if the connection fails, not just if the request returns a transient erroroptions(ellmer_timeout_s)
: Sets the default timeout time in seconds, which also applies to the initial connection phaseYou can also manage rate limits, specifically token usage limits, by limiting the number of maximum tokens per chat. The chat()
interface includes a params
parameter to configure max_tokens
, which also works in chatalot's chat functions.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4