Creates an httr2 request object for obtaining a response from a Hugging Face Inference endpoint for multiple text inputs in a single batch. The request body depends on the endpoint's inference engine and the task.
Arguments
- inputs
Vector or list of character strings to process in a batch
- parameters
Parameters to send with inputs. These override the defaults.
- endpoint_url
The URL of the Hugging Face Inference API endpoint
- key_name
Name of the environment variable containing the API key
- max_retries
Maximum number of attempts for requests that get 429 or 5xx
- timeout
Request timeout in seconds
- validate
Whether to validate the endpoint before creating the request
- engine
"toolkit"(default) or"tei"- task
"embed"(default) or"classify"- max_length
Maximum tokens per text for toolkit classification
Details
TEI classification sends each text as a one-element list (
[[text], [text]]), because TEI reads a flat list of 2 texts as one sentence pair. It also asks for raw scores, and EndpointR applies the softmax (seetidy_tei_classification_response()).TEI embeddings send
truncate = trueat the top level of the body.On TEI,
parametersare added to the top level of the body, because TEI ignores aparametersfield.Toolkit classification sends
return_all_scores,truncation,max_lengthandbatch_sizeinparameters. Withoutbatch_size, the toolkit runs one text at a time on the GPU.
Inputs are always sent as a JSON array, even for a single text.
Examples
if (FALSE) { # \dontrun{
batch_req <- hf_build_request_batch(
inputs = c("First text to embed", "Second text to embed"),
endpoint_url = "https://my-endpoint.huggingface.cloud/embedding_api",
key_name = "HF_API_KEY",
engine = "tei",
task = "embed"
)
} # }