| Title: | Tidy Integration of Large Language Models |
|---|---|
| Description: | A tidy interface for integrating large language model (LLM) APIs such as 'Claude', 'OpenAI', 'Gemini', 'Mistral', and local models via 'Ollama' into R workflows. The package supports text, image, audio, video, and document interactions; a unified media interface for attaching inline files or uploading to provider file stores; batch request APIs for cost-efficient large-scale processing; and a pipeline-oriented interface for seamless integration into data workflows. Web services are available at <https://www.anthropic.com>, <https://openai.com>, <https://aistudio.google.com/>, <https://mistral.ai/> and <https://ollama.com>. |
| Authors: | Eduard Brüll [aut, cre], Jia Zhang [ctb] |
| Maintainer: | Eduard Brüll <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.5.0 |
| Built: | 2026-05-27 06:25:52 UTC |
| Source: | https://github.com/edubruell/tidyllm |
Stores a reference to a local audio file for use in multimodal messages. The file is not encoded until the message is formatted for a provider.
audio_file(.path)audio_file(.path)
.path |
The path to the audio file on disk. |
A tidyllm_audio object.
The azure_openai() function acts as an interface for interacting with the Azure OpenAI API
through main tidyllm verbs.
azure_openai(..., .called_from = NULL)azure_openai(..., .called_from = NULL)
... |
Parameters to be passed to the Azure OpenAI API specific function, such as model configuration, input text, or API-specific options. |
.called_from |
An internal argument that specifies which action (e.g.,
|
azure_openai() currently routes messages only to azure_openai_chat() when used with chat().
send_batch(). It dynamically routes requests to OpenAI-specific functions
like azure_openai_chat() and azure_openai_embedding() based on the context of the call.
The result of the requested action, depending on the specific function invoked
(currently, only an updated LLMMessage object for azure_openai_chat()).
This function sends a message history to the Azure OpenAI Chat Completions API and returns the assistant's reply.
azure_openai_chat( .llm, .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .deployment = "gpt-4o-mini", .api_version = "2024-08-01-preview", .max_completion_tokens = NULL, .reasoning_effort = NULL, .frequency_penalty = NULL, .logit_bias = NULL, .presence_penalty = NULL, .seed = NULL, .stop = NULL, .stream = FALSE, .temperature = NULL, .top_p = NULL, .timeout = 60, .verbose = FALSE, .json_schema = NULL, .max_tries = 3, .dry_run = FALSE, .logprobs = NULL, .top_logprobs = NULL, .tools = NULL, .tool_choice = NULL, .max_tool_rounds = 10 )azure_openai_chat( .llm, .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .deployment = "gpt-4o-mini", .api_version = "2024-08-01-preview", .max_completion_tokens = NULL, .reasoning_effort = NULL, .frequency_penalty = NULL, .logit_bias = NULL, .presence_penalty = NULL, .seed = NULL, .stop = NULL, .stream = FALSE, .temperature = NULL, .top_p = NULL, .timeout = 60, .verbose = FALSE, .json_schema = NULL, .max_tries = 3, .dry_run = FALSE, .logprobs = NULL, .top_logprobs = NULL, .tools = NULL, .tool_choice = NULL, .max_tool_rounds = 10 )
.llm |
An |
.endpoint_url |
Base URL for the API (default: Sys.getenv("AZURE_ENDPOINT_URL")). |
.deployment |
The identifier of the model that is deployed (default: "gpt-4o-mini"). |
.api_version |
Which version of the API is deployed (default: "2024-08-01-preview"). |
.max_completion_tokens |
An upper bound for the number of tokens that can be generated for a completion. |
.reasoning_effort |
How long should reasoning models reason (can either be "low","medium" or "high"). |
.frequency_penalty |
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency. |
.logit_bias |
A named list modifying the likelihood of specified tokens appearing in the completion. |
.presence_penalty |
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far. |
.seed |
If specified, the system will make a best effort to sample deterministically. |
.stop |
Up to 4 sequences where the API will stop generating further tokens. |
.stream |
If set to TRUE, the answer will be streamed to console as it comes (default: FALSE). |
.temperature |
What sampling temperature to use, between 0 and 2. Higher values make the output more random. |
.top_p |
An alternative to sampling with temperature, called nucleus sampling. |
.timeout |
Request timeout in seconds (default: 60). |
.verbose |
Should additional information be shown after the API call (default: FALSE). |
.json_schema |
A JSON schema object provided by tidyllm schema or ellmer schemata. |
.max_tries |
Maximum retries to perform request. |
.dry_run |
If TRUE, perform a dry run and return the request object (default: FALSE). |
.logprobs |
If TRUE, get the log probabilities of each output token (default: NULL). |
.top_logprobs |
If specified, get the top N log probabilities of each output token (0-5, default: NULL). |
.tools |
Either a single TOOL object or a list of TOOL objects representing the available functions for tool calls. |
.tool_choice |
A character string specifying the tool-calling behavior; valid values are "none", "auto", or "required". |
.max_tool_rounds |
Integer specifying the maximum number of tool use iterations (default: 10). |
A new LLMMessage object containing the original messages plus the assistant's response.
Generate Embeddings Using OpenAI API on Azure
azure_openai_embedding( .input, .deployment = "text-embedding-3-small", .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .api_version = "2023-05-15", .truncate = TRUE, .timeout = 120, .dry_run = FALSE, .max_tries = 3 )azure_openai_embedding( .input, .deployment = "text-embedding-3-small", .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .api_version = "2023-05-15", .truncate = TRUE, .timeout = 120, .dry_run = FALSE, .max_tries = 3 )
.input |
A character vector of texts to embed or an |
.deployment |
The embedding model identifier (default: "text-embedding-3-small"). |
.endpoint_url |
Base URL for the API (default: Sys.getenv("AZURE_ENDPOINT_URL")). |
.api_version |
What API-Version othe Azure OpenAI API should be used (default: "2023-05-15") |
.truncate |
Whether to truncate inputs to fit the model's context length (default: TRUE). |
.timeout |
Timeout for the API request in seconds (default: 120). |
.dry_run |
If TRUE, perform a dry run and return the request object. |
.max_tries |
Maximum retry attempts for requests (default: 3). |
A tibble with two columns: input and embeddings.
The input column contains the texts sent to embed, and the embeddings column
is a list column where each row contains an embedding vector of the sent input.
This function cancels an in-progress batch created through the OpenAI API. The batch will be moved to a "cancelling" state and, eventually, "cancelled."
cancel_openai_batch(.batch_id, .dry_run = FALSE, .max_tries = 3, .timeout = 60)cancel_openai_batch(.batch_id, .dry_run = FALSE, .max_tries = 3, .timeout = 60)
.batch_id |
Character; the unique identifier for the batch to cancel. |
.dry_run |
Logical; if |
.max_tries |
Integer; maximum number of retries if the request fails (default: |
.timeout |
Integer; request timeout in seconds (default: |
A list containing the response from the OpenAI API about the cancellation status.
The chat() function sends a message to a language model via a specified provider and returns the response.
It routes the provided LLMMessage object to the appropriate provider-specific chat function,
while allowing for the specification of common arguments applicable across different providers.
chat( .llm, .provider = getOption("tidyllm_chat_default"), .dry_run = NULL, .stream = NULL, .temperature = NULL, .timeout = NULL, .top_p = NULL, .max_tries = NULL, .model = NULL, .verbose = NULL, .json_schema = NULL, .tools = NULL, .max_tool_rounds = NULL, .seed = NULL, .stop = NULL, .frequency_penalty = NULL, .presence_penalty = NULL )chat( .llm, .provider = getOption("tidyllm_chat_default"), .dry_run = NULL, .stream = NULL, .temperature = NULL, .timeout = NULL, .top_p = NULL, .max_tries = NULL, .model = NULL, .verbose = NULL, .json_schema = NULL, .tools = NULL, .max_tool_rounds = NULL, .seed = NULL, .stop = NULL, .frequency_penalty = NULL, .presence_penalty = NULL )
.llm |
An |
.provider |
A function or function call specifying the language model provider and any additional parameters.
This should be a call to a provider function like |
.dry_run |
Logical; if |
.stream |
Logical; if |
.temperature |
Numeric; controls the randomness of the model's output (0 = deterministic). |
.timeout |
Numeric; the maximum time (in seconds) to wait for a response. |
.top_p |
Numeric; nucleus sampling parameter, which limits the sampling to the top cumulative probability |
.max_tries |
Integer; the maximum number of retries for failed requests. |
.model |
Character; the model identifier to use (e.g., |
.verbose |
Logical; if |
.json_schema |
List; A JSON schema object as R list to enforce the output structure |
.tools |
Either a single TOOL object or a list of TOOL objects representing the available functions for tool calls. |
.max_tool_rounds |
Integer; the maximum number of tool use iterations for multi-turn tool calling (default varies by provider). |
.seed |
Integer; sets a random seed for reproducibility. |
.stop |
Character vector; specifies sequences where the model should stop generating further tokens. |
.frequency_penalty |
Numeric; adjusts the likelihood of repeating tokens (positive values decrease repetition). |
.presence_penalty |
Numeric; adjusts the likelihood of introducing new tokens (positive values encourage novelty). |
The chat() function provides a unified interface for interacting with different language model providers.
Common arguments such as .temperature, .model, and .stream are supported by most providers and can be
passed directly to chat(). If a provider does not support a particular argument, an error will be raised.
Advanced provider-specific configurations can be accessed via the provider functions.
An updated LLMMessage object containing the response from the language model.
## Not run: # Basic usage with OpenAI provider llm_message("Hello World") |> chat(ollama(.ollama_server = "https://my-ollama-server.de"),.model="mixtral") chat(mistral,.model="mixtral") # Use streaming with Claude provider llm_message("Tell me a story") |> chat(claude(),.stream=TRUE) ## End(Not run)## Not run: # Basic usage with OpenAI provider llm_message("Hello World") |> chat(ollama(.ollama_server = "https://my-ollama-server.de"),.model="mixtral") chat(mistral,.model="mixtral") # Use streaming with Claude provider llm_message("Tell me a story") |> chat(claude(),.stream=TRUE) ## End(Not run)
Provider function for interacting with any server that implements the OpenAI
Chat Completions wire format (vLLM, LiteLLM, Together, Anyscale, etc.).
Supports the chat() verb only.
chat_completions_chat( .llm, .api_url, .api_key_env_var = NULL, .model = "default", ... ) chat_completions(..., .called_from = NULL)chat_completions_chat( .llm, .api_url, .api_key_env_var = NULL, .model = "default", ... ) chat_completions(..., .called_from = NULL)
.llm |
An |
.api_url |
Base URL for the API endpoint (required). |
.api_key_env_var |
Name of the environment variable holding the API key. |
.model |
The model identifier to use (default: |
... |
Additional parameters passed to the underlying chat function. |
.called_from |
Internal routing argument; do not set manually. |
An updated LLMMessage object with the assistant's response appended.
This function converts an LLMMessage to the turns ellmer chat object.
The ellmer object is cloned and its turn history is cleared internatlly.
This maintains tidyllms stateless style.
chat_ellmer( .llm, .ellmer_chat, .stream = FALSE, .timeout = 60, .verbose = FALSE, .dry_run = FALSE, .tools = NULL, .max_tries = 3 )chat_ellmer( .llm, .ellmer_chat, .stream = FALSE, .timeout = 60, .verbose = FALSE, .dry_run = FALSE, .tools = NULL, .max_tries = 3 )
.llm |
An |
.ellmer_chat |
An ellmer chat object (e.g., from |
.stream |
Logical; if TRUE, streams the response piece by piece (default: FALSE). |
.timeout |
Request timeout in seconds (default: 60). |
.verbose |
If TRUE, displays additional information about the chat (default: FALSE). |
.dry_run |
If TRUE, returns the constructed request object without executing it (default: FALSE). |
.tools |
Dummy for error message if called from chat with tools (default: NULL). |
.max_tries |
Maximum retries to perform the request (default: 3). |
A new LLMMessage object containing the original messages plus the assistant's response.
This function retrieves the processing status and other details of a specified Azure OpenAI batch ID from the Azure OpenAI Batch API.
check_azure_openai_batch( .llms = NULL, .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )check_azure_openai_batch( .llms = NULL, .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )
.llms |
A list of LLMMessage objects. |
.endpoint_url |
Base URL for the API (default: Sys.getenv("AZURE_ENDPOINT_URL")). |
.batch_id |
A manually set batch ID. |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it (default: FALSE). |
.max_tries |
Maximum retries to perform the request (default: 3). |
.timeout |
Integer specifying the request timeout in seconds (default: 60). |
A tibble with information about the status of batch processing.
This function retrieves the processing status and other details of a specified
batchid or a list of LLMMessage objects with batch attribute.
It routes the input to the appropriate provider-specific batch API function.
check_batch( .llms, .provider = getOption("tidyllm_cbatch_default"), .dry_run = NULL, .max_tries = NULL, .timeout = NULL )check_batch( .llms, .provider = getOption("tidyllm_cbatch_default"), .dry_run = NULL, .max_tries = NULL, .timeout = NULL )
.llms |
A list of |
.provider |
A function or function call specifying the language model provider and any additional parameters.
This should be a call to a provider function like |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it |
.max_tries |
Maximum retries to perform the request |
.timeout |
Integer specifying the request timeout in seconds |
A tibble with information about the status of batch processing.
This function retrieves the processing status and other details of a specified Claude batch ID from the Claude API.
check_claude_batch( .llms = NULL, .batch_id = NULL, .api_url = "https://api.anthropic.com/", .dry_run = FALSE, .max_tries = 3, .timeout = 60 )check_claude_batch( .llms = NULL, .batch_id = NULL, .api_url = "https://api.anthropic.com/", .dry_run = FALSE, .max_tries = 3, .timeout = 60 )
.llms |
A list of LLMMessage objects |
.batch_id |
A manually set batchid |
.api_url |
Character; base URL of the Claude API (default: "https://api.anthropic.com/"). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it (default: FALSE). |
.max_tries |
Maximum retries to peform request |
.timeout |
Integer specifying the request timeout in seconds (default: 60). |
A tibble with information about the status of batch processing
Retrieves processing status and metadata for a Gemini batch operation.
check_gemini_batch( .llms = NULL, .batch_id = NULL, .timeout = 60, .max_tries = 3, .dry_run = FALSE )check_gemini_batch( .llms = NULL, .batch_id = NULL, .timeout = 60, .max_tries = 3, .dry_run = FALSE )
.llms |
(Optional) List of LLMMessage objects with a |
.batch_id |
(Optional) Character string: full batch operation name, e.g. |
.timeout |
Integer. Request timeout in seconds. Default: 60. |
.max_tries |
Integer. Maximum retry attempts. Default: 3. |
.dry_run |
Logical. If TRUE, return the request object instead of making the request (for debugging). Default: FALSE. |
You can supply either the .batch_id string (e.g. "batches/xyz...") or
a list of LLMMessage objects (.llms) with a "batch_id" attribute as returned by send_gemini_batch().
A tibble with the operation's metadata, including name, state, creation time, completion time, and done status.
This function retrieves the processing status and other details of a specified Groq batch.
check_groq_batch( .llms = NULL, .batch_id = NULL, .api_url = "https://api.groq.com/", .dry_run = FALSE, .max_tries = 3, .timeout = 60 )check_groq_batch( .llms = NULL, .batch_id = NULL, .api_url = "https://api.groq.com/", .dry_run = FALSE, .max_tries = 3, .timeout = 60 )
.llms |
A list of LLMMessage objects with a batch_id attribute. |
.batch_id |
A character string with the batch ID to check. |
.api_url |
Character; base URL of the Groq API (default: "https://api.groq.com/"). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing (default: FALSE). |
.max_tries |
Maximum retries to perform request. |
.timeout |
Integer specifying the request timeout in seconds (default: 60). |
A tibble with information about the status of batch processing.
check_job() dispatches to check_batch() for batch objects or
perplexity_check_research() / openai_check_research() for tidyllm_research_job objects.
check_job(.job, ...)check_job(.job, ...)
.job |
An object with a |
... |
Additional arguments passed to the underlying function. |
Status information; type depends on .job class.
This function retrieves the processing status and other details of a specified Mistral batch ID from the Mistral Batch API.
check_mistral_batch( .llms = NULL, .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )check_mistral_batch( .llms = NULL, .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )
.llms |
A list of LLMMessage objects. |
.batch_id |
A manually set batch ID. |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it (default: FALSE). |
.max_tries |
Maximum retries to perform the request (default: 3). |
.timeout |
Integer specifying the request timeout in seconds (default: 60). |
A tibble with information about the status of batch processing.
This function retrieves the processing status and other details of a specified OpenAI batch ID from the OpenAI Batch API.
check_openai_batch( .llms = NULL, .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )check_openai_batch( .llms = NULL, .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )
.llms |
A list of LLMMessage objects. |
.batch_id |
A manually set batch ID. |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it (default: FALSE). |
.max_tries |
Maximum retries to perform the request (default: 3). |
.timeout |
Integer specifying the request timeout in seconds (default: 60). |
A tibble with information about the status of batch processing.
The claude() function acts as an interface for interacting with the Anthropic API
through main tidyllm verbs such as chat(), embed(), and
send_batch(). It dynamically routes requests to Claude-specific functions
like claude_chat() and send_claude_batch() based on the context of the call.
claude(..., .called_from = NULL)claude(..., .called_from = NULL)
... |
Parameters to be passed to the appropriate OpenAI-specific function, such as model configuration, input text, or API-specific options. |
.called_from |
An internal argument that specifies which action (e.g.,
|
The result of the requested action, depending on the specific function invoked
(e.g., an updated LLMMessage object for chat(), or a matrix for embed()).
Interact with Claude AI models via the Anthropic API
claude_chat( .llm, .model = "claude-sonnet-4-6", .max_tokens = 2048, .temperature = NULL, .top_k = NULL, .top_p = NULL, .metadata = NULL, .stop_sequences = NULL, .tools = NULL, .json_schema = NULL, .file_ids = NULL, .api_url = "https://api.anthropic.com/", .verbose = FALSE, .max_tries = 3, .timeout = 60, .stream = FALSE, .dry_run = FALSE, .thinking = FALSE, .thinking_budget = 1024, .max_tool_rounds = 10 )claude_chat( .llm, .model = "claude-sonnet-4-6", .max_tokens = 2048, .temperature = NULL, .top_k = NULL, .top_p = NULL, .metadata = NULL, .stop_sequences = NULL, .tools = NULL, .json_schema = NULL, .file_ids = NULL, .api_url = "https://api.anthropic.com/", .verbose = FALSE, .max_tries = 3, .timeout = 60, .stream = FALSE, .dry_run = FALSE, .thinking = FALSE, .thinking_budget = 1024, .max_tool_rounds = 10 )
.llm |
An LLMMessage object containing the conversation history and system prompt. |
.model |
Character string specifying the Claude model version (default: "claude-sonnet-4-6"). |
.max_tokens |
Integer specifying the maximum number of tokens in the response (default: 1024). |
.temperature |
Numeric between 0 and 1 controlling response randomness. |
.top_k |
Integer controlling diversity by limiting the top K tokens. |
.top_p |
Numeric between 0 and 1 for nucleus sampling. |
.metadata |
List of additional metadata to include with the request. |
.stop_sequences |
Character vector of sequences that will halt response generation. |
.tools |
List of additional tools or functions the model can use. |
.json_schema |
A schema to enforce an output structure |
.file_ids |
Character; A vector of file IDs for files that were uploaded to Anthropics Servers |
.api_url |
Base URL for the Anthropic API (default: "https://api.anthropic.com/"). |
.verbose |
Logical; if TRUE, displays additional information about the API call (default: FALSE). |
.max_tries |
Maximum retries to peform request |
.timeout |
Integer specifying the request timeout in seconds (default: 60). |
.stream |
Logical; if TRUE, streams the response piece by piece (default: FALSE). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it (default: FALSE). |
.thinking |
Logical; if TRUE, enables Claude's thinking mode for complex reasoning tasks (default: FALSE). |
.thinking_budget |
Integer specifying the maximum tokens Claude can spend on thinking (default: 1024). Must be at least 1024. |
.max_tool_rounds |
Integer specifying the maximum number of tool use iterations (default: 10). Set to 1 for single-round tool use, or higher for multi-turn agentic loops. |
A new LLMMessage object containing the original messages plus Claude's response.
## Not run: # Basic usage msg <- llm_message("What is R programming?") result <- claude_chat(msg) # With custom parameters result2 <- claude_chat(msg, .temperature = 0.7, .max_tokens = 1000) ## End(Not run)## Not run: # Basic usage msg <- llm_message("What is R programming?") result <- claude_chat(msg) # With custom parameters result2 <- claude_chat(msg, .temperature = 0.7, .max_tokens = 1000) ## End(Not run)
Deletes a specific file from the Claude API using its file ID.
claude_delete_file( .file_id, .api_url = "https://api.anthropic.com/", .timeout = 60, .max_tries = 3, .dry_run = FALSE )claude_delete_file( .file_id, .api_url = "https://api.anthropic.com/", .timeout = 60, .max_tries = 3, .dry_run = FALSE )
.file_id |
The file ID to delete. |
.api_url |
Base URL for the Claude API (default: "https://api.anthropic.com/"). |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it. |
Invisibly returns NULL. Prints a confirmation message upon successful deletion.
Retrieves metadata for a specific file uploaded to the Claude API.
claude_file_metadata( .file_id, .api_url = "https://api.anthropic.com/", .timeout = 60, .max_tries = 3, .dry_run = FALSE )claude_file_metadata( .file_id, .api_url = "https://api.anthropic.com/", .timeout = 60, .max_tries = 3, .dry_run = FALSE )
.file_id |
The file ID to retrieve metadata for. |
.api_url |
Base URL for the Claude API (default: "https://api.anthropic.com/"). |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it. |
A tibble containing metadata fields such as file_id, filename, size, and MIME type.
Lists metadata for files uploaded to the Claude API, supporting pagination.
claude_list_files( .limit = 20, .order = "desc", .api_url = "https://api.anthropic.com/", .timeout = 60, .max_tries = 3, .dry_run = FALSE )claude_list_files( .limit = 20, .order = "desc", .api_url = "https://api.anthropic.com/", .timeout = 60, .max_tries = 3, .dry_run = FALSE )
.limit |
The maximum number of files to return (default: 20). |
.order |
Order of results, either "asc" or "desc" (default: "desc"). |
.api_url |
Base URL for the Claude API (default: "https://api.anthropic.com/"). |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it. |
A tibble containing metadata for each file, including file_id, filename, size, and MIME type.
List Available Models from the Anthropic Claude API
claude_list_models( .api_url = "https://api.anthropic.com", .timeout = 60, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE )claude_list_models( .api_url = "https://api.anthropic.com", .timeout = 60, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE )
.api_url |
Base URL for the API (default: "https://api.anthropic.com"). |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum number of retries for the API request (default: 3). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it. |
.verbose |
Logical; if TRUE, prints additional information about the request. |
A tibble containing model information (columns include type,id, display_name, and created_at),
or NULL if no models are found.
Uploads a file to the Claude API and returns its metadata as a tibble.
claude_upload_file( .file_path, .api_url = "https://api.anthropic.com/", .timeout = 60, .max_tries = 3, .dry_run = FALSE )claude_upload_file( .file_path, .api_url = "https://api.anthropic.com/", .timeout = 60, .max_tries = 3, .dry_run = FALSE )
.file_path |
The local file path of the file to upload. |
.api_url |
Base URL for the Claude API (default: "https://api.anthropic.com/"). |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it. |
A tibble containing metadata about the uploaded file, including its file_id, name, and size.
Returns a TOOL object for Claude's builtin web_search tool.
claude_websearch()claude_websearch()
The deep_research() function sends a message to a provider's deep research endpoint.
Currently supported: Perplexity (sonar-deep-research via async API).
deep_research(.llm, .provider, .background = FALSE, ...)deep_research(.llm, .provider, .background = FALSE, ...)
.llm |
An |
.provider |
A function or function call specifying the provider (e.g., |
.background |
Logical; if TRUE, returns a |
... |
Additional arguments passed to the provider's deep research function. |
If .background = FALSE, an LLMMessage with the research reply.
If .background = TRUE, a tidyllm_research_job for use with check_job()/fetch_job().
The deepseek() function acts as a provider interface for interacting with the Deepseek API
through tidyllm's chat() verb.
It dynamically routes requests to deepseek-specific function. At the moment this is only
deepseek_chat()
deepseek(..., .called_from = NULL)deepseek(..., .called_from = NULL)
... |
Parameters to be passed to the appropriate Deepseek-specific function, such as model configuration, input text, or API-specific options. |
.called_from |
An internal argument specifying which action (e.g.,
|
The result of the requested action, depending on the specific function invoked
(e.g., an updated LLMMessage object for chat()).
This function sends a message history to the DeepSeek Chat API and returns the assistant's reply. Currently tool calls cause problems on the DeepSeek API
deepseek_chat( .llm, .model = "deepseek-v4-pro", .thinking = NULL, .max_tokens = 2048, .temperature = NULL, .top_p = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .stop = NULL, .stream = FALSE, .logprobs = NULL, .top_logprobs = NULL, .tools = NULL, .tool_choice = NULL, .api_url = "https://api.deepseek.com/", .timeout = 60, .verbose = FALSE, .dry_run = FALSE, .max_tries = 3, .max_tool_rounds = 10 )deepseek_chat( .llm, .model = "deepseek-v4-pro", .thinking = NULL, .max_tokens = 2048, .temperature = NULL, .top_p = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .stop = NULL, .stream = FALSE, .logprobs = NULL, .top_logprobs = NULL, .tools = NULL, .tool_choice = NULL, .api_url = "https://api.deepseek.com/", .timeout = 60, .verbose = FALSE, .dry_run = FALSE, .max_tries = 3, .max_tool_rounds = 10 )
.llm |
An |
.model |
The identifier of the model to use (default: |
.thinking |
If TRUE, enables thinking mode via |
.max_tokens |
The maximum number of tokens that can be generated in the response (default: 2048). |
.temperature |
Controls the randomness in the model's response. Values between 0 and 2 are allowed (optional). |
.top_p |
Nucleus sampling parameter that controls the proportion of probability mass considered (optional). |
.frequency_penalty |
Number between -2.0 and 2.0. Penalizes repeated tokens to reduce repetition (optional). |
.presence_penalty |
Number between -2.0 and 2.0. Encourages new topics by penalizing tokens that have appeared so far (optional). |
.stop |
One or more sequences where the API will stop generating further tokens (optional). |
.stream |
Logical; if TRUE, streams the response piece by piece (default: FALSE). |
.logprobs |
If TRUE, returns log probabilities of each output token (default: FALSE). |
.top_logprobs |
Number between 0 and 5 specifying the number of top log probabilities to return (optional). |
.tools |
Either a single TOOL object or a list of TOOL objects representing the available functions for tool calls. |
.tool_choice |
A character string specifying the tool-calling behavior; valid values are |
.api_url |
Base URL for the DeepSeek API (default: |
.timeout |
Request timeout in seconds (default: 60). |
.verbose |
If TRUE, displays additional information after the API call (default: FALSE). |
.dry_run |
If TRUE, returns the constructed request object without executing it (default: FALSE). |
.max_tries |
Maximum retries to perform the request (default: 3). |
.max_tool_rounds |
Integer specifying the maximum number of tool use iterations (default: 10). Set to 1 for single-round tool use, or higher for multi-turn agentic loops. |
A new LLMMessage object containing the original messages plus the assistant's response.
Delete a File from a Provider's File Store
delete_file(.provider, .file_id, ...)delete_file(.provider, .file_id, ...)
.provider |
A provider function call. |
.file_id |
The file ID string to delete, or a |
... |
Additional provider-specific arguments. |
Invisibly NULL; prints a confirmation message.
This function converts a data frame into an LLMMessage object representing a conversation history.
The data frame must have specific columns (role and content), with each row representing a message.
df_llm_message(.df)df_llm_message(.df)
.df |
A data frame with at least two rows and columns |
An LLMMessage object representing the structured conversation.
Other Message Creation Utilities:
llm_message()
The chat_ellmer() function acts as a provider interface for interacting with
ellmer chat objects through tidyllm's verb interface
ellmer(..., .called_from = NULL)ellmer(..., .called_from = NULL)
... |
Additional parameters to pass through (for consistency with other providers). |
.called_from |
An internal argument specifying which action (e.g.,
|
This function allows you to use any ellmer chat object (e.g., from
ellmer::chat_anthropic(), ellmer::chat_openai(), etc.) as a stateless
backend for tidyllm. The ellmer object is cloned for each interaction to
maintain tidyllm's stateless approach.
A provider function that can be used with tidyllm::chat().
Converts an ellmer ToolDef or ToolBuiltIn object to a tidyllm TOOL object,
allowing seamless integration of ellmer-defined tools and builtin provider tools
with tidyllm workflows.
ellmer_tool(.ellmer_tool)ellmer_tool(.ellmer_tool)
.ellmer_tool |
An ellmer |
This function supports two types of ellmer tools:
Custom ToolDef objects: Extracts the function, description, and argument schemas from an ellmer tool and converts them to tidyllm's internal representation. Ellmer type objects are automatically converted to tidyllm field descriptors.
Builtin ToolBuiltIn objects: Converts provider-native builtin tools (like Claude's web search) to tidyllm format. For builtin tools, the tool definition is passed through as-is to the provider's API, which handles the tool execution natively.
A TOOL class object that can be used with tidyllm chat() functions
## Not run: library(ellmer) # Example 1: Custom tool tool_rnorm <- ellmer::tool( rnorm, description = "Draw numbers from a random normal distribution", arguments = list( n = ellmer::type_integer("The number of observations"), mean = ellmer::type_number("The mean value"), sd = ellmer::type_number("The standard deviation") ) ) tidyllm_tool_rnorm <- ellmer_tool(tool_rnorm) llm_message("Generate 100 random numbers") |> chat(openai(), .tools = tidyllm_tool_rnorm) # Example 2: Builtin tool web_search <- ellmer_tool(ellmer::claude_tool_web_search()) llm_message("What are the latest AI developments?") |> chat(claude(), .tools = web_search) ## End(Not run)## Not run: library(ellmer) # Example 1: Custom tool tool_rnorm <- ellmer::tool( rnorm, description = "Draw numbers from a random normal distribution", arguments = list( n = ellmer::type_integer("The number of observations"), mean = ellmer::type_number("The mean value"), sd = ellmer::type_number("The standard deviation") ) ) tidyllm_tool_rnorm <- ellmer_tool(tool_rnorm) llm_message("Generate 100 random numbers") |> chat(openai(), .tools = tidyllm_tool_rnorm) # Example 2: Builtin tool web_search <- ellmer_tool(ellmer::claude_tool_web_search()) llm_message("What are the latest AI developments?") |> chat(claude(), .tools = web_search) ## End(Not run)
The embed() function allows you to embed a text via a specified provider.
It routes the input to the appropriate provider-specific embedding function.
embed( .input, .provider = getOption("tidyllm_embed_default"), .model = NULL, .truncate = NULL, .timeout = NULL, .dry_run = NULL, .max_tries = NULL )embed( .input, .provider = getOption("tidyllm_embed_default"), .model = NULL, .truncate = NULL, .timeout = NULL, .dry_run = NULL, .max_tries = NULL )
.input |
A character vector of texts v, a list of texts and image objects, or an |
.provider |
A function or function call specifying the language model provider and any additional parameters.
This should be a call to a provider function like |
.model |
The embedding model to use |
.truncate |
Whether to truncate inputs to fit the model's context length |
.timeout |
Timeout for the API request in seconds |
.dry_run |
If TRUE, perform a dry run and return the request object. |
.max_tries |
Maximum retry attempts for requests |
A tibble with two columns: input and embeddings.
The input column contains the texts sent to embed, and the embeddings column
is a list column where each row contains an embedding vector of the sent input.
## Not run: c("What is the meaning of life, the universe and everything?", "How much wood would a woodchuck chuck?", "How does the brain work?") |> embed(gemini) ## End(Not run)## Not run: c("What is the meaning of life, the universe and everything?", "How much wood would a woodchuck chuck?", "How does the brain work?") |> embed(gemini) ## End(Not run)
This function retrieves the results of a completed Azure OpenAI batch and updates
the provided list of LLMMessage objects with the responses. It aligns each
response with the original request using the custom_ids generated in send_azure_openai_batch().
fetch_azure_openai_batch( .llms, .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )fetch_azure_openai_batch( .llms, .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )
.llms |
A list of |
.endpoint_url |
Base URL for the API (default: Sys.getenv("AZURE_ENDPOINT_URL")). |
.batch_id |
Character; the unique identifier for the batch. By default this is NULL
and the function will attempt to use the |
.dry_run |
Logical; if |
.max_tries |
Integer; maximum number of retries if the request fails (default: |
.timeout |
Integer; request timeout in seconds (default: |
A list of updated LLMMessage objects, each with the assistant's response added if successful.
This function retrieves the results of a completed batch and updates
the provided list of LLMMessage objects with the responses. It aligns each
response with the original request using the custom_ids generated in send_batch().
fetch_batch( .llms, .provider = getOption("tidyllm_fbatch_default"), .dry_run = NULL, .max_tries = NULL, .timeout = NULL )fetch_batch( .llms, .provider = getOption("tidyllm_fbatch_default"), .dry_run = NULL, .max_tries = NULL, .timeout = NULL )
.llms |
A list of |
.provider |
A function or function call specifying the language model provider and any additional parameters.
This should be a call to a provider function like |
.dry_run |
Logical; if |
.max_tries |
Integer; maximum number of retries if the request fails |
.timeout |
Integer; request timeout in seconds |
The function routes the input to the appropriate provider-specific batch API function.
A list of updated LLMMessage objects, each with the assistant's response added if successful.
This function retrieves the results of a completed Claude batch and updates
the provided list of LLMMessage objects with the responses. It aligns each
response with the original request using the custom_ids generated in send_claude_batch().
fetch_claude_batch( .llms, .batch_id = NULL, .api_url = "https://api.anthropic.com/", .dry_run = FALSE, .max_tries = 3, .timeout = 60 )fetch_claude_batch( .llms, .batch_id = NULL, .api_url = "https://api.anthropic.com/", .dry_run = FALSE, .max_tries = 3, .timeout = 60 )
.llms |
A list of |
.batch_id |
Character; the unique identifier for the batch. By default this is NULL
and the function will attempt to use the |
.api_url |
Character; the base URL for the Claude API (default: "https://api.anthropic.com/"). |
.dry_run |
Logical; if |
.max_tries |
Integer; maximum number of retries if the request fails (default: |
.timeout |
Integer; request timeout in seconds (default: |
A list of updated LLMMessage objects, each with the assistant's response added if successful.
Retrieves the results of a completed Gemini batch and updates the provided list of LLMMessage objects with the assistant's responses, matching by original list order.
fetch_gemini_batch( .llms, .batch_name = NULL, .timeout = 60, .max_tries = 3, .dry_run = FALSE )fetch_gemini_batch( .llms, .batch_name = NULL, .timeout = 60, .max_tries = 3, .dry_run = FALSE )
.llms |
List of |
.batch_name |
(Optional) Character; batch operation name (e.g. "batches/xyz123"). If not provided, is taken from |
.timeout |
Integer; request timeout in seconds (default: 60). |
.max_tries |
Integer; maximum retry attempts (default: 3). |
.dry_run |
Logical; if |
A list of updated LLMMessage objects with the assistant response appended to each, in the same order.
This function retrieves the results of a completed Groq batch and updates
the provided list of LLMMessage objects with the responses.
fetch_groq_batch( .llms, .batch_id = NULL, .api_url = "https://api.groq.com/", .dry_run = FALSE, .max_tries = 3, .timeout = 60 )fetch_groq_batch( .llms, .batch_id = NULL, .api_url = "https://api.groq.com/", .dry_run = FALSE, .max_tries = 3, .timeout = 60 )
.llms |
A list of |
.batch_id |
Character; the unique identifier for the batch. |
.api_url |
Character; the base URL for the Groq API (default: "https://api.groq.com/"). |
.dry_run |
Logical; if |
.max_tries |
Integer; maximum number of retries if the request fails (default: |
.timeout |
Integer; request timeout in seconds (default: |
A list of updated LLMMessage objects, each with the assistant's response added if successful.
fetch_job() dispatches to fetch_batch() for batch objects or
perplexity_fetch_research() / openai_fetch_research() for tidyllm_research_job objects.
fetch_job(.job, .provider = NULL, ...)fetch_job(.job, .provider = NULL, ...)
.job |
An object with a |
.provider |
A provider function (required for batch jobs, ignored for research jobs). |
... |
Additional arguments passed to the underlying function. |
Fetched results; type depends on .job class.
This function retrieves the results of a completed Mistral batch and updates
the provided list of LLMMessage objects with the responses. It aligns each
response with the original request using the custom_ids generated in send_mistral_batch().
fetch_mistral_batch( .llms, .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )fetch_mistral_batch( .llms, .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )
.llms |
A list of |
.batch_id |
Character; the unique identifier for the batch. By default this is NULL
and the function will attempt to use the |
.dry_run |
Logical; if |
.max_tries |
Integer; maximum number of retries if the request fails (default: |
.timeout |
Integer; request timeout in seconds (default: |
A list of updated LLMMessage objects, each with the assistant's response added if successful.
This function retrieves the results of a completed OpenAI batch and updates
the provided list of LLMMessage objects with the responses. It aligns each
response with the original request using the custom_ids generated in send_openai_batch().
fetch_openai_batch( .llms, .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )fetch_openai_batch( .llms, .batch_id = NULL, .dry_run = FALSE, .max_tries = 3, .timeout = 60 )
.llms |
A list of |
.batch_id |
Character; the unique identifier for the batch. By default this is NULL
and the function will attempt to use the |
.dry_run |
Logical; if |
.max_tries |
Integer; maximum number of retries if the request fails (default: |
.timeout |
Integer; request timeout in seconds (default: |
A list of updated LLMMessage objects, each with the assistant's response added if successful.
These functions create field descriptors used in tidyllm_schema() or field_object() to define JSON schema fields. They support character, factor, numeric, and logical types.
field_chr(.description = character(0), .vector = FALSE) field_fct(.description = character(0), .levels, .vector = FALSE) field_dbl(.description = character(0), .vector = FALSE) field_lgl(.description = character(0), .vector = FALSE)field_chr(.description = character(0), .vector = FALSE) field_fct(.description = character(0), .levels, .vector = FALSE) field_dbl(.description = character(0), .vector = FALSE) field_lgl(.description = character(0), .vector = FALSE)
.description |
A character string describing the field (optional). |
.vector |
A logical value indicating if the field is a vector (default: FALSE). |
.levels |
A character vector specifying allowable values (for |
An S7 tidyllm_field object representing the field descriptor.
field_chr("A common street name") field_fct("State abbreviation", .levels = c("CA", "TX", "Other")) field_dbl("House number") field_lgl("Is residential") field_dbl("A list of appartment numbers at the address",.vector=TRUE )field_chr("A common street name") field_fct("State abbreviation", .levels = c("CA", "TX", "Other")) field_dbl("House number") field_lgl("Is residential") field_dbl("A list of appartment numbers at the address",.vector=TRUE )
Define a nested object field
field_object(.description = character(0), ..., .vector = FALSE)field_object(.description = character(0), ..., .vector = FALSE)
.description |
A character string describing the field (optional). |
... |
Named fields to include in the object definition (required). |
.vector |
A logical value indicating if the field is a list of objects (default: FALSE). |
An S7 tidyllm_field object of type "object" containing nested fields.
# Define an address object with nested fields address <- field_object("A mailing address", street = field_chr("Street name"), city = field_chr("City name"), zipcode = field_chr("Postal code") ) # Create a vector of objects addresses <- field_object("List of addresses", street = field_chr("Street name"), city = field_chr("City name"), .vector = TRUE )# Define an address object with nested fields address <- field_object("A mailing address", street = field_chr("Street name"), city = field_chr("City name"), zipcode = field_chr("Postal code") ) # Create a vector of objects addresses <- field_object("List of addresses", street = field_chr("Street name"), city = field_chr("City name"), .vector = TRUE )
Get Metadata for a File Stored on a Provider
file_info(.provider, .file_id, ...)file_info(.provider, .file_id, ...)
.provider |
A provider function call. |
.file_id |
The file ID string to look up, or a |
... |
Additional provider-specific arguments. |
A single-row tibble of file metadata.
The gemini() function acts as a provider interface for interacting with the Google Gemini API
through tidyllm's main verbs such as chat() and embed().
It dynamically routes requests to Gemini-specific functions
like gemini_chat() and gemini_embedding() based on the context of the call.
gemini(..., .called_from = NULL)gemini(..., .called_from = NULL)
... |
Parameters to be passed to the appropriate Gemini-specific function, such as model configuration, input text, or API-specific options. |
.called_from |
An internal argument specifying which action (e.g.,
|
Some functions, such as gemini_upload_file() and gemini_delete_file(),
are specific to Gemini and do not have general verb counterparts.
The result of the requested action, depending on the specific function invoked
(e.g., an updated LLMMessage object for chat()).
Send LLMMessage to Gemini API
gemini_chat( .llm, .model = "gemini-2.5-flash", .fileid = NULL, .temperature = NULL, .max_output_tokens = NULL, .top_p = NULL, .top_k = NULL, .grounding_threshold = NULL, .presence_penalty = NULL, .frequency_penalty = NULL, .stop_sequences = NULL, .safety_settings = NULL, .json_schema = NULL, .tools = NULL, .thinking_budget = NULL, .timeout = 120, .dry_run = FALSE, .max_tries = 3, .verbose = FALSE, .stream = FALSE, .max_tool_rounds = 10 )gemini_chat( .llm, .model = "gemini-2.5-flash", .fileid = NULL, .temperature = NULL, .max_output_tokens = NULL, .top_p = NULL, .top_k = NULL, .grounding_threshold = NULL, .presence_penalty = NULL, .frequency_penalty = NULL, .stop_sequences = NULL, .safety_settings = NULL, .json_schema = NULL, .tools = NULL, .thinking_budget = NULL, .timeout = 120, .dry_run = FALSE, .max_tries = 3, .verbose = FALSE, .stream = FALSE, .max_tool_rounds = 10 )
.llm |
An existing LLMMessage object or an initial text prompt. |
.model |
The model identifier (default: "gemini-1.5-flash"). |
.fileid |
Optional vector of file IDs uploaded via |
.temperature |
Controls randomness in generation (default: NULL, range: 0.0-2.0). |
.max_output_tokens |
Maximum tokens in the response (default: NULL). |
.top_p |
Controls nucleus sampling (default: NULL, range: 0.0-1.0). |
.top_k |
Controls diversity in token selection (default: NULL, range: 0 or more). |
.grounding_threshold |
A grounding threshold between 0 and 1. With lower grounding thresholds Gemini will use Google to search for relevant information before answering. (default: NULL). |
.presence_penalty |
Penalizes new tokens (default: NULL, range: -2.0 to 2.0). |
.frequency_penalty |
Penalizes frequent tokens (default: NULL, range: -2.0 to 2.0). |
.stop_sequences |
Optional character sequences to stop generation (default: NULL, up to 5). |
.safety_settings |
A list of safety settings (default: NULL). |
.json_schema |
A schema to enforce an output structure |
.tools |
Either a single TOOL object or a list of TOOL objects representing the available functions for tool calls. |
.thinking_budget |
Token budget for internal reasoning (default: NULL). Works with |
.timeout |
When should our connection time out (default: 120 seconds). |
.dry_run |
If TRUE, perform a dry run and return the request object. |
.max_tries |
Maximum retries to perform request (default: 3). |
.verbose |
Should additional information be shown after the API call. |
.stream |
Should the response be streamed (default: FALSE). |
.max_tool_rounds |
Integer specifying the maximum number of tool use iterations (default: 10). Set to 1 for single-round tool use, or higher for multi-turn agentic loops. |
A new LLMMessage object containing the original messages plus the assistant's response.
Deletes a specific file from the Gemini API using its file ID.
gemini_delete_file(.file_name)gemini_delete_file(.file_name)
.file_name |
The file ID (e.g., "files/abc-123") to delete. |
Invisibly returns NULL. Prints a confirmation message upon successful deletion.
Generate Embeddings Using the Google Gemini API
gemini_embedding( .input, .model = "gemini-embedding-2-preview", .truncate = TRUE, .timeout = 120, .dry_run = FALSE, .max_tries = 3 )gemini_embedding( .input, .model = "gemini-embedding-2-preview", .truncate = TRUE, .timeout = 120, .dry_run = FALSE, .max_tries = 3 )
.input |
A character vector of texts to embed or an |
.model |
The embedding model identifier (default: "text-embedding-3-small"). |
.truncate |
Whether to truncate inputs to fit the model's context length (default: TRUE). |
.timeout |
Timeout for the API request in seconds (default: 120). |
.dry_run |
If TRUE, perform a dry run and return the request object. |
.max_tries |
Maximum retry attempts for requests (default: 3). |
A matrix where each column corresponds to the embedding of a message in the message history.
Retrieves metadata for a specific file uploaded to the Gemini API.
gemini_file_metadata(.file_name)gemini_file_metadata(.file_name)
.file_name |
The file ID (e.g., "files/abc-123") to retrieve metadata for. |
A tibble containing metadata fields such as name, display name, MIME type, size, and URI.
Lists metadata for files uploaded to the Gemini API, supporting pagination.
gemini_list_files(.page_size = 10, .page_token = NULL)gemini_list_files(.page_size = 10, .page_token = NULL)
.page_size |
The maximum number of files to return per page (default: 10, maximum: 100). |
.page_token |
A token for fetching the next page of results (default: NULL). |
A tibble containing metadata for each file, including fields such as name, display name, MIME type, and URI.
List Available Models from the Google Gemini API
gemini_list_models(.timeout = 60, .max_tries = 3, .dry_run = FALSE)gemini_list_models(.timeout = 60, .max_tries = 3, .dry_run = FALSE)
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum number of retries for the API request (default: 3). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it. |
A tibble containing model information with columns including name, base_model_id,
version, display_name, description, input_token_limit, output_token_limit,
supported_generation_methods, thinking, temperature, max_temperature, top_p, and top_k,
or NULL if no models are found.
Uploads a file to the Gemini API and returns its metadata as a tibble.
gemini_upload_file(.file_path)gemini_upload_file(.file_path)
.file_path |
The local file path of the file to upload. |
A tibble containing metadata about the uploaded file, including its name, URI, and MIME type.
Extracts token log probabilities from assistant replies within an LLMMessage object.
Each row represents a token with its log probability and top alternative tokens.
get_logprobs(.llm, .index = NULL)get_logprobs(.llm, .index = NULL)
.llm |
An |
.index |
A positive integer specifying which assistant reply's log probabilities to extract.
If |
An empty tibble is output if no logprobs were requested. Works with openai_chat(), llamacpp_chat(), and other providers that support logprobs.
Columns include:
reply_index: The index of the assistant reply in the message history.
token: The generated token.
logprob: The log probability of the generated token.
bytes: The byte-level encoding of the token.
top_logprobs: A list column containing the top alternative tokens with their log probabilities.
A tibble containing log probabilities for the specified assistant reply or all replies.
Retrieves metadata from assistant replies within an LLMMessage object.
It returns the metadata as a tibble.
get_metadata(.llm, .index = NULL) last_metadata(.llm)get_metadata(.llm, .index = NULL) last_metadata(.llm)
.llm |
An |
.index |
A positive integer specifying which assistant reply's metadata to extract.
If |
Metadata columns may include:
model: The model used for generating the reply.
timestamp: The time when the reply was generated.
prompt_tokens: The number of tokens in the input prompt.
completion_tokens: The number of tokens in the assistant's reply.
total_tokens: The total number of tokens (prompt + completion).
api_specific: A list column with API-specific metadata.
For convenience, last_metadata() is provided to retrieve the metadata for the last message.
A tibble containing metadata for the specified assistant reply or all replies.
Extracts the plain text content of the assistant's reply from an LLMMessage object.
Use get_reply_data() for structured replies in JSON format.
get_reply(.llm, .index = NULL) last_reply(.llm)get_reply(.llm, .index = NULL) last_reply(.llm)
.llm |
An |
.index |
A positive integer indicating the index of the assistant reply to retrieve.
Defaults to |
This function is the core utility for retrieving assistant replies by index.
For convenience, last_reply() is provided as a wrapper to retrieve the
latest assistant reply.
Returns a character string containing the assistant's reply, or NA_character_ if no reply exists.
get_reply_data(), last_reply()
Parses the assistant's reply as JSON and returns the corresponding structured data. If the reply is not marked as JSON, attempts to extract and parse JSON content from the text.
get_reply_data(.llm, .index = NULL) last_reply_data(.llm)get_reply_data(.llm, .index = NULL) last_reply_data(.llm)
.llm |
An |
.index |
A positive integer indicating the index of the assistant reply to retrieve.
Defaults to |
For convenience, last_reply_data() is provided as a wrapper to retrieve the
latest assistant reply's data.
Returns the parsed data from the assistant's reply, or NULL if parsing fails.
get_reply(), last_reply_data()
Extracts the content of a user's message from an LLMMessage object at a specific index.
get_user_message(.llm, .index = NULL) last_user_message(.llm)get_user_message(.llm, .index = NULL) last_user_message(.llm)
.llm |
An |
.index |
A positive integer indicating which user message to retrieve. Defaults to |
For convenience, last_user_message() is provided as a wrapper to retrieve the
latest user message without specifying an index.
Returns the content of the user's message at the specified index. If no messages are found, returns NA_character_.
The groq() function acts as an interface for interacting with the Groq API
through tidyllm's main verbs. Currently, Groq only supports groq_chat()
for chat-based interactions and groq_transcribe() for transcription tasks.
groq(..., .called_from = NULL)groq(..., .called_from = NULL)
... |
Parameters to be passed to the Groq-specific function, such as model configuration, input text, or API-specific options. |
.called_from |
An internal argument that specifies which action (e.g.,
|
Since groq_transcribe() is unique to Groq and does not have a general verb counterpart,
groq() currently routes messages only to groq_chat() when used with verbs like chat().
The result of the requested action, depending on the specific function invoked
(currently, only an updated LLMMessage object for groq_chat()).
This function sends a message history to the Groq Chat API and returns the assistant's reply.
groq_chat( .llm, .model = "openai/gpt-oss-120b", .max_tokens = 1024, .temperature = NULL, .top_p = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .stop = NULL, .seed = NULL, .tools = NULL, .tool_choice = NULL, .api_url = "https://api.groq.com/", .json_schema = NULL, .timeout = 60, .verbose = FALSE, .stream = FALSE, .dry_run = FALSE, .max_tries = 3, .max_tool_rounds = 10 )groq_chat( .llm, .model = "openai/gpt-oss-120b", .max_tokens = 1024, .temperature = NULL, .top_p = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .stop = NULL, .seed = NULL, .tools = NULL, .tool_choice = NULL, .api_url = "https://api.groq.com/", .json_schema = NULL, .timeout = 60, .verbose = FALSE, .stream = FALSE, .dry_run = FALSE, .max_tries = 3, .max_tool_rounds = 10 )
.llm |
An |
.model |
The identifier of the model to use (default: "llama-3.2-11b-vision-preview"). |
.max_tokens |
The maximum number of tokens that can be generated in the response (default: 1024). |
.temperature |
Controls the randomness in the model's response. Values between 0 and 2 are allowed, where higher values increase randomness (optional). |
.top_p |
Nucleus sampling parameter that controls the proportion of probability mass considered. Values between 0 and 1 are allowed (optional). |
.frequency_penalty |
Number between -2.0 and 2.0. Positive values penalize repeated tokens, reducing likelihood of repetition (optional). |
.presence_penalty |
Number between -2.0 and 2.0. Positive values encourage new topics by penalizing tokens that have appeared so far (optional). |
.stop |
One or more sequences where the API will stop generating further tokens. Can be a string or a list of strings (optional). |
.seed |
An integer for deterministic sampling. If specified, attempts to return the same result for repeated requests with identical parameters (optional). |
.tools |
Either a single TOOL object or a list of TOOL objects representing the available functions for tool calls (optional). |
.tool_choice |
A character string specifying the tool-calling behavior; valid values are "none", "auto", or "required" (optional). |
.api_url |
Base URL for the Groq API (default: "https://api.groq.com/"). |
.json_schema |
A list or tidyllm schema created with |
.timeout |
Request timeout in seconds (default: 60). |
.verbose |
If TRUE, displays additional information after the API call, including rate limit details (default: FALSE). |
.stream |
Logical; if TRUE, streams the response piece by piece (default: FALSE). |
.dry_run |
If TRUE, performs a dry run and returns the constructed request object without executing it (default: FALSE). |
.max_tries |
Maximum retries to peform request |
.max_tool_rounds |
Integer specifying the maximum number of tool use iterations (default: 10). Set to 1 for single-round tool use, or higher for multi-turn agentic loops. |
A new LLMMessage object containing the original messages plus the assistant's response.
## Not run: # Basic usage msg <- llm_message("What is Groq?") result <- groq_chat(msg) # With custom parameters result2 <- groq_chat(msg, .model = "llama-3.2-vision", .temperature = 0.5, .max_tokens = 512) ## End(Not run)## Not run: # Basic usage msg <- llm_message("What is Groq?") result <- groq_chat(msg) # With custom parameters result2 <- groq_chat(msg, .model = "llama-3.2-vision", .temperature = 0.5, .max_tokens = 512) ## End(Not run)
List Available Models from the Groq API
groq_list_models( .api_url = "https://api.groq.com", .timeout = 60, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE )groq_list_models( .api_url = "https://api.groq.com", .timeout = 60, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE )
.api_url |
Base URL for the API (default: "https://api.groq.com"). |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum number of retries for the API request (default: 3). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it. |
.verbose |
Logical; if TRUE, prints additional information about the request. |
A tibble containing model information (columns include id, created, owned_by, and context_window),
or NULL if no models are found.
This function reads an audio file and sends it to the Groq transcription API for transcription.
groq_transcribe( .audio_file, .model = "playai-tts", .language = NULL, .prompt = NULL, .temperature = 0, .api_url = "https://api.groq.com/openai/v1/audio/transcriptions", .dry_run = FALSE, .verbose = FALSE, .max_tries = 3 )groq_transcribe( .audio_file, .model = "playai-tts", .language = NULL, .prompt = NULL, .temperature = 0, .api_url = "https://api.groq.com/openai/v1/audio/transcriptions", .dry_run = FALSE, .verbose = FALSE, .max_tries = 3 )
.audio_file |
The path to the audio file (required). Supported formats include flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. |
.model |
The model to use for transcription (default: "whisper-large-v3"). |
.language |
The language of the input audio, in ISO-639-1 format (optional). |
.prompt |
A prompt to guide the transcription style. It should match the audio language (optional). |
.temperature |
Sampling temperature, between 0 and 1, with higher values producing more randomness (default: 0). |
.api_url |
Base URL for the API (default: "https://api.groq.com/openai/v1/audio/transcriptions"). |
.dry_run |
Logical; if TRUE, performs a dry run and returns the request object without making the API call (default: FALSE). |
.verbose |
Logical; if TRUE, rate limiting info is displayed after the API request (default: FALSE). |
.max_tries |
Maximum retries to peform request |
A character vector containing the transcription.
## Not run: # Basic usage groq_transcribe(.audio_file = "example.mp3") ## End(Not run)## Not run: # Basic usage groq_transcribe(.audio_file = "example.mp3") ## End(Not run)
This function reads an image file from disk, encodes it in base64,
and returns a tidyllm_image object that can be used in multimodal
embedding requests or attached to messages via .media.
img(.path)img(.path)
.path |
The path to the image file on disk. |
A tidyllm_image object.
Retrieves batch request details from the Azure OpenAI Batch API.
list_azure_openai_batches( .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .limit = 20, .max_tries = 3, .timeout = 60 )list_azure_openai_batches( .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .limit = 20, .max_tries = 3, .timeout = 60 )
.endpoint_url |
Base URL for the API (default: Sys.getenv("AZURE_ENDPOINT_URL")). |
.limit |
Maximum number of batches to retrieve (default: 20). |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.timeout |
Request timeout in seconds (default: 60). |
A tibble with batch details: batch ID, status, creation time, expiration time, and request counts (total, completed, failed).
List all Batch Requests on a Batch API
list_batches(.provider = getOption("tidyllm_lbatch_default"))list_batches(.provider = getOption("tidyllm_lbatch_default"))
.provider |
A function or function call specifying the language model provider and any additional parameters.
This should be a call to a provider function like |
A tibble with information about the status of batch processing.
Retrieves batch request details from the Claude API.
list_claude_batches( .api_url = "https://api.anthropic.com/", .limit = 20, .max_tries = 3, .timeout = 60 )list_claude_batches( .api_url = "https://api.anthropic.com/", .limit = 20, .max_tries = 3, .timeout = 60 )
.api_url |
Base URL for the Claude API (default: "https://api.anthropic.com/"). |
.limit |
Maximum number of batches to retrieve (default: 20). |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.timeout |
Request timeout in seconds (default: 60). |
A tibble with batch details: batch ID, status, creation time, expiration time, and request counts (succeeded, errored, expired, canceled).
List Files Stored on a Provider
list_files(.provider, ...)list_files(.provider, ...)
.provider |
A provider function call. |
... |
Additional provider-specific arguments. |
A tibble of file metadata.
Returns a tibble with recent Gemini batch operations and their metadata.
list_gemini_batches( .filter = NULL, .page_size = 20, .timeout = 60, .max_tries = 3, .dry_run = FALSE )list_gemini_batches( .filter = NULL, .page_size = 20, .timeout = 60, .max_tries = 3, .dry_run = FALSE )
.filter |
Optional filter expression for batch listing (see Gemini API docs). |
.page_size |
Integer. Maximum number of results to return. Default: 20. |
.timeout |
Integer. Request timeout in seconds. Default: 60. |
.max_tries |
Integer. Maximum retry attempts. Default: 3. |
.dry_run |
Logical. If TRUE, returns the request object (for debugging). Default: FALSE. |
A tibble with columns: name, state, done, create_time, complete_time.
Retrieves batch request details from the Groq API.
list_groq_batches( .api_url = "https://api.groq.com/", .limit = 20, .max_tries = 3, .timeout = 60 )list_groq_batches( .api_url = "https://api.groq.com/", .limit = 20, .max_tries = 3, .timeout = 60 )
.api_url |
Base URL for the Groq API (default: "https://api.groq.com/"). |
.limit |
Maximum number of batches to retrieve (default: 20). |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.timeout |
Request timeout in seconds (default: 60). |
A tibble with batch details including batch ID, status, creation time, and request counts.
Calls the Hugging Face Hub API to list all .gguf files in a repository,
along with their sizes. Useful for choosing a quantization level before
calling llamacpp_download_model().
list_hf_gguf_files(.repo, .timeout = 30)list_hf_gguf_files(.repo, .timeout = 30)
.repo |
Hugging Face repository ID in |
.timeout |
Request timeout in seconds (default: 30). |
A tibble with columns filename, size_gb, and url.
Retrieves batch request details from the OpenAI Batch API.
list_mistral_batches( .limit = 100, .max_tries = 3, .timeout = 60, .status = NULL, .created_after = NULL )list_mistral_batches( .limit = 100, .max_tries = 3, .timeout = 60, .status = NULL, .created_after = NULL )
.limit |
Maximum number of batches to retrieve (default: 20). |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.timeout |
Request timeout in seconds (default: 60). |
.status |
Filter by status. (default: NULL) |
.created_after |
created after a string specifiying a date-time (default: NULL) |
A tibble with batch details for all batches fitting the request
The list_models() function retrieves available models from the specified provider.
list_models(.provider = getOption("tidyllm_lmodels_default"), ...)list_models(.provider = getOption("tidyllm_lmodels_default"), ...)
.provider |
A function or function call specifying the provider and any additional parameters.
You can also set a default provider via the |
... |
Additional arguments to be passed to the provider-specific list_models function. |
A tibble containing model information.
Retrieves batch request details from the OpenAI Batch API.
list_openai_batches(.limit = 20, .max_tries = 3, .timeout = 60)list_openai_batches(.limit = 20, .max_tries = 3, .timeout = 60)
.limit |
Maximum number of batches to retrieve (default: 20). |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.timeout |
Request timeout in seconds (default: 60). |
A tibble with batch details: batch ID, status, creation time, expiration time, and request counts (total, completed, failed).
The llamacpp() provider connects tidyllm to a locally running
llama.cpp server. It exposes
the same verb/provider pattern as every other tidyllm provider while
also offering llama.cpp-specific features: BNF grammar constraints
(.grammar), token logprobs (.logprobs), and model management helpers.
The server must be started separately before calling llamacpp(). See
llamacpp_health() to verify the server is running, and
llamacpp_download_model() / list_hf_gguf_files() to obtain models.
llamacpp(..., .called_from = NULL)llamacpp(..., .called_from = NULL)
... |
Parameters passed to the appropriate llama.cpp-specific function. |
.called_from |
An internal argument specifying which verb invoked this function. Managed automatically by tidyllm verbs; do not set manually. |
The result of the requested action (e.g., an updated LLMMessage
for chat(), a tibble for embed() or list_models()).
Sends a message history to a local llama.cpp server using the OpenAI-compatible Chat Completions API. Supports BNF grammar constraints (a llama.cpp-specific feature that enforces output format at the token sampling level) and token logprobs for uncertainty quantification.
llamacpp_chat( .llm, .model = "local-model", .max_tokens = 1024, .temperature = NULL, .top_p = NULL, .stop = NULL, .stream = FALSE, .tools = NULL, .tool_choice = NULL, .json_schema = NULL, .grammar = NULL, .logprobs = FALSE, .top_logprobs = NULL, .seed = NULL, .thinking = NULL, .thinking_budget = NULL, .server = Sys.getenv("LLAMACPP_SERVER", "http://localhost:8080"), .api_key = Sys.getenv("LLAMACPP_API_KEY", ""), .timeout = 120, .verbose = FALSE, .dry_run = FALSE, .max_tries = 3, .max_tool_rounds = 10 )llamacpp_chat( .llm, .model = "local-model", .max_tokens = 1024, .temperature = NULL, .top_p = NULL, .stop = NULL, .stream = FALSE, .tools = NULL, .tool_choice = NULL, .json_schema = NULL, .grammar = NULL, .logprobs = FALSE, .top_logprobs = NULL, .seed = NULL, .thinking = NULL, .thinking_budget = NULL, .server = Sys.getenv("LLAMACPP_SERVER", "http://localhost:8080"), .api_key = Sys.getenv("LLAMACPP_API_KEY", ""), .timeout = 120, .verbose = FALSE, .dry_run = FALSE, .max_tries = 3, .max_tool_rounds = 10 )
.llm |
An |
.model |
The model name (default: |
.max_tokens |
Maximum tokens in the response (default: 1024). |
.temperature |
Controls randomness (0–2, optional). |
.top_p |
Nucleus sampling parameter (0–1, optional). |
.stop |
One or more stop sequences (optional). |
.stream |
Logical; if TRUE, streams the response (default: FALSE). |
.tools |
Either a single TOOL object or a list of TOOL objects. |
.tool_choice |
Tool-calling behavior: |
.json_schema |
A JSON schema as an R list to enforce structured output. Passed
as |
.grammar |
A BNF grammar string to constrain sampling to any formal language
(e.g. |
.logprobs |
Logical; if TRUE, returns token log-probabilities (default: FALSE). |
.top_logprobs |
Integer; number of top-alternative log-prob entries to return
per token (1–20, optional). Requires |
.seed |
Integer; random seed for reproducible outputs (optional). |
.thinking |
Logical; if TRUE, enables extended reasoning/thinking mode for models
that support it (e.g. Qwen3). |
.thinking_budget |
Integer; maximum tokens the model may use for thinking when
|
.server |
Base URL of the llama.cpp server. Defaults to the |
.api_key |
API key for the llama.cpp server. Defaults to the |
.timeout |
Request timeout in seconds (default: 120). |
.verbose |
If TRUE, displays additional information (default: FALSE). |
.dry_run |
If TRUE, returns the request object without executing it (default: FALSE). |
.max_tries |
Maximum retries (default: 3). |
.max_tool_rounds |
Maximum tool use iterations (default: 10). |
A new LLMMessage object containing the original messages plus the
assistant's response.
Deletes a GGUF file from disk. Issues a warning confirming the deletion.
Mirrors the ollama_delete_model() pattern.
llamacpp_delete_model(.path)llamacpp_delete_model(.path)
.path |
Full path to the |
Invisibly returns TRUE on success.
Downloads a single GGUF file from a Hugging Face repository with a streaming
progress bar. Use list_hf_gguf_files() first to browse available quantizations.
llamacpp_download_model( .repo, .filename, .dir = Sys.getenv("LLAMACPP_MODEL_DIR", "~/models"), .timeout = 3600 )llamacpp_download_model( .repo, .filename, .dir = Sys.getenv("LLAMACPP_MODEL_DIR", "~/models"), .timeout = 3600 )
.repo |
Hugging Face repository ID (e.g. |
.filename |
The exact filename to download (e.g. |
.dir |
Destination directory. Defaults to |
.timeout |
Download timeout in seconds (default: 3600). |
Invisibly returns the full path of the downloaded file.
Sends text to the /v1/embeddings endpoint of a running llama.cpp server
and returns embedding vectors.
llamacpp_embedding( .input, .model = "local-model", .server = Sys.getenv("LLAMACPP_SERVER", "http://localhost:8080"), .api_key = Sys.getenv("LLAMACPP_API_KEY", ""), .timeout = 120, .dry_run = FALSE, .max_tries = 3 )llamacpp_embedding( .input, .model = "local-model", .server = Sys.getenv("LLAMACPP_SERVER", "http://localhost:8080"), .api_key = Sys.getenv("LLAMACPP_API_KEY", ""), .timeout = 120, .dry_run = FALSE, .max_tries = 3 )
.input |
A character vector of texts to embed, or an |
.model |
The model name (default: |
.server |
Base URL of the llama.cpp server. Defaults to the |
.api_key |
API key for the server (default: |
.timeout |
Request timeout in seconds (default: 120). |
.dry_run |
If TRUE, returns the request object without executing it (default: FALSE). |
.max_tries |
Maximum retries (default: 3). |
A tibble with columns input (text) and embeddings (list of numeric vectors).
Calls the /health endpoint of a running llama.cpp server.
Returns the status string ("ok", "loading model", "no model loaded",
or "error") along with the full parsed response body as a named list.
llamacpp_health( .server = Sys.getenv("LLAMACPP_SERVER", "http://localhost:8080"), .timeout = 10 )llamacpp_health( .server = Sys.getenv("LLAMACPP_SERVER", "http://localhost:8080"), .timeout = 10 )
.server |
Base URL of the llama.cpp server. Defaults to |
.timeout |
Request timeout in seconds (default: 10). |
A named list with at least a status element.
Scans a directory for .gguf files and returns a tibble with their names,
sizes, and modification times. No server needed.
llamacpp_list_local_models( .path = Sys.getenv("LLAMACPP_MODEL_DIR", "~/models") )llamacpp_list_local_models( .path = Sys.getenv("LLAMACPP_MODEL_DIR", "~/models") )
.path |
Directory to scan (default: |
A tibble with columns filename, size_gb, modified, and path.
Calls the /v1/models endpoint of a running llama.cpp server and returns
the currently loaded model(s) as a tibble. In normal operation this is one
row; two rows appear when speculative decoding is active (main + draft model).
llamacpp_list_models( .server = Sys.getenv("LLAMACPP_SERVER", "http://localhost:8080"), .api_key = Sys.getenv("LLAMACPP_API_KEY", ""), .timeout = 30, .max_tries = 3 )llamacpp_list_models( .server = Sys.getenv("LLAMACPP_SERVER", "http://localhost:8080"), .api_key = Sys.getenv("LLAMACPP_API_KEY", ""), .timeout = 30, .max_tries = 3 )
.server |
Base URL of the llama.cpp server. Defaults to |
.api_key |
API key for the server (default: |
.timeout |
Request timeout in seconds (default: 30). |
.max_tries |
Maximum retries (default: 3). |
A tibble with columns id, object, and created.
Calls the /v1/reranking endpoint of a running llama.cpp server to score
documents by relevance to a query. Useful for building fully-local RAG
pipelines (embed → cosine search → rerank → chat, all with llamacpp()).
llamacpp_rerank( .query, .documents, .model = "local-model", .server = Sys.getenv("LLAMACPP_SERVER", "http://localhost:8080"), .api_key = Sys.getenv("LLAMACPP_API_KEY", ""), .timeout = 60, .max_tries = 3, .dry_run = FALSE )llamacpp_rerank( .query, .documents, .model = "local-model", .server = Sys.getenv("LLAMACPP_SERVER", "http://localhost:8080"), .api_key = Sys.getenv("LLAMACPP_API_KEY", ""), .timeout = 60, .max_tries = 3, .dry_run = FALSE )
.query |
A single query string. |
.documents |
A character vector of documents to rerank. |
.model |
The model name (default: |
.server |
Base URL of the llama.cpp server. Defaults to |
.api_key |
API key for the server (default: |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum retries (default: 3). |
.dry_run |
If TRUE, returns the request object without executing it (default: FALSE). |
A tibble with columns index (original position), document (text),
and relevance_score, sorted by descending score.
This function creates a new LLMMessage object or updates an existing one.
It supports adding text prompts and various media types, such as images, PDFs, text files, or plots.
llm_message( .llm = NULL, .prompt = NULL, .role = "user", .system_prompt = "You are a helpful assistant", .media = NULL, .files = NULL, .imagefile = NULL, .pdf = NULL, .textfile = NULL, .capture_plot = FALSE, .f = NULL )llm_message( .llm = NULL, .prompt = NULL, .role = "user", .system_prompt = "You are a helpful assistant", .media = NULL, .files = NULL, .imagefile = NULL, .pdf = NULL, .textfile = NULL, .capture_plot = FALSE, .f = NULL )
.llm |
An existing LLMMessage object or an initial text prompt. |
.prompt |
Text prompt to add to the message history. |
.role |
The role of the message sender, typically "user" or "assistant". |
.system_prompt |
Default system prompt if a new LLMMessage needs to be created. |
.media |
An inline media object or a list of them. Accepted types: |
.files |
A |
.imagefile |
Path to an image file to be attached (optional). Deprecated; use |
.pdf |
Path to a PDF file to be attached (optional). Deprecated; use |
.textfile |
Path to a text file to be read and attached (optional). |
.capture_plot |
Boolean to indicate whether a plot should be captured and attached as an image (optional). |
.f |
An R function or an object coercible to a function via |
Returns an updated or new LLMMessage object.
Other Message Creation Utilities:
df_llm_message()
LLMMessage is an S7 class for managing a conversation history intended for use with large language models (LLMs). Please use
llm_message()to create or modify LLMMessage objects.
LLMMessage(message_history = list(), system_prompt = character(0))LLMMessage(message_history = list(), system_prompt = character(0))
message_history |
A list containing messages. Each message is a named list with keys like |
system_prompt |
A character string representing the default system prompt used for the conversation. |
The LLMMessage class includes the following features:
Stores message history in a structured format.
Supports attaching media and metadata to messages.
Provides generics like add_message(), has_image(), and remove_message() for interaction.
Enables API-specific formatting through the to_api_format() generic.
message_history: A list containing messages. Each message is a named list with keys like role, content, media, etc.
system_prompt: A character string representing the default system prompt used for the conversation.
The mistral() function acts as an interface for interacting with the Mistral API
through main tidyllm verbs such as chat() and embed().
It dynamically routes requests to Mistral-specific functions
like mistral_chat() and mistral_embedding() based on the context of the call.
mistral(..., .called_from = NULL)mistral(..., .called_from = NULL)
... |
Parameters to be passed to the appropriate Mistral-specific function, such as model configuration, input text, or API-specific options. |
.called_from |
An internal argument that specifies which action (e.g.,
|
The result of the requested action, depending on the specific function invoked
(e.g., an updated LLMMessage object for chat(), or a matrix for embed()).
Send LLMMessage to Mistral API
mistral_chat( .llm, .model = "mistral-large-latest", .frequency_penalty = NULL, .logit_bias = NULL, .presence_penalty = NULL, .seed = NULL, .stop = NULL, .stream = FALSE, .temperature = 0.7, .top_p = 1, .min_tokens = NULL, .max_tokens = NULL, .json_schema = NULL, .safe_prompt = FALSE, .reasoning_effort = NULL, .timeout = 120, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE, .tools = NULL, .tool_choice = NULL, .max_tool_rounds = 10 )mistral_chat( .llm, .model = "mistral-large-latest", .frequency_penalty = NULL, .logit_bias = NULL, .presence_penalty = NULL, .seed = NULL, .stop = NULL, .stream = FALSE, .temperature = 0.7, .top_p = 1, .min_tokens = NULL, .max_tokens = NULL, .json_schema = NULL, .safe_prompt = FALSE, .reasoning_effort = NULL, .timeout = 120, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE, .tools = NULL, .tool_choice = NULL, .max_tool_rounds = 10 )
.llm |
An |
.model |
The model identifier to use (default: |
.frequency_penalty |
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency. |
.logit_bias |
A named list modifying the likelihood of specified tokens appearing in the completion. |
.presence_penalty |
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far. |
.seed |
If specified, the system will make a best effort to sample deterministically. |
.stop |
Up to 4 sequences where the API will stop generating further tokens. |
.stream |
If set to TRUE, the answer will be streamed to console as it comes (default: FALSE). |
.temperature |
What sampling temperature to use, between 0 and 2. Higher values make the output more random. |
.top_p |
An alternative to sampling with temperature, called nucleus sampling. |
.min_tokens |
The minimum number of tokens to generate in the completion. Must be |
.max_tokens |
An upper bound for the number of tokens that can be generated for a completion. |
.json_schema |
A JSON schema object provided by tidyllm schema or ellmer schemata. |
.safe_prompt |
Whether to inject a safety prompt before all conversations (default: |
.reasoning_effort |
Controls the reasoning effort for Magistral thinking models; one of |
.timeout |
When should our connection time out in seconds (default: |
.max_tries |
Maximum retries to peform request |
.dry_run |
If |
.verbose |
Should additional information be shown after the API call? (default: |
.tools |
Either a single TOOL object or a list of TOOL objects representing the available functions for tool calls. |
.tool_choice |
A character string specifying the tool-calling behavior; valid values are "none", "auto", or "required". |
.max_tool_rounds |
Integer specifying the maximum number of tool use iterations (default: 10). Set to 1 for single-round tool use, or higher for multi-turn agentic loops. |
Returns an updated LLMMessage object.
Generate Embeddings Using Mistral API
mistral_embedding( .input, .model = "mistral-embed", .timeout = 120, .max_tries = 3, .dry_run = FALSE )mistral_embedding( .input, .model = "mistral-embed", .timeout = 120, .max_tries = 3, .dry_run = FALSE )
.input |
A character vector of texts to embed or an |
.model |
The embedding model identifier (default: "mistral-embed"). |
.timeout |
Timeout for the API request in seconds (default: 120). |
.max_tries |
Maximum retries to peform request |
.dry_run |
If TRUE, perform a dry run and return the request object. |
A matrix where each column corresponds to the embedding of a message in the message history.
List Available Models from the Mistral API
mistral_list_models( .api_url = "https://api.mistral.ai", .timeout = 60, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE )mistral_list_models( .api_url = "https://api.mistral.ai", .timeout = 60, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE )
.api_url |
Base URL for the API (default: "https://api.mistral.ai"). |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum number of retries for the API request (default: 3). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it. |
.verbose |
Logical; if TRUE, prints additional information about the request. |
A tibble containing model information (columns include id and created),
or NULL if no models are found.
The ollama() function acts as an interface for interacting with local AI models via the Ollama API.
It integrates seamlessly with the main tidyllm verbs such as chat() and embed().
ollama(..., .called_from = NULL)ollama(..., .called_from = NULL)
... |
Parameters to be passed to the appropriate Ollama-specific function, such as model configuration, input text, or API-specific options. |
.called_from |
An internal argument specifying the verb (e.g., |
Some functionalities, like ollama_download_model() or ollama_list_models()
are unique to the Ollama API and do not have a general verb counterpart.
These functions can be only accessed directly.
Supported Verbs:
chat(): Sends a message to an Ollama model and retrieves the model's response.
embed(): Generates embeddings for input texts using an Ollama model.
send_batch(): Behaves different than the other send_batch() verbs since it immediately processes the answers
The result of the requested action:
For chat(): An updated LLMMessage object containing the model's response.
For embed(): A matrix where each column corresponds to an embedding.
Interact with local AI models via the Ollama API
ollama_chat( .llm, .model = "qwen3.5:4b", .stream = FALSE, .seed = NULL, .json_schema = NULL, .temperature = NULL, .num_ctx = 2048, .num_predict = NULL, .top_k = NULL, .top_p = NULL, .min_p = NULL, .mirostat = NULL, .mirostat_eta = NULL, .mirostat_tau = NULL, .repeat_last_n = NULL, .repeat_penalty = NULL, .tools = NULL, .max_tool_rounds = 10, .tfs_z = NULL, .stop = NULL, .think = NULL, .ollama_server = "http://localhost:11434", .timeout = 120, .keep_alive = NULL, .dry_run = FALSE )ollama_chat( .llm, .model = "qwen3.5:4b", .stream = FALSE, .seed = NULL, .json_schema = NULL, .temperature = NULL, .num_ctx = 2048, .num_predict = NULL, .top_k = NULL, .top_p = NULL, .min_p = NULL, .mirostat = NULL, .mirostat_eta = NULL, .mirostat_tau = NULL, .repeat_last_n = NULL, .repeat_penalty = NULL, .tools = NULL, .max_tool_rounds = 10, .tfs_z = NULL, .stop = NULL, .think = NULL, .ollama_server = "http://localhost:11434", .timeout = 120, .keep_alive = NULL, .dry_run = FALSE )
.llm |
An LLMMessage object containing the conversation history and system prompt. |
.model |
Character string specifying the Ollama model to use (default: "qwen3-vl") |
.stream |
Logical; whether to stream the response (default: FALSE) |
.seed |
Integer; seed for reproducible generation (default: NULL) |
.json_schema |
A JSON schema object as R list to enforce the output structure (default: NULL) |
.temperature |
Float between 0-2; controls randomness in responses (default: NULL) |
.num_ctx |
Integer; sets the context window size (default: 2048) |
.num_predict |
Integer; maximum number of tokens to predict (default: NULL) |
.top_k |
Integer; controls diversity by limiting top tokens considered (default: NULL) |
.top_p |
Float between 0-1; nucleus sampling threshold (default: NULL) |
.min_p |
Float between 0-1; minimum probability threshold (default: NULL) |
.mirostat |
Integer (0,1,2); enables Mirostat sampling algorithm (default: NULL) |
.mirostat_eta |
Float; Mirostat learning rate (default: NULL) |
.mirostat_tau |
Float; Mirostat target entropy (default: NULL) |
.repeat_last_n |
Integer; tokens to look back for repetition (default: NULL) |
.repeat_penalty |
Float; penalty for repeated tokens (default: NULL) |
.tools |
Either a single TOOL object or a list of TOOL objects representing the available functions for tool calls. |
.max_tool_rounds |
Integer; maximum number of tool use iterations for multi-turn tool calling (default: 10). Set to 1 for single-round tool use, or higher for multi-turn agentic loops. |
.tfs_z |
Float; tail free sampling parameter (default: NULL) |
.stop |
Character; custom stop sequence(s) (default: NULL) |
.think |
Logical or character; controls thinking mode for supported models like Qwen3. Use FALSE to disable, TRUE to enable, or "high"/"medium"/"low" to set effort level (default: NULL - model default) |
.ollama_server |
String; Ollama API endpoint (default: "http://localhost:11434") |
.timeout |
Integer; API request timeout in seconds (default: 120) |
.keep_alive |
Character; How long should the ollama model be kept in memory after request (default: NULL - 5 Minutes) |
.dry_run |
Logical; if TRUE, returns request object without execution (default: FALSE) |
The function provides extensive control over the generation process through various parameters:
Temperature (0-2): Higher values increase creativity, lower values make responses more focused
Top-k/Top-p: Control diversity of generated text
Mirostat: Advanced sampling algorithm for maintaining consistent complexity
Repeat penalties: Prevent repetitive text
Context window: Control how much previous conversation is considered
A new LLMMessage object containing the original messages plus the model's response
## Not run: llm_message("user", "Hello, how are you?") response <- ollama_chat(llm, .model = "gemma2", .temperature = 0.7) # With custom parameters response <- ollama_chat( llm, .model = "llama2", .temperature = 0.8, .top_p = 0.9, .num_ctx = 4096 ) ## End(Not run)## Not run: llm_message("user", "Hello, how are you?") response <- ollama_chat(llm, .model = "gemma2", .temperature = 0.7) # With custom parameters response <- ollama_chat( llm, .model = "llama2", .temperature = 0.8, .top_p = 0.9, .num_ctx = 4096 ) ## End(Not run)
This function sends a DELETE request to the Ollama API to remove a specified model.
ollama_delete_model(.model, .ollama_server = "http://localhost:11434")ollama_delete_model(.model, .ollama_server = "http://localhost:11434")
.model |
The name of the model to delete. |
.ollama_server |
The base URL of the Ollama API (default is "http://localhost:11434"). |
This function sends a request to the Ollama API to download a specified model from Ollama's large online library of models.
ollama_download_model(.model, .ollama_server = "http://localhost:11434")ollama_download_model(.model, .ollama_server = "http://localhost:11434")
.model |
The name of the model to download. |
.ollama_server |
The base URL of the Ollama API (default is "http://localhost:11434"). |
Generate Embeddings Using Ollama API
ollama_embedding( .input, .model = "qwen3-embedding:0.6b", .truncate = TRUE, .ollama_server = "http://localhost:11434", .timeout = 120, .dry_run = FALSE )ollama_embedding( .input, .model = "qwen3-embedding:0.6b", .truncate = TRUE, .ollama_server = "http://localhost:11434", .timeout = 120, .dry_run = FALSE )
.input |
Aa charachter vector of texts to embed or an |
.model |
The embedding model identifier (default: "all-minilm"). |
.truncate |
Whether to truncate inputs to fit the model's context length (default: TRUE). |
.ollama_server |
The URL of the Ollama server to be used (default: "http://localhost:11434"). |
.timeout |
Timeout for the API request in seconds (default: 120). |
.dry_run |
If TRUE, perform a dry run and return the request object. |
A matrix where each column corresponds to the embedding of a message in the message history.
This function connects to the Ollama API and retrieves information about available models, returning it as a tibble.
ollama_list_models(.ollama_server = "http://localhost:11434")ollama_list_models(.ollama_server = "http://localhost:11434")
.ollama_server |
The URL of the ollama server to be used |
A tibble containing model information, or NULL if no models are found.
The openai() function acts as an interface for interacting with the OpenAI API
through main tidyllm verbs such as chat(), embed(), and
send_batch(). It dynamically routes requests to OpenAI-specific functions
like openai_chat() and openai_embedding() based on the context of the call.
openai(..., .called_from = NULL) openai(..., .called_from = NULL)openai(..., .called_from = NULL) openai(..., .called_from = NULL)
... |
Parameters passed to the appropriate OpenAI-specific function. |
.called_from |
Internal routing argument; do not set manually. |
The result of the requested action, depending on the specific function invoked
(e.g., an updated LLMMessage object for chat(), or a matrix for embed()).
Result of the requested action.
Sends a message history to the OpenAI Responses API (POST /v1/responses) and
returns the assistant's reply. Supports streaming, tool use, structured output,
and reasoning models (o-series) via .reasoning_effort.
openai_chat( .llm, .model = "gpt-5.5", .max_output_tokens = NULL, .temperature = NULL, .seed = NULL, .stream = FALSE, .timeout = 60, .verbose = FALSE, .json_schema = NULL, .max_tries = 3, .dry_run = FALSE, .reasoning_effort = NULL, .tools = NULL, .tool_choice = NULL, .max_tool_rounds = 10, .stateful = FALSE )openai_chat( .llm, .model = "gpt-5.5", .max_output_tokens = NULL, .temperature = NULL, .seed = NULL, .stream = FALSE, .timeout = 60, .verbose = FALSE, .json_schema = NULL, .max_tries = 3, .dry_run = FALSE, .reasoning_effort = NULL, .tools = NULL, .tool_choice = NULL, .max_tool_rounds = 10, .stateful = FALSE )
.llm |
An |
.model |
The model identifier (default: |
.max_output_tokens |
Maximum tokens to generate (caps reasoning + completion). |
.temperature |
Sampling temperature (0-2). |
.seed |
Seed for deterministic sampling. |
.stream |
If TRUE, stream output to console (default: FALSE). |
.timeout |
Request timeout in seconds (default: 60). |
.verbose |
Print rate-limit info after the call (default: FALSE). |
.json_schema |
A tidyllm schema or ellmer type for structured output. |
.max_tries |
Maximum retry attempts (default: 3). |
.dry_run |
If TRUE, return the request object without sending (default: FALSE). |
.reasoning_effort |
For o-series models: |
.tools |
A TOOL object or list of TOOL objects for function calling. |
.tool_choice |
Tool selection behavior: |
.max_tool_rounds |
Maximum tool-loop iterations (default: 10). |
.stateful |
If |
A new LLMMessage object with the assistant's response appended.
Polls the status of an OpenAI background response created by
openai_deep_research(.background = TRUE).
openai_check_research(.job, .max_tries = 3)openai_check_research(.job, .max_tries = 3)
.job |
A |
.max_tries |
Maximum retries per HTTP request (default: |
An updated tidyllm_research_job with $status set. If completed, $response
is also populated and ready for fetch_job().
OpenAI built-in code interpreter tool (server-executed)
openai_code_interpreter()openai_code_interpreter()
A TOOL object declaring the code_interpreter built-in.
Sends a research request to OpenAI using the deep research models
(o3-deep-research or o4-mini-deep-research) via the Responses API with
background: true. The model autonomously searches the web and synthesises
a long-form answer, which can take 5-30 minutes.
openai_deep_research( .llm, .model = "o4-mini-deep-research", .background = FALSE, .reasoning_effort = "medium", .json_schema = NULL, .max_output_tokens = NULL, .timeout = 1800, .max_tries = 3 )openai_deep_research( .llm, .model = "o4-mini-deep-research", .background = FALSE, .reasoning_effort = "medium", .json_schema = NULL, .max_output_tokens = NULL, .timeout = 1800, .max_tries = 3 )
.llm |
An |
.model |
The deep research model to use (default: |
.background |
Logical; if |
.reasoning_effort |
Reasoning level for the model: |
.json_schema |
A tidyllm schema for structured JSON output (optional). |
.max_output_tokens |
Maximum tokens to generate (default: |
.timeout |
Seconds to wait in blocking mode before giving up (default: |
.max_tries |
Maximum retries per HTTP request (default: |
If .background = FALSE, an updated LLMMessage with the research reply.
If .background = TRUE, a tidyllm_research_job for use with check_job()/fetch_job().
Generate Embeddings Using OpenAI API
openai_embedding( .input, .model = "text-embedding-3-small", .truncate = TRUE, .timeout = 120, .dry_run = FALSE, .max_tries = 3, .verbose = FALSE )openai_embedding( .input, .model = "text-embedding-3-small", .truncate = TRUE, .timeout = 120, .dry_run = FALSE, .max_tries = 3, .verbose = FALSE )
.input |
An existing LLMMessage object (or a character vector of texts to embed) |
.model |
The embedding model identifier (default: "text-embedding-3-small"). |
.truncate |
Whether to truncate inputs to fit the model's context length (default: TRUE). |
.timeout |
Timeout for the API request in seconds (default: 120). |
.dry_run |
If TRUE, perform a dry run and return the request object. |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.verbose |
Should information about current ratelimits be printed? (default: FALSE) |
A tibble with two columns: input and embeddings.
The input column contains the texts sent to embed, and the embeddings column
is a list column where each row contains an embedding vector of the sent input.
Extracts the assistant reply from a completed tidyllm_research_job returned
by openai_deep_research(.background = TRUE).
openai_fetch_research(.job, .max_tries = 3)openai_fetch_research(.job, .max_tries = 3)
.job |
A |
.max_tries |
Maximum retries per HTTP request (default: |
An updated LLMMessage with the research reply appended.
List Available Models from the OpenAI API
openai_list_models( .api_url = "https://api.openai.com", .timeout = 60, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE )openai_list_models( .api_url = "https://api.openai.com", .timeout = 60, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE )
.api_url |
Base URL for the API (default: "https://api.openai.com"). |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum number of retries for the API request (default: 3). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it. |
.verbose |
Logical; if TRUE, prints additional information about the request. |
A tibble containing model information (columns include id, created, and owned_by),
or NULL if no models are found.
OpenAI built-in web search tool (server-executed)
openai_websearch()openai_websearch()
A TOOL object declaring the web_search_preview built-in.
The openrouter() function provides access to hundreds of AI models from
different providers through the OpenRouter API, using a single
OpenAI-compatible interface.
openrouter(..., .called_from = NULL)openrouter(..., .called_from = NULL)
... |
Parameters passed to the appropriate OpenRouter-specific function. |
.called_from |
An internal argument specifying which verb invoked this function. Managed automatically by tidyllm verbs; do not set manually. |
The result of the requested action (e.g., an updated LLMMessage for chat()).
Sends a message history to the OpenRouter API, which provides access to hundreds of models from different providers through a single OpenAI-compatible endpoint.
openrouter_chat( .llm, .model = "anthropic/claude-sonnet-4-6", .max_tokens = 2048, .temperature = NULL, .top_p = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .stop = NULL, .stream = FALSE, .json_schema = NULL, .tools = NULL, .tool_choice = NULL, .reasoning = NULL, .provider = NULL, .route = NULL, .models = NULL, .api_url = "https://openrouter.ai", .timeout = 60, .verbose = FALSE, .dry_run = FALSE, .max_tries = 3, .max_tool_rounds = 10 )openrouter_chat( .llm, .model = "anthropic/claude-sonnet-4-6", .max_tokens = 2048, .temperature = NULL, .top_p = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .stop = NULL, .stream = FALSE, .json_schema = NULL, .tools = NULL, .tool_choice = NULL, .reasoning = NULL, .provider = NULL, .route = NULL, .models = NULL, .api_url = "https://openrouter.ai", .timeout = 60, .verbose = FALSE, .dry_run = FALSE, .max_tries = 3, .max_tool_rounds = 10 )
.llm |
An |
.model |
The model identifier to use (default: |
.max_tokens |
Maximum number of tokens in the response (default: 2048). |
.temperature |
Controls randomness (0–2, optional). |
.top_p |
Nucleus sampling parameter (0–1, optional). |
.frequency_penalty |
Penalizes repeated tokens (-2 to 2, optional). |
.presence_penalty |
Encourages new topics (-2 to 2, optional). |
.stop |
One or more stop sequences (optional). |
.stream |
Logical; if TRUE, streams the response (default: FALSE). |
.json_schema |
A JSON schema object for structured output (default: NULL). |
.tools |
Either a single TOOL object or a list of TOOL objects for tool calls. |
.tool_choice |
Tool-calling behavior: |
.reasoning |
A named list controlling reasoning token behavior (optional). Supported fields vary by model family:
Example: |
.provider |
A named list of OpenRouter provider preferences, e.g.
|
.route |
OpenRouter routing strategy; |
.models |
A character vector of model IDs to use as fallbacks when the primary
model is unavailable (optional). Used together with |
.api_url |
Base URL for the OpenRouter API (default: |
.timeout |
Request timeout in seconds (default: 60). |
.verbose |
If TRUE, displays additional information after the API call (default: FALSE). |
.dry_run |
If TRUE, returns the request object without executing it (default: FALSE). |
.max_tries |
Maximum retries (default: 3). |
.max_tool_rounds |
Maximum number of tool use iterations (default: 10). |
A new LLMMessage object containing the original messages plus the assistant's response.
Returns the total credits purchased and total usage so far for the current API key.
openrouter_credits( .api_url = "https://openrouter.ai", .timeout = 60, .max_tries = 3 )openrouter_credits( .api_url = "https://openrouter.ai", .timeout = 60, .max_tries = 3 )
.api_url |
Base URL for the OpenRouter API (default: |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum retries (default: 3). |
A tibble with columns total_credits (USD purchased), total_usage
(USD consumed so far), and remaining (USD remaining).
Sends text to an embedding model accessible via OpenRouter and returns
embedding vectors. Note that embedding models are not listed in
list_models(openrouter()) — specify the model ID directly.
Known supported models include "openai/text-embedding-3-small",
"openai/text-embedding-3-large", and "mistralai/mistral-embed".
openrouter_embedding( .input, .model = "openai/text-embedding-3-small", .timeout = 120, .dry_run = FALSE, .max_tries = 3 )openrouter_embedding( .input, .model = "openai/text-embedding-3-small", .timeout = 120, .dry_run = FALSE, .max_tries = 3 )
.input |
An |
.model |
The embedding model ID (default: |
.timeout |
Request timeout in seconds (default: 120). |
.dry_run |
If TRUE, returns the request object without executing it (default: FALSE). |
.max_tries |
Maximum retries (default: 3). |
A tibble with columns input (text) and embeddings (list of numeric vectors).
Fetches cost, latency, and token details for a past generation using its ID.
The generation ID is available in get_metadata(result)$api_specific$id
after a chat() call.
openrouter_generation( .id, .api_url = "https://openrouter.ai", .timeout = 60, .max_tries = 3 )openrouter_generation( .id, .api_url = "https://openrouter.ai", .timeout = 60, .max_tries = 3 )
.id |
The generation ID string (e.g. |
.api_url |
Base URL for the OpenRouter API (default: |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum retries (default: 3). |
A named list with generation details including id, model,
total_cost, tokens_prompt, tokens_completion, and latency.
Retrieves the list of models available through the OpenRouter API, including pricing and context window information.
openrouter_list_models( .api_url = "https://openrouter.ai", .timeout = 60, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE )openrouter_list_models( .api_url = "https://openrouter.ai", .timeout = 60, .max_tries = 3, .dry_run = FALSE, .verbose = FALSE )
.api_url |
Base URL for the OpenRouter API (default: |
.timeout |
Request timeout in seconds (default: 60). |
.max_tries |
Maximum retries (default: 3). |
.dry_run |
If TRUE, returns the request object without executing it (default: FALSE). |
.verbose |
If TRUE, displays additional information (default: FALSE). |
A tibble with columns id, name, context_length,
prompt_price_per_million, and completion_price_per_million,
or NULL if no models are found.
Stores a reference to a local PDF file along with a pdftools text extraction. Binary encoding is deferred to format time; providers that support binary PDF encode on demand, others use the stored text fallback.
pdf_file(.path, pages = NULL, .text_extract = FALSE, engine = NULL)pdf_file(.path, pages = NULL, .text_extract = FALSE, engine = NULL)
.path |
The path to the PDF file on disk. |
pages |
An integer vector of page numbers to include (e.g. |
.text_extract |
Logical; if TRUE always use pdftools text extraction regardless of provider
(equivalent to the old |
engine |
Optional engine name (e.g. |
A tidyllm_pdf object.
This function processes a PDF file page by page. For each page, it extracts the text and converts the page into an image. It creates a list of LLMMessage objects with the text and the image for multimodal processing. Users can specify a range of pages to process and provide a custom function to generate prompts for each page.
pdf_page_batch( .pdf, .general_prompt, .system_prompt = "You are a helpful assistant", .page_range = NULL, .prompt_fn = NULL )pdf_page_batch( .pdf, .general_prompt, .system_prompt = "You are a helpful assistant", .page_range = NULL, .prompt_fn = NULL )
.pdf |
Path to the PDF file. |
.general_prompt |
A default prompt that is applied to each page if |
.system_prompt |
Optional system prompt to initialize the LLMMessage (default is "You are a helpful assistant"). |
.page_range |
A vector of two integers specifying the start and end pages to process. If NULL, all pages are processed. |
.prompt_fn |
An optional custom function that generates a prompt for each page. The function takes the page text as input
and returns a string. If NULL, |
A list of LLMMessage objects, each containing the text and image for a page.
The perplexity() function acts as a provider interface for interacting with the Perplexity API
through tidyllm's chat() verb.
It dynamically routes requests to Perplxeity-specific function. At the moment this is only
perplexity_chat()
perplexity(..., .called_from = NULL)perplexity(..., .called_from = NULL)
... |
Parameters to be passed to the appropriate Perplexity-specific function, such as model configuration, input text, or API-specific options. |
.called_from |
An internal argument specifying which action (e.g.,
|
The result of the requested action, depending on the specific function invoked
(e.g., an updated LLMMessage object for chat()).
Sends a chat message history to the Perplexity Chat API, supporting all documented API parameters.
perplexity_chat( .llm, .model = "sonar", .max_tokens = 1024, .temperature = NULL, .top_p = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .stop = NULL, .search_domain_filter = NULL, .search_language_filter = NULL, .language_preference = NULL, .return_images = FALSE, .image_domain_filter = NULL, .image_format_filter = NULL, .search_recency_filter = NULL, .search_mode = "web", .search_after_date_filter = NULL, .search_before_date_filter = NULL, .last_updated_after_filter = NULL, .last_updated_before_filter = NULL, .disable_search = FALSE, .enable_search_classifier = FALSE, .reasoning_effort = NULL, .return_related_questions = FALSE, .user_location = NULL, .search_context_size = NULL, .search_type = NULL, .stream_mode = NULL, .json_schema = NULL, .top_k = NULL, .web_search_options = NULL, .api_url = "https://api.perplexity.ai/", .timeout = 60, .stream = FALSE, .verbose = FALSE, .max_tries = 3, .dry_run = FALSE )perplexity_chat( .llm, .model = "sonar", .max_tokens = 1024, .temperature = NULL, .top_p = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .stop = NULL, .search_domain_filter = NULL, .search_language_filter = NULL, .language_preference = NULL, .return_images = FALSE, .image_domain_filter = NULL, .image_format_filter = NULL, .search_recency_filter = NULL, .search_mode = "web", .search_after_date_filter = NULL, .search_before_date_filter = NULL, .last_updated_after_filter = NULL, .last_updated_before_filter = NULL, .disable_search = FALSE, .enable_search_classifier = FALSE, .reasoning_effort = NULL, .return_related_questions = FALSE, .user_location = NULL, .search_context_size = NULL, .search_type = NULL, .stream_mode = NULL, .json_schema = NULL, .top_k = NULL, .web_search_options = NULL, .api_url = "https://api.perplexity.ai/", .timeout = 60, .stream = FALSE, .verbose = FALSE, .max_tries = 3, .dry_run = FALSE )
.llm |
An |
.model |
Model name to use (default: "sonar"). |
.max_tokens |
Max completion tokens (default: 1024). |
.temperature |
Controls response randomness (0 < x < 2). |
.top_p |
Nucleus sampling threshold (0 < x < 1). |
.frequency_penalty |
Number > 0. Penalizes frequent tokens. |
.presence_penalty |
Numeric between -2 and 2. Penalizes present tokens. |
.stop |
Stop sequence(s), string or character vector/list. |
.search_domain_filter |
Character vector of domains to allowlist/denylist (max 10; prefix with "-" to denylist). |
.search_language_filter |
ISO 639-1 language code to restrict search results (e.g. "en", "de", "fr"). |
.language_preference |
ISO 639-1 code for preferred response language (e.g. "en"). |
.return_images |
Logical; if TRUE, returns images from search. |
.image_domain_filter |
Character vector of domains to restrict image results to. |
.image_format_filter |
Character vector of image formats to include (e.g. c("png", "jpg")). |
.search_recency_filter |
Restrict search to recent results: "hour", "day", "week", "month", or "year". |
.search_mode |
Search index to use: "web" (default), "academic", or "sec". |
.search_after_date_filter |
Only include content published after this date (MM/DD/YYYY). |
.search_before_date_filter |
Only include content published before this date (MM/DD/YYYY). |
.last_updated_after_filter |
Only include content last updated after this date (MM/DD/YYYY). |
.last_updated_before_filter |
Only include content last updated before this date (MM/DD/YYYY). |
.disable_search |
Logical; if TRUE, disables web search entirely (default: FALSE). |
.enable_search_classifier |
Logical; if TRUE, lets the model decide whether to search (default: FALSE). |
.reasoning_effort |
Reasoning level: "low", "medium", or "high". |
.return_related_questions |
Logical; if TRUE, returns related questions. |
.user_location |
Named list for geographic search personalisation. Accepted fields:
|
.search_context_size |
Amount of search context to include: "low", "medium" (default), or "high". |
.search_type |
Search quality preference inside |
.stream_mode |
Response format: "full" (default) or "concise". |
.json_schema |
A tidyllm schema created with |
.top_k |
Top-k token sampling (integer, 0 disables). |
.web_search_options |
Named list with raw web_search_options overrides. Values set here take precedence over the dedicated parameters above. |
.api_url |
API endpoint (default: "https://api.perplexity.ai/"). |
.timeout |
Timeout in seconds (default: 60). |
.stream |
If TRUE, streams response. |
.verbose |
If TRUE, prints additional info. |
.max_tries |
Max request retries (default: 3). |
.dry_run |
If TRUE, returns constructed request instead of sending. |
An updated LLMMessage object with the assistant's reply and metadata, including citations and search_results.
Check the Status of a Perplexity Deep Research Job
perplexity_check_research( .job, .api_key = Sys.getenv("PERPLEXITY_API_KEY"), .max_tries = 3 )perplexity_check_research( .job, .api_key = Sys.getenv("PERPLEXITY_API_KEY"), .max_tries = 3 )
.job |
A |
.api_key |
Character; Perplexity API key (default: from environment). |
.max_tries |
Integer; maximum retries (default: 3). |
An updated tidyllm_research_job with a $status field and $response if completed.
Submit a Deep Research Request to Perplexity
perplexity_deep_research( .llm, .background = FALSE, .reasoning_effort = "medium", .search_context_size = "medium", .search_domain_filter = NULL, .search_language_filter = NULL, .language_preference = NULL, .search_recency_filter = NULL, .search_mode = NULL, .search_after_date_filter = NULL, .search_before_date_filter = NULL, .last_updated_after_filter = NULL, .last_updated_before_filter = NULL, .user_location = NULL, .json_schema = NULL, .idempotency_key = NULL, .api_key = Sys.getenv("PERPLEXITY_API_KEY"), .timeout = 300, .max_tries = 3 )perplexity_deep_research( .llm, .background = FALSE, .reasoning_effort = "medium", .search_context_size = "medium", .search_domain_filter = NULL, .search_language_filter = NULL, .language_preference = NULL, .search_recency_filter = NULL, .search_mode = NULL, .search_after_date_filter = NULL, .search_before_date_filter = NULL, .last_updated_after_filter = NULL, .last_updated_before_filter = NULL, .user_location = NULL, .json_schema = NULL, .idempotency_key = NULL, .api_key = Sys.getenv("PERPLEXITY_API_KEY"), .timeout = 300, .max_tries = 3 )
.llm |
An |
.background |
Logical; if TRUE, returns a |
.reasoning_effort |
Reasoning level: "low", "medium" (default), or "high". |
.search_context_size |
Amount of search context: "low", "medium" (default), or "high". |
.search_domain_filter |
Character vector of domains to allowlist/denylist (max 10; prefix with "-" to denylist). |
.search_language_filter |
ISO 639-1 language code to restrict search results (e.g. "en", "de"). |
.language_preference |
ISO 639-1 code for preferred response language. |
.search_recency_filter |
Restrict search to recent results: "hour", "day", "week", "month", or "year". |
.search_mode |
Search index to use: "web" (default), "academic", or "sec". |
.search_after_date_filter |
Only include content published after this date (MM/DD/YYYY). |
.search_before_date_filter |
Only include content published before this date (MM/DD/YYYY). |
.last_updated_after_filter |
Only include content last updated after this date (MM/DD/YYYY). |
.last_updated_before_filter |
Only include content last updated before this date (MM/DD/YYYY). |
.user_location |
Named list for geographic search personalisation (fields: country, city, region, latitude, longitude). |
.json_schema |
A tidyllm schema created with |
.idempotency_key |
Optional string; unique key to prevent duplicate submissions. |
.api_key |
Character; Perplexity API key (default: from environment variable). |
.timeout |
Integer; request timeout in seconds for blocking polling (default: 300). |
.max_tries |
Integer; maximum retries (default: 3). |
If .background = FALSE, an updated LLMMessage with the research reply.
If .background = TRUE, a tidyllm_research_job object.
Fetch Results from a Completed Perplexity Deep Research Job
perplexity_fetch_research( .job, .api_key = Sys.getenv("PERPLEXITY_API_KEY"), .max_tries = 3 )perplexity_fetch_research( .job, .api_key = Sys.getenv("PERPLEXITY_API_KEY"), .max_tries = 3 )
.job |
A |
.api_key |
Character; Perplexity API key (default: from environment). |
.max_tries |
Integer; maximum retries (default: 3). |
An updated LLMMessage with the research reply appended.
This function retrieves the rate limit details for the specified API, or for all APIs stored in the .tidyllm_rate_limit_env if no API is specified.
rate_limit_info(.api_name = NULL)rate_limit_info(.api_name = NULL)
.api_name |
(Optional) The name of the API whose rate limit info you want to get If not provided, the rate limit info for all APIs in the environment will be returned |
A tibble containing the rate limit information.
This function creates and submits a batch of messages to the Azure OpenAI Batch API for asynchronous processing.
send_azure_openai_batch( .llms, .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .deployment = "gpt-4o-mini", .api_version = "2024-10-01-preview", .max_completion_tokens = NULL, .reasoning_effort = NULL, .frequency_penalty = NULL, .logit_bias = NULL, .presence_penalty = NULL, .seed = NULL, .stop = NULL, .temperature = NULL, .top_p = NULL, .logprobs = NULL, .top_logprobs = NULL, .dry_run = FALSE, .overwrite = FALSE, .max_tries = 3, .timeout = 60, .verbose = FALSE, .json_schema = NULL, .id_prefix = "tidyllm_azure_openai_req_" )send_azure_openai_batch( .llms, .endpoint_url = Sys.getenv("AZURE_ENDPOINT_URL"), .deployment = "gpt-4o-mini", .api_version = "2024-10-01-preview", .max_completion_tokens = NULL, .reasoning_effort = NULL, .frequency_penalty = NULL, .logit_bias = NULL, .presence_penalty = NULL, .seed = NULL, .stop = NULL, .temperature = NULL, .top_p = NULL, .logprobs = NULL, .top_logprobs = NULL, .dry_run = FALSE, .overwrite = FALSE, .max_tries = 3, .timeout = 60, .verbose = FALSE, .json_schema = NULL, .id_prefix = "tidyllm_azure_openai_req_" )
.llms |
A list of LLMMessage objects containing conversation histories. |
.endpoint_url |
Base URL for the API (default: Sys.getenv("AZURE_ENDPOINT_URL")). |
.deployment |
The identifier of the model that is deployed (default: "gpt-4o-mini"). |
.api_version |
Which version of the API is deployed (default: "2024-10-01-preview") |
.max_completion_tokens |
Integer specifying the maximum tokens per response (default: NULL). |
.reasoning_effort |
How long should reasoning models reason (can either be "low","medium" or "high") |
.frequency_penalty |
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency. |
.logit_bias |
A named list modifying the likelihood of specified tokens appearing in the completion. |
.presence_penalty |
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far. |
.seed |
If specified, the system will make a best effort to sample deterministically. |
.stop |
Up to 4 sequences where the API will stop generating further tokens. |
.temperature |
What sampling temperature to use, between 0 and 2. Higher values make the output more random. |
.top_p |
An alternative to sampling with temperature, called nucleus sampling. |
.logprobs |
If TRUE, get the log probabilities of each output token (default: NULL). |
.top_logprobs |
If specified, get the top N log probabilities of each output token (0-5, default: NULL). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it (default: FALSE). |
.overwrite |
Logical; if TRUE, allows overwriting an existing batch ID (default: FALSE). |
.max_tries |
Maximum number of retries to perform the request (default: 3). |
.timeout |
Integer specifying the request timeout in seconds (default: 60). |
.verbose |
Logical; if TRUE, additional info about the requests is printed (default: FALSE). |
.json_schema |
A JSON schema object provided by tidyllm schema or ellmer schemata (default: NULL). |
.id_prefix |
Character string to specify a prefix for generating custom IDs when names in |
An updated and named list of .llms with identifiers that align with batch responses, including a batch_id attribute.
The send_batch() function allows you to send a list of LLMMessage objects
to an API.
It routes the input to the appropriate provider-specific batch API function.
send_batch( .llms, .provider = getOption("tidyllm_sbatch_default"), .dry_run = NULL, .temperature = NULL, .timeout = NULL, .top_p = NULL, .max_tries = NULL, .model = NULL, .verbose = NULL, .json_schema = NULL, .seed = NULL, .stop = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .id_prefix = NULL )send_batch( .llms, .provider = getOption("tidyllm_sbatch_default"), .dry_run = NULL, .temperature = NULL, .timeout = NULL, .top_p = NULL, .max_tries = NULL, .model = NULL, .verbose = NULL, .json_schema = NULL, .seed = NULL, .stop = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .id_prefix = NULL )
.llms |
A list of |
.provider |
A function or function call specifying the language model provider and any additional parameters.
This should be a call to a provider function like |
.dry_run |
Logical; if |
.temperature |
Numeric; controls the randomness of the model's output (0 = deterministic). |
.timeout |
Numeric; the maximum time (in seconds) to wait for a response. |
.top_p |
Numeric; nucleus sampling parameter, which limits the sampling to the top cumulative probability |
.max_tries |
Integer; the maximum number of retries for failed requests. |
.model |
Character; the model identifier to use (e.g., |
.verbose |
Logical; if |
.json_schema |
List; A JSON schema object as R list to enforce the output structure |
.seed |
Integer; sets a random seed for reproducibility. |
.stop |
Character vector; specifies sequences where the model should stop generating further tokens. |
.frequency_penalty |
Numeric; adjusts the likelihood of repeating tokens (positive values decrease repetition). |
.presence_penalty |
Numeric; adjusts the likelihood of introducing new tokens (positive values encourage novelty). |
.id_prefix |
Character string to specify a prefix for generating custom IDs when names in |
An updated and named list of .llms with identifiers that align with batch responses, including a batch_id attribute.
This function creates and submits a batch of messages to the Claude API for asynchronous processing.
send_claude_batch( .llms, .model = "claude-sonnet-4-6", .max_tokens = 1024, .temperature = NULL, .top_k = NULL, .top_p = NULL, .stop_sequences = NULL, .json_schema = NULL, .thinking = FALSE, .thinking_budget = 1024, .api_url = "https://api.anthropic.com/", .verbose = FALSE, .dry_run = FALSE, .overwrite = FALSE, .max_tries = 3, .timeout = 60, .id_prefix = "tidyllm_claude_req_" )send_claude_batch( .llms, .model = "claude-sonnet-4-6", .max_tokens = 1024, .temperature = NULL, .top_k = NULL, .top_p = NULL, .stop_sequences = NULL, .json_schema = NULL, .thinking = FALSE, .thinking_budget = 1024, .api_url = "https://api.anthropic.com/", .verbose = FALSE, .dry_run = FALSE, .overwrite = FALSE, .max_tries = 3, .timeout = 60, .id_prefix = "tidyllm_claude_req_" )
.llms |
A list of LLMMessage objects containing conversation histories. |
.model |
Character string specifying the Claude model version (default: "claude-sonnet-4-6"). |
.max_tokens |
Integer specifying the maximum tokens per response (default: 1024). |
.temperature |
Numeric between 0 and 1 controlling response randomness. |
.top_k |
Integer for diversity by limiting the top K tokens. |
.top_p |
Numeric between 0 and 1 for nucleus sampling. |
.stop_sequences |
Character vector of sequences that halt response generation. |
.json_schema |
A schema to enforce an output structure |
.thinking |
Logical; if TRUE, enables Claude's thinking mode for complex reasoning tasks (default: FALSE). |
.thinking_budget |
Integer specifying the maximum tokens Claude can spend on thinking (default: 1024). Must be at least 1024. Defaults to "tidyllm_claude_req_". |
.api_url |
Base URL for the Claude API (default: "https://api.anthropic.com/"). |
.verbose |
Logical; if TRUE, prints a message with the batch ID (default: FALSE). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it (default: FALSE). |
.overwrite |
Logical; if TRUE, allows overwriting an existing batch ID associated with the request (default: FALSE). |
.max_tries |
Maximum number of retries to perform the request. |
.timeout |
Integer specifying the request timeout in seconds (default: 60). |
.id_prefix |
Character string to specify a prefix for generating custom IDs when names in |
An updated and named list of .llms with identifiers that align with batch responses, including a batch_id attribute.
Returns a named list (same as input) with batch_id and json attributes.
send_gemini_batch( .llms, .model = "gemini-2.5-flash", .temperature = NULL, .max_output_tokens = NULL, .top_p = NULL, .top_k = NULL, .presence_penalty = NULL, .frequency_penalty = NULL, .stop_sequences = NULL, .safety_settings = NULL, .json_schema = NULL, .grounding_threshold = NULL, .timeout = 120, .dry_run = FALSE, .max_tries = 3, .display = "tidyllm_batch", .id_prefix = "tidyllm_gemini_req_" )send_gemini_batch( .llms, .model = "gemini-2.5-flash", .temperature = NULL, .max_output_tokens = NULL, .top_p = NULL, .top_k = NULL, .presence_penalty = NULL, .frequency_penalty = NULL, .stop_sequences = NULL, .safety_settings = NULL, .json_schema = NULL, .grounding_threshold = NULL, .timeout = 120, .dry_run = FALSE, .max_tries = 3, .display = "tidyllm_batch", .id_prefix = "tidyllm_gemini_req_" )
.llms |
List of LLMMessage objects (named or unnamed). |
.model |
The model identifier (default: "gemini-1.5-flash"). |
.temperature |
Controls randomness (default: NULL, range: 0-2). |
.max_output_tokens |
Maximum tokens in the response (default: NULL). |
.top_p |
Nucleus sampling (default: NULL, range: 0-1). |
.top_k |
Diversity in token selection (default: NULL). |
.presence_penalty |
Penalizes new tokens (default: NULL, -2 to 2). |
.frequency_penalty |
Penalizes frequent tokens (default: NULL, -2 to 2). |
.stop_sequences |
Character vector or NULL of up to 5. |
.safety_settings |
Optional list of safety settings (default: NULL). |
.json_schema |
Optional schema to enforce output structure. |
.grounding_threshold |
Optional grounding threshold (0-1) to enable Google Search. |
.timeout |
Timeout in seconds (default: 120). |
.dry_run |
If TRUE, returns the constructed request (default: FALSE). |
.max_tries |
Maximum retry attempts (default: 3). |
.display |
Display name for this batch (default: "tidyllm_batch"). |
.id_prefix |
Prefix for message IDs (default: "tidyllm_gemini_req_"). |
Named list of LLMMessage objects with attributes batch_id and json
This function creates and submits a batch of messages to the Groq API for asynchronous processing.
send_groq_batch( .llms, .model = "openai/gpt-oss-120b", .max_tokens = 1024, .temperature = NULL, .top_p = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .stop = NULL, .seed = NULL, .api_url = "https://api.groq.com/", .json_schema = NULL, .completion_window = "24h", .verbose = FALSE, .dry_run = FALSE, .overwrite = FALSE, .max_tries = 3, .timeout = 60, .id_prefix = "tidyllm_groq_req_" )send_groq_batch( .llms, .model = "openai/gpt-oss-120b", .max_tokens = 1024, .temperature = NULL, .top_p = NULL, .frequency_penalty = NULL, .presence_penalty = NULL, .stop = NULL, .seed = NULL, .api_url = "https://api.groq.com/", .json_schema = NULL, .completion_window = "24h", .verbose = FALSE, .dry_run = FALSE, .overwrite = FALSE, .max_tries = 3, .timeout = 60, .id_prefix = "tidyllm_groq_req_" )
.llms |
A list of LLMMessage objects containing conversation histories. |
.model |
Character string specifying the model to use (default: "deepseek-r1-distill-llama-70b"). |
.max_tokens |
Integer specifying the maximum tokens per response (default: 1024). |
.temperature |
Numeric between 0 and 2 controlling response randomness. |
.top_p |
Numeric between 0 and 1 for nucleus sampling. |
.frequency_penalty |
Number between -2.0 and 2.0 to penalize repetition. |
.presence_penalty |
Number between -2.0 and 2.0 to encourage new topics. |
.stop |
One or more sequences where the API will stop generating further tokens. |
.seed |
An integer for deterministic sampling. |
.api_url |
Base URL for the Groq API (default: "https://api.groq.com/"). |
.json_schema |
A list or tidyllm schema created with |
.completion_window |
Character string for the batch completion window (default: "24h"). |
.verbose |
Logical; if TRUE, prints a message with the batch ID (default: FALSE). |
.dry_run |
Logical; if TRUE, returns the prepared request objects without executing (default: FALSE). |
.overwrite |
Logical; if TRUE, allows overwriting an existing batch ID (default: FALSE). |
.max_tries |
Maximum number of retries to perform the request. |
.timeout |
Integer specifying the request timeout in seconds (default: 60). |
.id_prefix |
Character string to specify a prefix for generating custom IDs when names in |
An updated and named list of .llms with identifiers that align with batch responses, including a batch_id attribute.
This function creates and submits a batch of messages to the Mistral API for asynchronous processing.
send_mistral_batch( .llms, .model = "mistral-small-latest", .endpoint = "/v1/chat/completions", .metadata = NULL, .temperature = 0.7, .top_p = 1, .max_tokens = 1024, .min_tokens = NULL, .frequency_penalty = NULL, .logit_bias = NULL, .presence_penalty = NULL, .seed = NULL, .stop = NULL, .safe_prompt = FALSE, .json_schema = NULL, .dry_run = FALSE, .overwrite = FALSE, .max_tries = 3, .timeout = 60, .id_prefix = "tidyllm_mistral_req_" )send_mistral_batch( .llms, .model = "mistral-small-latest", .endpoint = "/v1/chat/completions", .metadata = NULL, .temperature = 0.7, .top_p = 1, .max_tokens = 1024, .min_tokens = NULL, .frequency_penalty = NULL, .logit_bias = NULL, .presence_penalty = NULL, .seed = NULL, .stop = NULL, .safe_prompt = FALSE, .json_schema = NULL, .dry_run = FALSE, .overwrite = FALSE, .max_tries = 3, .timeout = 60, .id_prefix = "tidyllm_mistral_req_" )
.llms |
A list of LLMMessage objects containing conversation histories. |
.model |
The Mistral model version (default: "mistral-small-latest"). |
.endpoint |
The API endpoint (default: "/v1/chat/completions"). |
.metadata |
Optional metadata for the batch. |
.temperature |
Sampling temperature to use, between |
.top_p |
Nucleus sampling parameter, between |
.max_tokens |
The maximum number of tokens to generate in the completion (default: |
.min_tokens |
The minimum number of tokens to generate (optional). |
.frequency_penalty |
Numeric value (or NULL) for frequency penalty. |
.logit_bias |
A named list modifying the likelihood of specific tokens (or NULL). |
.presence_penalty |
Numeric value (or NULL) for presence penalty. |
.seed |
Random seed for deterministic outputs (optional). |
.stop |
Sequence(s) at which to stop generation (optional). |
.safe_prompt |
Logical; if TRUE, injects a safety prompt (default: FALSE). |
.json_schema |
A JSON schema object for structured output (optional). |
.dry_run |
Logical; if TRUE, returns the prepared request without executing it (default: FALSE). |
.overwrite |
Logical; if TRUE, allows overwriting existing custom IDs (default: FALSE). |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.timeout |
Request timeout in seconds (default: 60). |
.id_prefix |
Prefix for generating custom IDs (default: "tidyllm_mistral_req_"). |
The prepared LLMMessage list with a batch_id attribute.
This function creates and submits a batch of messages to the Ollama API
Contrary to other batch functions, this functions waits for the batch to finish and receives requests.
The advantage compared to sending single messages via chat() is that Ollama handles large parallel
requests quicker than many individual chat requests.
send_ollama_batch( .llms, .model = "qwen3.5:4b", .stream = FALSE, .seed = NULL, .json_schema = NULL, .temperature = NULL, .num_ctx = 2048, .num_predict = NULL, .top_k = NULL, .top_p = NULL, .min_p = NULL, .mirostat = NULL, .mirostat_eta = NULL, .mirostat_tau = NULL, .repeat_last_n = NULL, .repeat_penalty = NULL, .tfs_z = NULL, .stop = NULL, .ollama_server = "http://localhost:11434", .timeout = 120, .keep_alive = NULL, .dry_run = FALSE )send_ollama_batch( .llms, .model = "qwen3.5:4b", .stream = FALSE, .seed = NULL, .json_schema = NULL, .temperature = NULL, .num_ctx = 2048, .num_predict = NULL, .top_k = NULL, .top_p = NULL, .min_p = NULL, .mirostat = NULL, .mirostat_eta = NULL, .mirostat_tau = NULL, .repeat_last_n = NULL, .repeat_penalty = NULL, .tfs_z = NULL, .stop = NULL, .ollama_server = "http://localhost:11434", .timeout = 120, .keep_alive = NULL, .dry_run = FALSE )
.llms |
A list of LLMMessage objects containing conversation histories. |
.model |
Character string specifying the Ollama model to use (default: "qwen3-vl") |
.stream |
Logical; whether to stream the response (default: FALSE) |
.seed |
Integer; seed for reproducible generation (default: NULL) |
.json_schema |
A JSON schema object as R list to enforce the output structure (default: NULL) |
.temperature |
Float between 0-2; controls randomness in responses (default: NULL) |
.num_ctx |
Integer; sets the context window size (default: 2048) |
.num_predict |
Integer; maximum number of tokens to predict (default: NULL) |
.top_k |
Integer; controls diversity by limiting top tokens considered (default: NULL) |
.top_p |
Float between 0-1; nucleus sampling threshold (default: NULL) |
.min_p |
Float between 0-1; minimum probability threshold (default: NULL) |
.mirostat |
Integer (0,1,2); enables Mirostat sampling algorithm (default: NULL) |
.mirostat_eta |
Float; Mirostat learning rate (default: NULL) |
.mirostat_tau |
Float; Mirostat target entropy (default: NULL) |
.repeat_last_n |
Integer; tokens to look back for repetition (default: NULL) |
.repeat_penalty |
Float; penalty for repeated tokens (default: NULL) |
.tfs_z |
Float; tail free sampling parameter (default: NULL) |
.stop |
Character; custom stop sequence(s) (default: NULL) |
.ollama_server |
String; Ollama API endpoint (default: "http://localhost:11434") |
.timeout |
Integer; API request timeout in seconds (default: 120) |
.keep_alive |
Character; How long should the ollama model be kept in memory after request (default: NULL - 5 Minutes) |
.dry_run |
Logical; if TRUE, returns request object without execution (default: FALSE) |
The function provides extensive control over the generation process through various parameters:
Temperature (0-2): Higher values increase creativity, lower values make responses more focused
Top-k/Top-p: Control diversity of generated text
Mirostat: Advanced sampling algorithm for maintaining consistent complexity
Repeat penalties: Prevent repetitive text
Context window: Control how much previous conversation is considered
A list of updated LLMMessage objects, each with the assistant's response added if successful.
This function creates and submits a batch of messages to the OpenAI Batch API for asynchronous processing.
send_openai_batch( .llms, .model = "gpt-5.4", .max_completion_tokens = NULL, .reasoning_effort = NULL, .frequency_penalty = NULL, .logit_bias = NULL, .presence_penalty = NULL, .seed = NULL, .stop = NULL, .temperature = NULL, .top_p = NULL, .logprobs = NULL, .top_logprobs = NULL, .dry_run = FALSE, .overwrite = FALSE, .json_schema = NULL, .max_tries = 3, .timeout = 60, .verbose = FALSE, .id_prefix = "tidyllm_openai_req_" )send_openai_batch( .llms, .model = "gpt-5.4", .max_completion_tokens = NULL, .reasoning_effort = NULL, .frequency_penalty = NULL, .logit_bias = NULL, .presence_penalty = NULL, .seed = NULL, .stop = NULL, .temperature = NULL, .top_p = NULL, .logprobs = NULL, .top_logprobs = NULL, .dry_run = FALSE, .overwrite = FALSE, .json_schema = NULL, .max_tries = 3, .timeout = 60, .verbose = FALSE, .id_prefix = "tidyllm_openai_req_" )
.llms |
A list of LLMMessage objects containing conversation histories. |
.model |
Character string specifying the OpenAI model version (default: "gpt-5.1-chat-latest"). |
.max_completion_tokens |
Integer specifying the maximum tokens per response (default: NULL). |
.reasoning_effort |
How long should reasoning models reason (can either be "low","medium" or "high") |
.frequency_penalty |
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far. |
.logit_bias |
A named list modifying the likelihood of specified tokens appearing in the completion. |
.presence_penalty |
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far. |
.seed |
If specified, the system will make a best effort to sample deterministically. |
.stop |
Up to 4 sequences where the API will stop generating further tokens. |
.temperature |
What sampling temperature to use, between 0 and 2. Higher values make the output more random. |
.top_p |
An alternative to sampling with temperature, called nucleus sampling. |
.logprobs |
If TRUE, get the log probabilities of each output token (default: NULL). |
.top_logprobs |
If specified, get the top N log probabilities of each output token (0-5, default: NULL). |
.dry_run |
Logical; if TRUE, returns the prepared request object without executing it (default: FALSE). |
.overwrite |
Logical; if TRUE, allows overwriting an existing batch ID associated with the request (default: FALSE). |
.json_schema |
A JSON schema object provided by tidyllm_schema or ellmer schemata (default: NULL). |
.max_tries |
Maximum number of retries to perform the request (default: 3). |
.timeout |
Integer specifying the request timeout in seconds (default: 60). |
.verbose |
Logical; if TRUE, additional info about the requests is printed (default: FALSE). |
.id_prefix |
Character string to specify a prefix for generating custom IDs when names in |
An updated and named list of .llms with identifiers that align with batch responses, including a batch_id attribute.
This function creates a JSON schema for structured outputs, supporting both character-based shorthand and S7 tidyllm_field objects.
It also integrates with ellmer types like ellmer::type_string() if ellmer is in your namespace
tidyllm_schema(name = "tidyllm_schema", ...)tidyllm_schema(name = "tidyllm_schema", ...)
name |
A character string specifying the schema name (default: "tidyllm_schema"). |
... |
Named arguments where each name represents a field, and each value is either a character string, a Supported character shorthand types:
|
A list representing the JSON schema, suitable for use with .json_schema in LLM API calls.
## Not run: # Example using different field types address_schema <- tidyllm_schema( name = "AddressSchema", Street = field_chr("A common street name"), house_number = field_dbl(), City = field_chr("Name of a city"), State = field_fct("State abbreviation", .levels = c("CA", "TX", "Other")), Country = "string", PostalCode = "string" ) llm_message("Imagine an address") |> chat(openai, .json_schema = address_schema) # Example with vector field tidyllm_schema( plz = field_dbl(.vector = TRUE) ) ## End(Not run)## Not run: # Example using different field types address_schema <- tidyllm_schema( name = "AddressSchema", Street = field_chr("A common street name"), house_number = field_dbl(), City = field_chr("Name of a city"), State = field_fct("State abbreviation", .levels = c("CA", "TX", "Other")), Country = "string", PostalCode = "string" ) llm_message("Imagine an address") |> chat(openai, .json_schema = address_schema) # Example with vector field tidyllm_schema( plz = field_dbl(.vector = TRUE) ) ## End(Not run)
Creates a tool definition for use with Language Model API calls that support function calling. This function wraps an existing R function with schema information for LLM interaction.
tidyllm_tool(.f, .description = character(0), ...)tidyllm_tool(.f, .description = character(0), ...)
.f |
The function to wrap as a tool |
.description |
Character string describing what the tool does |
... |
Named arguments providing schema definitions for each function parameter using tidyllm_fields |
Each parameter schema in ... should correspond to a parameter in the wrapped function.
All required function parameters must have corresponding schema definitions.
A TOOL class object that can be used with tidyllm chat() functions
get_weather <- function(location){} weather_tool <- tidyllm_tool( get_weather, "Get the current weather in a given location", location = field_chr("The city and state, e.g., San Francisco, CA") )get_weather <- function(location){} weather_tool <- tidyllm_tool( get_weather, "Get the current weather in a given location", location = field_chr("The city and state, e.g., San Francisco, CA") )
Upload a File to a Provider's File Store
upload_file(.provider, .path, ...)upload_file(.provider, .path, ...)
.provider |
A provider function call (e.g. |
.path |
Path to the local file to upload. |
... |
Additional provider-specific arguments. |
A tidyllm_file object.
Stores a reference to a local video file for use in multimodal messages. The file is not encoded until the message is formatted for a provider.
video_file(.path)video_file(.path)
.path |
The path to the video file on disk. |
A tidyllm_video object.
The voyage() function acts as a provider interface for interacting with the Voyage.ai API
through tidyllm's verbs.
It dynamically routes requests to voyage-specific functions. At the moment this is only
voyage_embed()
voyage(..., .called_from = NULL)voyage(..., .called_from = NULL)
... |
Parameters to be passed to the appropriate Voyage-specific function, such as model configuration, input text, or API-specific options. |
.called_from |
An internal argument specifying which action (e.g.,
|
The result of the requested action, depending on the specific function invoked
This function creates embedding vectors from text or multimodal inputs (text and images) using the Voyage AI API. It supports three types of input:
voyage_embedding( .input, .model = "voyage-4", .output_dimension = NULL, .timeout = 120, .dry_run = FALSE, .max_tries = 3, .verbose = FALSE )voyage_embedding( .input, .model = "voyage-4", .output_dimension = NULL, .timeout = 120, .dry_run = FALSE, .max_tries = 3, .verbose = FALSE )
.input |
Input to embed. Can be:
|
.model |
The embedding model identifier. For text-only: "voyage-3.5-lite" (default). For multimodal inputs: "voyage-multimodal-3.5" is used automatically. |
.output_dimension |
Optional integer to control output vector size (default: NULL, uses model default). |
.timeout |
Timeout for the API request in seconds (default: 120). |
.dry_run |
If TRUE, perform a dry run and return the request object without sending. |
.max_tries |
Maximum retry attempts for requests (default: 3). |
.verbose |
Should information about current rate limits be printed? (default: FALSE). |
Character vector: Embeds each text string separately
LLMMessage object: Extracts and embeds text content from messages
List of mixed content: Processes a combination of text strings and image objects created with img()
For multimodal inputs, the function automatically switches to Voyage's multimodal API
and formats the response with appropriate labels (e.g., "[IMG] image.png") for images.
A tibble with two columns: input and embeddings.
The input column contains the input texts or image labels
The embeddings column is a list column where each row contains an embedding vector
## Not run: # Text embeddings voyage_embedding("How does photosynthesis work?") # Multimodal embeddings list("A banana", img("banana.jpg"), "Yellow fruit") |> voyage_embedding() ## End(Not run)## Not run: # Text embeddings voyage_embedding("How does photosynthesis work?") # Multimodal embeddings list("A banana", img("banana.jpg"), "Yellow fruit") |> voyage_embedding() ## End(Not run)
Rerank Documents Using Voyage AI API
voyage_rerank( .query, .documents, .model = "rerank-2", .top_k = NULL, .api_key = Sys.getenv("VOYAGE_API_KEY"), .timeout = 60, .max_tries = 3 )voyage_rerank( .query, .documents, .model = "rerank-2", .top_k = NULL, .api_key = Sys.getenv("VOYAGE_API_KEY"), .timeout = 60, .max_tries = 3 )
.query |
A single character string representing the search query. |
.documents |
A character vector of documents to rerank. |
.model |
The reranking model identifier (default: "rerank-2"). |
.top_k |
Integer; return only the top-k results (default: NULL, returns all). |
.api_key |
Character; Voyage API key (default: from environment). |
.timeout |
Integer; request timeout in seconds (default: 60). |
.max_tries |
Integer; maximum retries (default: 3). |
A tibble with columns index, document, and relevance_score, sorted by score descending.