| Title: | ask R anything |
|---|---|
| Description: | Interface to do useful things in R with LLMs. |
| Authors: | Antoine Fabri [aut, cre], Jordi Rosell [ctb] |
| Maintainer: | Antoine Fabri <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.0.9000 |
| Built: | 2026-05-28 08:59:00 UTC |
| Source: | https://github.com/moodymudskipper/ask |
Ask the same thing again, by default with the same parameters, if cache
is used a new request will be sent for the given arguments, and cached
instead of the older value.
again( conversation = last_conversation(), model = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )again( conversation = last_conversation(), model = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )
conversation |
A conversation, initiated by |
model, api_args
|
inherited from the last item
of |
cache |
A path where to cache the outputs, or "ram" to store them in RAM. useful to spare tokens and to have reproducible code. |
api_key |
API key |
These are all current models from openai, anthropic and ollama. We don't guarantee that they all work with ask though as we've tested a limited amount. ChatGPT, Claude, and llama models seem to work ok, please open a ticket to request further support.
all_models( openai_api_key = Sys.getenv("OPENAI_API_KEY"), only_supported = TRUE )all_models( openai_api_key = Sys.getenv("OPENAI_API_KEY"), only_supported = TRUE )
openai_api_key |
an api key for open ai (for other models we use webscraping rather than rest APIs to get the list of models) |
A tibble
Ask anything
ask( prompt = listen(), context = NULL, model = getOption("ask.model", "gpt-4o"), image = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )ask( prompt = listen(), context = NULL, model = getOption("ask.model", "gpt-4o"), image = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )
prompt |
Your request, a string or a character vector that will be concatenated to a string with line breaks as separators. |
context |
An object of class "ask_context" usually built from a call
to |
model |
The model to choose, see https://platform.openai.com/docs/models
or call |
image |
Path or URL to image to provide. Only considered for gpt models. |
cache |
A path where to cache the outputs, or "ram" to store them in RAM. useful to spare tokens and to have reproducible code. |
api_args |
Additional arguments to the api, depend on the model and rarely needed, most useful ones
include |
api_key |
API key |
a converstaion object
Ask a boolean question
ask_boolean(prompt = listen(), context = NULL, ...) ask_numeric(prompt = listen(), unit = NULL, context = NULL, ...)ask_boolean(prompt = listen(), context = NULL, ...) ask_numeric(prompt = listen(), unit = NULL, context = NULL, ...)
prompt |
Your request, a string or a character vector that will be concatenated to a string with line breaks as separators. |
context |
An object of class "ask_context" usually built from a call
to |
... |
forwarded to |
unit |
Optional, if not the SI is used, but better provide it. |
This function behaves like ask() but copies the output to the clipboard.
ask_clipboard( prompt = listen(), context = NULL, model = getOption("ask.model", "gpt-4o"), image = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )ask_clipboard( prompt = listen(), context = NULL, model = getOption("ask.model", "gpt-4o"), image = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )
prompt |
Your request, a string or a character vector that will be concatenated to a string with line breaks as separators. |
context |
An object of class "ask_context" usually built from a call
to |
model |
The model to choose, see https://platform.openai.com/docs/models
or call |
image |
Path or URL to image to provide. Only considered for gpt models. |
cache |
A path where to cache the outputs, or "ram" to store them in RAM. useful to spare tokens and to have reproducible code. |
api_args |
Additional arguments to the api, depend on the model and rarely needed, most useful ones
include |
api_key |
API key |
These are simple wrappers around ask() and follow_up(), that print to the
console rather than the viewer (Something that can also be achieved with
print(ask(...), venue = "console")). Only the last answer is printed but the
output object is still the entire conversation.
ask_console( prompt = listen(), context = NULL, model = getOption("ask.model", "gpt-4o"), image = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL, follow_up = FALSE ) follow_up_console( prompt = listen(), context = NULL, conversation = last_conversation(), model = NULL, image = NULL, cache = getOption("ask.cache"), ap_args = NULL, api_key = NULL )ask_console( prompt = listen(), context = NULL, model = getOption("ask.model", "gpt-4o"), image = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL, follow_up = FALSE ) follow_up_console( prompt = listen(), context = NULL, conversation = last_conversation(), model = NULL, image = NULL, cache = getOption("ask.cache"), ap_args = NULL, api_key = NULL )
prompt |
Your request, a string or a character vector that will be concatenated to a string with line breaks as separators. |
context |
An object of class "ask_context" usually built from a call
to |
model |
The model to choose, see https://platform.openai.com/docs/models
or call |
image |
Path or URL to image to provide. Only considered for gpt models. |
cache |
A path where to cache the outputs, or "ram" to store them in RAM. useful to spare tokens and to have reproducible code. |
api_args |
Additional arguments to the api, depend on the model and rarely needed, most useful ones
include |
api_key |
API key |
follow_up |
Whether to automatically follow up in the console, this triggers an interactive prompt that you can exit by pressing Esc or Ctrl+C.. |
conversation |
A conversation, initiated by |
The result from the ask() function.
This will change files in place a terminal command in a new terminal, and print extra
information in the R console. context = context_repo() is often useful
here unless the package is not too big.
ask_in_place( prompt = listen(), context = NULL, model = getOption("ask.model", "gpt-4o"), ... ) follow_up_in_place( prompt = listen(), context = NULL, conversation = last_conversation(), ... )ask_in_place( prompt = listen(), context = NULL, model = getOption("ask.model", "gpt-4o"), ... ) follow_up_in_place( prompt = listen(), context = NULL, conversation = last_conversation(), ... )
prompt |
Your request, a string or a character vector that will be concatenated to a string with line breaks as separators. |
context |
An object of class "ask_context" usually built from a call
to |
model |
The model to choose, see https://platform.openai.com/docs/models
or call |
... |
Forwarded to |
conversation |
A conversation, initiated by |
## Not run: ask_in_place("update the existing readme with useful missing info", context = context_repo()) ## End(Not run)## Not run: ask_in_place("update the existing readme with useful missing info", context = context_repo()) ## End(Not run)
Ask to open one or several files
ask_open( prompt, context = NULL, model = getOption("ask.model", "gpt-4o"), image = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )ask_open( prompt, context = NULL, model = getOption("ask.model", "gpt-4o"), image = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )
prompt |
Your request, a string or a character vector that will be concatenated to a string with line breaks as separators. |
context |
An object of class "ask_context" usually built from a call
to |
model |
The model to choose, see https://platform.openai.com/docs/models
or call |
image |
Path or URL to image to provide. Only considered for gpt models. |
cache |
A path where to cache the outputs, or "ram" to store them in RAM. useful to spare tokens and to have reproducible code. |
api_args |
Additional arguments to the api, depend on the model and rarely needed, most useful ones
include |
api_key |
API key |
A conversation object
## Not run: ask_open("the file(s) touched by the last commit", context_commits()) ask_open("the script were roxygen2 imports are defined", context_repo()) ## End(Not run)## Not run: ask_open("the file(s) touched by the last commit", context_commits()) ask_open("the script were roxygen2 imports are defined", context_repo()) ## End(Not run)
ask_smart() guesses which ask*() function and which context*()
function is appropriate, so you don't need to think too much or know the
package in depth.
ask_smart( prompt = listen(), context = NULL, model = getOption("ask.model", "gpt-4o"), cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )ask_smart( prompt = listen(), context = NULL, model = getOption("ask.model", "gpt-4o"), cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )
prompt |
Your request, a string or a character vector that will be concatenated to a string with line breaks as separators. |
context |
An object of class "ask_context" usually built from a call
to |
model |
The model to choose, see https://platform.openai.com/docs/models
or call |
cache |
A path where to cache the outputs, or "ram" to store them in RAM. useful to spare tokens and to have reproducible code. |
api_args |
Additional arguments to the api, depend on the model and rarely needed, most useful ones
include |
api_key |
API key |
It works by calling a llm twice, first to figure out the proper functions to use, then through these functions. As a consequence it is slower and spends more token (with an increased chance of reaching the limit of maximum tokens per minute)
This will suggest a terminal command in a new terminal, and print extra information in the R console.
ask_terminal(prompt = listen(), context = NULL, ...)ask_terminal(prompt = listen(), context = NULL, ...)
prompt |
Your request, a string or a character vector that will be concatenated to a string with line breaks as separators. |
context |
An object of class "ask_context" usually built from a call
to |
... |
Forwarded to |
## Not run: ask_terminal("who contributed to this project?") ask_terminal("show the latest 5 changes in compact form") ## End(Not run)## Not run: ask_terminal("who contributed to this project?") ask_terminal("show the latest 5 changes in compact form") ## End(Not run)
Ask for a tibble
ask_tibble(prompt = listen(), context = NULL, ...)ask_tibble(prompt = listen(), context = NULL, ...)
prompt |
Your request, a string or a character vector that will be concatenated to a string with line breaks as separators. |
context |
An object of class "ask_context" usually built from a call
to |
... |
forwarded to |
ask.cache: For optimal reproducibility, a path to a directory where to
store the cache, or ram to store it into the RAM.
Capture current plot (can be a base plot, a ggplot2 plot or anything else)
and saves it into a temp png file whose path is returned. meant to be used
with the image argument of ask*() functions.
capture_plot(width = 800, height = 600)capture_plot(width = 800, height = 600)
width |
image width |
height |
image height |
The path to the created file
Build an object of class "ask_context" to be used in the context argument.
of ask* functions. Most of the time using the provided context_*() functions
is sufficient.
context(...)context(...)
... |
named character vectors, or other context ojects (named or not).
These dots are dynamic in the rlang sense ( |
context() can be used :
To combine existing contexts, as in context(context1, context2)
To define a completely new context as in
To nest contexts as in context("new label" = context(context1, context2))
For any combination of the above
They are implemented as nested lists so the labels can be numbered when flattened
internally in ask*() functions or when printing them. Run examples below to see
how this works.
An object of class "ask_context"
context_smith <- context( "Smith family" = "The Smith family is John, Wendy, and their 3 kids Boris, Judith and Michael." ) context_johnson <- context("Johnson family" = "The Johnson family is Robert and his sister Brenda.") context_house <- context( "House" = "The Smiths and the Johnsons live in the same house, called 'the happy place'," ) context_johnson full_context <- context( Families = context(context_smith, context_johnson), context_house ) full_context ## Not run: ask("What are the names of the kids that live in the happy place", context = full_context) ask_numeric("How many people live in the happy place?", context = full_context) ask_boolean("Are Robert and Brenda related?", context = full_context) ## End(Not run)context_smith <- context( "Smith family" = "The Smith family is John, Wendy, and their 3 kids Boris, Judith and Michael." ) context_johnson <- context("Johnson family" = "The Johnson family is Robert and his sister Brenda.") context_house <- context( "House" = "The Smiths and the Johnsons live in the same house, called 'the happy place'," ) context_johnson full_context <- context( Families = context(context_smith, context_johnson), context_house ) full_context ## Not run: ask("What are the names of the kids that live in the happy place", context = full_context) ask_numeric("How many people live in the happy place?", context = full_context) ask_boolean("Are Robert and Brenda related?", context = full_context) ## End(Not run)
Contextualize clipboard content
context_clipboard()context_clipboard()
An object of class "ask_context"
Contextualize git commits
context_commits(n = 5)context_commits(n = 5)
n |
The number of commits to return context for (default is 5) |
An object of class "ask_context"
Contextualize uncommited changes
context_diff()context_diff()
An object of class "ask_context"
Contextualize GitHub issues
context_github( repo = NULL, state = c("open", "closed", "all"), filter = c("assigned", "created", "mentioned", "subscribed", "all"), labels = NULL, sort = c("created", "updated", "comments"), direction = c("asc", "desc"), since = NULL, n = 30 )context_github( repo = NULL, state = c("open", "closed", "all"), filter = c("assigned", "created", "mentioned", "subscribed", "all"), labels = NULL, sort = c("created", "updated", "comments"), direction = c("asc", "desc"), since = NULL, n = 30 )
repo |
A string in the form 'my.org/my.repo' specifying the repository. If not provided, will be fetched from the URL field of the DESCRIPTION file. |
state |
State of the issues to return ('open', 'closed', or 'all'). |
filter |
A string, see details. |
labels |
A vector of labels to filter the issues by. |
sort |
What to sort the results by |
direction |
The direction to sort the results by. |
since |
A date or time used to only show results that were last updated after the given time. |
n |
Number of results (max 100). |
An object of class "ask_context"
assigned (default): Issues assigned to the authenticated user.
created: Issues created by the authenticated user.
mentioned: Issues mentioning the authenticated user.
subscribed: Issues the user is subscribed to.
all: All issues owned by the authenticated user.
Contextualize Gmail messages from threads
context_gmail( search = NULL, num_results = 5, page_token = NULL, label_ids = NULL, include_spam_trash = NULL, user_id = "me" )context_gmail( search = NULL, num_results = 5, page_token = NULL, label_ids = NULL, include_spam_trash = NULL, user_id = "me" )
search, num_results, page_token, label_ids, include_spam_trash, user_id
|
Forwarded to |
An object of class "ask_context"
Contextualize R objects
context_objects(objects)context_objects(objects)
objects |
A list of R objects to be contextualized. |
An object of class "ask_context"
Contextualize package
context_package( pkg, DESCRIPTION = TRUE, NAMESPACE = TRUE, README = TRUE, NEWS = TRUE, LICENSE = TRUE, help_files = TRUE, code = FALSE, vignettes = FALSE )context_package( pkg, DESCRIPTION = TRUE, NAMESPACE = TRUE, README = TRUE, NEWS = TRUE, LICENSE = TRUE, help_files = TRUE, code = FALSE, vignettes = FALSE )
pkg |
Name of the package. |
DESCRIPTION |
Boolean, whether to include the DESCRIPTION file. |
NAMESPACE |
Boolean, whether to include the NAMESPACE file. |
README |
Boolean, whether to include the README file. |
NEWS |
Boolean, whether to include the NEWS.md file. |
LICENSE |
Boolean, whether to include the LICENSE file. |
help_files |
Boolean, whether to include help files. |
code |
Boolean, whether to include code files. |
vignettes |
Boolean, whether to include vignettes. |
An object of class "ask_context"
Contextualize pdf text content
context_pdf( file, pages = NULL, opw = "", upw = "", dpi = 600, language = "eng", options = NULL, type = "text" )context_pdf( file, pages = NULL, opw = "", upw = "", dpi = 600, language = "eng", options = NULL, type = "text" )
file |
file path or raw vector with pdf data |
pages |
which pages of the pdf file to extract |
opw |
string with owner password to open pdf |
upw |
string with user password to open pdf |
dpi |
resolution to render image that is passed to pdf_convert. |
language |
passed to tesseract to specify the languge of the engine. |
options |
passed to tesseract to specify OCR parameters |
type |
one or more from "text", "ocr_text", "ocr_data". Decides wether to
use |
An object of class "ask_context"
## Not run: ask("what is this about?", context_pdf("http://arxiv.org/pdf/1403.2805.pdf")) ## End(Not run)## Not run: ask("what is this about?", context_pdf("http://arxiv.org/pdf/1403.2805.pdf")) ## End(Not run)
Contextualize all R files in the repository
context_repo()context_repo()
An object of class "ask_context"
Contextualize a script
context_script(file = NULL)context_script(file = NULL)
file |
Path to the file, if |
An object of class "ask_context"
Contextualize the R session information
context_session_info()context_session_info()
An object of class "ask_context"
Contextualize an url
context_url(url, only_text = TRUE)context_url(url, only_text = TRUE)
url |
An url |
only_text |
Whether to cleanup the html and extract the text only |
An object of class "ask_context"
A small shiny app to manage all conversations. Whenever an ask*() function is used (not just ask()), a new conversation
is recorded and can be accessed through the conversation manager. There we
can expand or remove conversations, or even start a new one from scratch.
When you pick a conversation you leave the shiny app and the chosen conversation is
printed in the viewer and stored as last_conversation() so you can use
follow_up() or again() to expand it..
conversation_manager()conversation_manager()
A conversation
Continue a conversation, by default with the same parameters.
follow_up( prompt = listen(), context = NULL, conversation = last_conversation(), image = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )follow_up( prompt = listen(), context = NULL, conversation = last_conversation(), image = NULL, cache = getOption("ask.cache"), api_args = NULL, api_key = NULL )
prompt |
Your request, a string or a character vector that will be concatenated to a string with line breaks as separators. |
context |
An object of class "ask_context" usually built from a call
to |
conversation |
A conversation, initiated by |
image |
Path or URL to image to provide. Only considered for gpt models. |
cache |
A path where to cache the outputs, or "ram" to store them in RAM. useful to spare tokens and to have reproducible code. |
api_key |
API key |
model, api_args
|
inherited from the last item
of |
a conversation object
Fetch the last updated conversation
last_conversation()last_conversation()
listen to voice input
listen(verbose = TRUE)listen(verbose = TRUE)
verbose |
whether to print the recorded text as a message |
A string