| Title: | Chat Completion and Text Annotation with Local and OpenAI Models |
|---|---|
| Description: | Enables chat completion and text annotation with local and 'OpenAI' <https://openai.com/> language models, supporting batch processing, multiple annotators, and consistent output formats. |
| Authors: | Jason Timm [aut, cre] |
| Maintainer: | Jason Timm <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-05-20 06:59:13 UTC |
| Source: | https://github.com/cran/hollr |
This function generates text using the OpenAI API or a local model.
hollr( id, user_message = "", annotators = 1, model, temperature = 1, top_p = 1, max_tokens = NULL, max_length = 1024, max_new_tokens = NULL, system_message = "", force_json = TRUE, flatten_json = TRUE, max_attempts = 10, openai_api_key = Sys.getenv("OPENAI_API_KEY"), openai_organization = NULL, cores = 1, batch_size = 1, extract_json = TRUE, verbose = TRUE )hollr( id, user_message = "", annotators = 1, model, temperature = 1, top_p = 1, max_tokens = NULL, max_length = 1024, max_new_tokens = NULL, system_message = "", force_json = TRUE, flatten_json = TRUE, max_attempts = 10, openai_api_key = Sys.getenv("OPENAI_API_KEY"), openai_organization = NULL, cores = 1, batch_size = 1, extract_json = TRUE, verbose = TRUE )
id |
A unique identifier for the request. |
user_message |
The message provided by the user. |
annotators |
The number of annotators (default is 1). |
model |
The name of the model to use. |
temperature |
The temperature for the model's output (default is 1). |
top_p |
The top-p sampling value (default is 1). |
max_tokens |
The maximum number of tokens to generate (default is NULL). |
max_length |
The maximum length of the input prompt (default is 1024, for local models only). |
max_new_tokens |
The maximum number of new tokens to generate (default is NULL, for local models only). |
system_message |
The message provided by the system (default is ”). |
force_json |
A logical indicating whether the output should be JSON (default is TRUE). |
flatten_json |
A logical indicating whether the output should be converted to DF (default is TRUE). |
max_attempts |
The maximum number of attempts to make for generating valid output (default is 10). |
openai_api_key |
The API key for the OpenAI API (default is retrieved from environment variables). |
openai_organization |
The organization ID for the OpenAI API (default is NULL). |
cores |
The number of cores to use for parallel processing (default is 1). |
batch_size |
The number of batch_size to process (default is 1, only for local models). |
extract_json |
A logical indicating whether to extract and clean JSON strings from the response (default is TRUE). |
verbose |
A logical indicating whether to show progress and other messages (default is TRUE). |
A data.table containing the generated text and metadata.
# Example using the OpenAI API if (nzchar(Sys.getenv("OPENAI_API_KEY"))) { result <- hollr(id = "example_id", user_message = "What is the capital of France?", model = "gpt-3.5-turbo", openai_api_key = Sys.getenv("OPENAI_API_KEY")) print(result) } else { message("OpenAI API key is not available. Example not run.") }# Example using the OpenAI API if (nzchar(Sys.getenv("OPENAI_API_KEY"))) { result <- hollr(id = "example_id", user_message = "What is the capital of France?", model = "gpt-3.5-turbo", openai_api_key = Sys.getenv("OPENAI_API_KEY")) print(result) } else { message("OpenAI API key is not available. Example not run.") }