Title: | High Performance, Low Friction Large Language Model Chat |
---|---|
Description: | Introduces a 'Copilot'-like completion experience, but it knows how to talk to the objects in your R environment. 'ellmer' chats are integrated directly into your 'RStudio' and 'Positron' sessions, automatically incorporating relevant context from surrounding lines of code and your global environment (like data frame columns and types). Open the package dialog box with a keyboard shortcut, type your request, and the assistant will stream its response directly into your documents. |
Authors: | Simon Couch [aut, cre]
|
Maintainer: | Simon Couch <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-19 16:29:13 UTC |
Source: | CRAN |
The gander addin is intended to be called using the RStudio addin rather
than explicitly by the user. See vignette("gander", package = "gander")
to learn more about using the gander addin.
gander_addin()
gander_addin()
The underlying ellmer Chat, invisibly. Primarily called for its side effects, modifying the current RStudio editor based on user input. Will error if no text is entered in the dialog.
## Not run: # Requires an interactive session, access to the RStudio API, # and an active connection to an LLM API. gander_addin() ## End(Not run)
## Not run: # Requires an interactive session, access to the RStudio API, # and an active connection to an LLM API. gander_addin() ## End(Not run)
The gander package makes use of a few notable user-facing options.
gander uses the .gander_chat
option to configure which model powers the
addin. .gander_chat
is an ellmer Chat object.
For example, to use OpenAI's GPT-4o-mini, you might write
options(.gander_chat = ellmer::chat_claude())
Paste that code in your .Rprofile
via usethis::edit_r_profile()
to
always use the same model every time you start an R session.
The gander package used to use options .gander_fn
and .gander_args
,
but those are deprecated in favor of .gander_chat
.
By default, gander responses use the following style
conventions: "Use tidyverse style and, when relevant, tidyverse packages. For example, when asked to plot something, use ggplot2, or when asked to transform data, using dplyr and/or tidyr unless explicitly instructed otherwise. " Set the .gander_style
option to
some other string to tailor responses to your own taste, e.g.:
options(.gander_style = "Use base R.")
Paste that code in your
.Rprofile
via usethis::edit_r_profile()
to always use the same style (or
even always begin with some base set of knowledge about frameworks you
work with often) every time you start an R session.
By default, gander will show the first 5 rows and 100 columns of every
relevant data frame, allowing for models to pick up on the names, types, and
distributions of the variables it may work with while also keeping the number
of tokens submitted per chat to a minimum. The option .gander_dims
allows
you to adjust how many rows and columns to supply to gander addin.
For richer context but increasing token usage, increase the number of rows
and columns. For example, to supply the first 50 rows and all columns of
datasets supplied to the model, you could use
options(.gander_dims = c(50, Inf))
.
To decrease token usage, decrease the number of rows and columns, e.g.
options(.gander_dims = c(0, 10))
to just show the names and types of the
first 10 columns. One could make the argument that setting the number of rows
to 0 is privacy-preserving, but do note that the model may pick up on the
values of specific cells based on code context alone.
Set that option in your ~/.Rprofile
to always use that setting.
# Running the following will adjust R options, so don't run by default: ## Not run: # Describe the first 100 rows and every column in relevant data # frames rather than the first 5 rows and 100 columns (this can # increase token usage greatly): options(.gander_dims = c(100, Inf)) # Only describe relevant data frame columns and their types, but don't # provide any rows: options(.gander_dims = c(0, Inf)) # Override default tidyverse style to tell the model to prefer another style: options(.gander_style = "Use base R.") # Configure gander to use its recommended model, Anthropic's Claude Sonnet # 3.5. Set this option in your `~/.Rprofile` to always use this setting. # Note that this requires an `ANTHROPIC_API_KEY` envvar: options(.gander_chat = ellmer::chat_claude()) ## End(Not run)
# Running the following will adjust R options, so don't run by default: ## Not run: # Describe the first 100 rows and every column in relevant data # frames rather than the first 5 rows and 100 columns (this can # increase token usage greatly): options(.gander_dims = c(100, Inf)) # Only describe relevant data frame columns and their types, but don't # provide any rows: options(.gander_dims = c(0, Inf)) # Override default tidyverse style to tell the model to prefer another style: options(.gander_style = "Use base R.") # Configure gander to use its recommended model, Anthropic's Claude Sonnet # 3.5. Set this option in your `~/.Rprofile` to always use this setting. # Note that this requires an `ANTHROPIC_API_KEY` envvar: options(.gander_chat = ellmer::chat_claude()) ## End(Not run)
gander_peek()
returns the ellmer Chat
object from the most recent call
to the gander assistant so that you can see what happened under-the-hood.
Note that gander initializes a new chat every time you invoke the addin, so the token count and conversation history only describes the most recent interaction with the package.
gander_peek()
gander_peek()
The ellmer Chat
object from the last assistant interaction,
or NULL
if no previous interaction exists.
## Not run: # First, run the addin to generate a response. gander_addin() # Then, use this function to examine what happened under-the-hood: gander_peek() ## End(Not run)
## Not run: # First, run the addin to generate a response. gander_addin() # Then, use this function to examine what happened under-the-hood: gander_peek() ## End(Not run)