Skip to contents

Retrieve batch results

Usage

batch_result(batch_id, simplify = TRUE)

Arguments

batch_id

(chr) the batch id to retrieve

simplify

(lgl, default TRUE) whether to simplify the output, i.e. return only the response body as for single standard completions (the default), or the full response.

Value

(list) if simplify is TRUE, a list of the batch results; otherwise, a list of the full responses.

Details

For more information, see the OpenAI API documentation.

See also

Examples

if (FALSE) {
  batch_file_info <- file_upload("abc123.jsonl")
  batch_job_info <- batch_file_info[["id"]] |>
    batch_create()
  batch_status <- batch_job_info[["id"]] |>
    batch_status()

  # once the batch is completed
  if (batch_status[["status"]] == "completed") {
    results <- batch_status[["id"]] |>
      batch_result()
    res <- results |>
      purrr::map_chr(get_content)
    res
  }

  full_results <- batch_status[["id"]] |>
    batch_result(simplify = FALSE)
  str(full_results, 2)
  full_res <- full_results |>
    purrr::map_chr(\(x) get_content(x[["response"]][["body"]]))
  full_res

  identical(res, full_res)
}