Maps the old mode strings onto recipes. Unlike v1, each mode runs as an
isolated pipeline, so selecting several modes no longer changes any of their
answers, and mode no longer defaults to running all five.
Usage
answer_question(
file_path,
question,
mode = "Chunked",
use_parallel = FALSE,
refine = FALSE,
return_json = FALSE,
client = NULL,
...
)Arguments
- file_path
Path to the document.
- question
The question.
- mode
One or more of
"Retrieval","Chunked","Semantic","Hierarchical","MultiPass". Defaults to"Chunked"only.- use_parallel
Run per-chunk calls in parallel.
- refine
Request chunk-level citations in the answer. v1's
refineverification pass is not reproduced: it could never run, because it called asearch_text()function that was never defined.- return_json
Return the answers, the comparison summary and the trace as JSON instead of the answer string.
- client
A
gr_client.- ...
Passed to
answer_document().
See also
answer_document(), gr_compare(), gr_recipes()
Other v1 compatibility:
gpt_read_chunked(),
gpt_read_hierarchical(),
gpt_read_multipass(),
gpt_read_retrieval(),
parse_text()
Examples
cl <- gr_mock_client(function(m, p) "45.2 million dollars")
# v1 style, still works, warns once.
suppressWarnings(
answer_question(readgpt_example(), "What was revenue?", mode = "Chunked", client = cl))
#> Extracting 'annual_report.md' with the 'md' extractor.
#> Ingested 17 block(s), ~573 tokens (11 chars removed by cleaning).
#> Segmenting with 'paragraph' (cap 1200 tokens, overlap 0).
#> Reading with 'map_reduce' (all|N+logN|tree) over 1 chunk(s).
#> [1] "45.2 million dollars"
# The modern equivalent.
answer_document(readgpt_example(), "What was revenue?", "thorough",
client = cl, return = "text")
#> Extracting 'annual_report.md' with the 'md' extractor.
#> Ingested 17 block(s), ~573 tokens (11 chars removed by cleaning).
#> Segmenting with 'paragraph' (cap 1200 tokens, overlap 120).
#> Reading with 'map_reduce' (all|N+logN|tree) over 1 chunk(s).
#> [1] "45.2 million dollars"