Skip to contents

Superseded by gr_read() with reader = "map_reduce". Kept so v1 scripts keep running; it warns once per session and does not reproduce v1's unbounded merge prompt, which produced HTTP 400s once the per-chunk answers outgrew the context window. For v1's actual behaviour, use recipe = "legacy".

Usage

gpt_read_chunked(chunks, question, client = NULL, return_json = FALSE, ...)

Arguments

chunks

Character vector of chunks, or a gr_chunks.

question

The question.

client

A gr_client.

return_json

Return the whole answer object, including its trace, as JSON.

...

Passed to gr_read_spec().

Value

A single string when return_json is FALSE; otherwise a json-classed string holding the answer, its notes and the full trace.

Examples

cl <- gr_mock_client(function(m, p) "45.2 million dollars")
chunks <- suppressWarnings(parse_text(readgpt_example(), chunk_token_limit = 200))
#> Extracting 'annual_report.md' with the 'md' extractor.
#> Ingested 17 block(s), ~573 tokens (11 chars removed by cleaning).
#> Segmenting with 'paragraph' (cap 200 tokens, overlap 0).

# v1 style, still works, warns once.
suppressWarnings(gpt_read_chunked(chunks, "What was revenue?", client = cl))
#> Ingested 17 block(s), ~573 tokens (0 chars removed by cleaning).
#> Reading with 'map_reduce' (all|N+logN|tree) over 4 chunk(s).
#> [1] "45.2 million dollars"

# The modern equivalent, which also reports what it did.
ch <- gr_segment(readgpt_example(), list(method = "paragraph", max_tokens = 200))
#> Using cached ingestion for this document + settings.
#> Segmenting with 'paragraph' (cap 200 tokens, overlap 0).
gr_read(ch, "What was revenue?", gr_mock_client(function(m, p) "45.2 million dollars"),
        "map_reduce")$notes$chunks
#> Reading with 'map_reduce' (all|N+logN|tree) over 4 chunk(s).
#> [1] 4