llm-large-files 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1402 -467
- package/README.md +188 -60
- package/dist/analyze.d.ts +5 -0
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +96 -47
- package/dist/analyze.js.map +1 -1
- package/dist/anthropic/adapter.d.ts +14 -3
- package/dist/anthropic/adapter.d.ts.map +1 -1
- package/dist/anthropic/adapter.js +190 -39
- package/dist/anthropic/adapter.js.map +1 -1
- package/dist/ask.d.ts +60 -4
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +1068 -206
- package/dist/ask.js.map +1 -1
- package/dist/encoding.d.ts +17 -0
- package/dist/encoding.d.ts.map +1 -0
- package/dist/encoding.js +852 -0
- package/dist/encoding.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +333 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +159 -0
- package/dist/events.js.map +1 -0
- package/dist/evidence.d.ts +2 -0
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +3 -2
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +35 -3
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +626 -58
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts +17 -8
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +108 -61
- package/dist/gemini/adapter.js.map +1 -1
- package/dist/gemini/chat.d.ts +23 -3
- package/dist/gemini/chat.d.ts.map +1 -1
- package/dist/gemini/chat.js +6 -2
- package/dist/gemini/chat.js.map +1 -1
- package/dist/gemini/errors.d.ts +9 -4
- package/dist/gemini/errors.d.ts.map +1 -1
- package/dist/gemini/errors.js +32 -0
- package/dist/gemini/errors.js.map +1 -1
- package/dist/gemini/generate.d.ts +10 -2
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +13 -7
- package/dist/gemini/generate.js.map +1 -1
- package/dist/gemini/index.d.ts +3 -3
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/gemini/index.js +2 -2
- package/dist/gemini/index.js.map +1 -1
- package/dist/gemini/sse.d.ts +1 -1
- package/dist/gemini/sse.d.ts.map +1 -1
- package/dist/gemini/sse.js +1 -1
- package/dist/gemini/sse.js.map +1 -1
- package/dist/http.d.ts +116 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +347 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +11 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts +67 -5
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +405 -85
- package/dist/library.js.map +1 -1
- package/dist/map-reduce.d.ts +28 -1
- package/dist/map-reduce.d.ts.map +1 -1
- package/dist/map-reduce.js +240 -52
- package/dist/map-reduce.js.map +1 -1
- package/dist/model.d.ts +84 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +182 -1
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts +20 -4
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +122 -20
- package/dist/node/handlers.js.map +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/sse.d.ts +59 -0
- package/dist/node/sse.d.ts.map +1 -0
- package/dist/node/sse.js +174 -0
- package/dist/node/sse.js.map +1 -0
- package/dist/openai/adapter.d.ts +29 -5
- package/dist/openai/adapter.d.ts.map +1 -1
- package/dist/openai/adapter.js +311 -37
- package/dist/openai/adapter.js.map +1 -1
- package/dist/output-limit.d.ts +14 -2
- package/dist/output-limit.d.ts.map +1 -1
- package/dist/output-limit.js +39 -10
- package/dist/output-limit.js.map +1 -1
- package/dist/pause.d.ts +24 -0
- package/dist/pause.d.ts.map +1 -0
- package/dist/pause.js +38 -0
- package/dist/pause.js.map +1 -0
- package/dist/pdf-pages.d.ts +32 -2
- package/dist/pdf-pages.d.ts.map +1 -1
- package/dist/pdf-pages.js +275 -14
- package/dist/pdf-pages.js.map +1 -1
- package/dist/pdf-pictures.d.ts +30 -3
- package/dist/pdf-pictures.d.ts.map +1 -1
- package/dist/pdf-pictures.js +50 -8
- package/dist/pdf-pictures.js.map +1 -1
- package/dist/pdf-work.d.ts +40 -0
- package/dist/pdf-work.d.ts.map +1 -0
- package/dist/pdf-work.js +734 -0
- package/dist/pdf-work.js.map +1 -0
- package/dist/plan.d.ts +22 -4
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +61 -12
- package/dist/plan.js.map +1 -1
- package/dist/retry.d.ts +23 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +33 -3
- package/dist/retry.js.map +1 -1
- package/dist/search.d.ts +8 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +60 -10
- package/dist/search.js.map +1 -1
- package/dist/sse.d.ts +35 -2
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +145 -31
- package/dist/sse.js.map +1 -1
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js +5 -2
- package/dist/stores.js.map +1 -1
- package/dist/text-index.d.ts +6 -0
- package/dist/text-index.d.ts.map +1 -1
- package/dist/text-index.js +25 -8
- package/dist/text-index.js.map +1 -1
- package/dist/text.d.ts +62 -2
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +314 -14
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts +61 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +269 -42
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +102 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/zip-directory.d.ts +43 -0
- package/dist/zip-directory.d.ts.map +1 -0
- package/dist/zip-directory.js +130 -0
- package/dist/zip-directory.js.map +1 -0
- package/docs/README.md +288 -0
- package/docs/api.md +37 -381
- package/docs/configuration.md +28 -558
- package/docs/getting-started.md +407 -223
- package/docs/guides/anthropic.md +590 -0
- package/docs/guides/conversations.md +629 -0
- package/docs/guides/costs-and-limits.md +726 -0
- package/docs/guides/deployment.md +654 -0
- package/docs/guides/errors-and-reliability.md +735 -0
- package/docs/guides/explorer-model.md +399 -0
- package/docs/guides/openai-compatible.md +602 -0
- package/docs/guides/own-adapter-and-loop.md +1169 -0
- package/docs/guides/pdfs.md +971 -0
- package/docs/guides/storage.md +731 -0
- package/docs/guides/testing.md +1199 -0
- package/docs/guides/vertex-and-gemini.md +717 -0
- package/docs/guides/web-app.md +1589 -0
- package/docs/how-it-works.md +1012 -164
- package/docs/measurements.md +881 -0
- package/docs/publishing.md +274 -46
- package/docs/reference/anthropic.md +427 -0
- package/docs/reference/ask.md +892 -0
- package/docs/reference/errors-and-retries.md +758 -0
- package/docs/reference/events.md +993 -0
- package/docs/reference/gemini.md +823 -0
- package/docs/reference/library.md +1467 -0
- package/docs/reference/node.md +528 -0
- package/docs/reference/openai.md +385 -0
- package/docs/reference/tools.md +883 -0
- package/docs/security.md +897 -103
- package/docs/troubleshooting.md +1390 -0
- package/package.json +2 -2
- package/src/analyze.ts +93 -42
- package/src/anthropic/adapter.ts +196 -39
- package/src/ask.ts +1087 -202
- package/src/encoding.ts +850 -0
- package/src/errors.ts +17 -0
- package/src/events.ts +442 -0
- package/src/evidence.ts +5 -2
- package/src/extract.ts +602 -62
- package/src/gemini/adapter.ts +118 -65
- package/src/gemini/chat.ts +28 -4
- package/src/gemini/errors.ts +34 -1
- package/src/gemini/generate.ts +23 -10
- package/src/gemini/index.ts +3 -3
- package/src/gemini/sse.ts +1 -1
- package/src/http.ts +376 -1
- package/src/index.ts +27 -5
- package/src/library.ts +459 -85
- package/src/map-reduce.ts +252 -51
- package/src/model.ts +236 -3
- package/src/node/handlers.ts +137 -22
- package/src/node/index.ts +2 -0
- package/src/node/sse.ts +198 -0
- package/src/openai/adapter.ts +306 -38
- package/src/output-limit.ts +44 -8
- package/src/pause.ts +41 -0
- package/src/pdf-pages.ts +268 -15
- package/src/pdf-pictures.ts +56 -9
- package/src/pdf-work.ts +722 -0
- package/src/plan.ts +68 -12
- package/src/retry.ts +49 -5
- package/src/search.ts +63 -10
- package/src/sse.ts +153 -28
- package/src/stores.ts +5 -2
- package/src/text-index.ts +26 -7
- package/src/text.ts +323 -13
- package/src/tools.ts +261 -42
- package/src/types.ts +107 -4
- package/src/zip-directory.ts +136 -0
package/docs/README.md
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
# llm-large-files documentation
|
|
2
|
+
|
|
3
|
+
`llm-large-files` lets a language model answer questions about files larger than its context window
|
|
4
|
+
or its request size limit: logs, books and other text, CSV, JSON, Word, PowerPoint and PDF files. A
|
|
5
|
+
file that fits goes into the prompt whole; a larger one becomes a short card, and the model
|
|
6
|
+
searches it, reads line ranges, reads all of it in parts or looks at the pages of a PDF, in one
|
|
7
|
+
tool loop that works with Gemini and Vertex AI, OpenAI-compatible endpoints, Claude or a model of
|
|
8
|
+
your own. This page is the map: where to start, which entry point to use, the words the other pages
|
|
9
|
+
use, and every page in one line.
|
|
10
|
+
|
|
11
|
+
## Start here
|
|
12
|
+
|
|
13
|
+
### A chatbot on Gemini or Vertex AI
|
|
14
|
+
|
|
15
|
+
For an application where users upload files into a chat, ask about them and watch the answer
|
|
16
|
+
stream in, with Gemini on Vertex AI or the Gemini API. Read in this order:
|
|
17
|
+
|
|
18
|
+
1. [Getting started](./getting-started.md): install, a quickstart that runs, and the integration
|
|
19
|
+
in short steps.
|
|
20
|
+
2. [Gemini API and Vertex AI](./guides/vertex-and-gemini.md): endpoints and access tokens,
|
|
21
|
+
`askGemini`, thinking, whole-file reads, pages, gateways, Vertex quotas and errors.
|
|
22
|
+
3. [Web app](./guides/web-app.md): uploads, answers and progress streamed to the browser,
|
|
23
|
+
cancelling.
|
|
24
|
+
4. [Conversations](./guides/conversations.md): the history you keep, tool turns included, across
|
|
25
|
+
requests and servers.
|
|
26
|
+
5. [Storage](./guides/storage.md): where documents live, owners, a layout per user and per chat
|
|
27
|
+
session, retention.
|
|
28
|
+
6. [Errors and reliability](./guides/errors-and-reliability.md): what each failure means and what
|
|
29
|
+
to show the user.
|
|
30
|
+
7. [Costs and limits](./guides/costs-and-limits.md): what one question may spend, and its usage per
|
|
31
|
+
user or session.
|
|
32
|
+
8. [An explorer model](./guides/explorer-model.md): a cheaper model that searches the files while
|
|
33
|
+
yours writes the answer.
|
|
34
|
+
9. [Deployment](./guides/deployment.md): several servers, memory, sweeps, proxies, upgrades.
|
|
35
|
+
|
|
36
|
+
### Another model
|
|
37
|
+
|
|
38
|
+
For OpenAI, Azure OpenAI, DeepSeek, a local server, Claude, or a model that has no adapter yet:
|
|
39
|
+
|
|
40
|
+
1. [Getting started](./getting-started.md).
|
|
41
|
+
2. [OpenAI-compatible endpoints](./guides/openai-compatible.md) or [Claude](./guides/anthropic.md):
|
|
42
|
+
the adapter and its settings for your provider.
|
|
43
|
+
3. [Your own adapter and loop](./guides/own-adapter-and-loop.md): when your model has no adapter,
|
|
44
|
+
or you already run a tool loop of your own.
|
|
45
|
+
|
|
46
|
+
Then go on with steps 3 to 9 of the first path. Those guides are not tied to a provider.
|
|
47
|
+
|
|
48
|
+
## Which entry point
|
|
49
|
+
|
|
50
|
+
There are three ways to ask a question. All three use the same `LargeFiles` object from
|
|
51
|
+
`createLargeFiles()`, so your documents, store and owners stay as they are when you move from one
|
|
52
|
+
to another.
|
|
53
|
+
|
|
54
|
+
| Entry point | Pick it when | What you do yourself |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `askGemini`, from `llm-large-files/gemini` | Your model is Gemini, on the Gemini API or Vertex AI. One endpoint (`vertexAi()`, `geminiApi()`, or your gateway's URL and headers) says where the model is and can name an explorer model, and you may pass the history as Gemini `contents`. | Keep the history and show the answer; the loop does the rest. The explorer can only be another Gemini model, called with the same headers. |
|
|
57
|
+
| `askWithFiles` with an adapter, from `llm-large-files` | Any other model (`openAiCompatible()`, `anthropic()`, an adapter of your own), an explorer of another provider than the answering model, or an adapter you wrap for logging, quotas or a gateway. With `gemini()`, it also lets you declare the model's `contextTokens`, `maxRequestBytes` and `id` on the adapter. | The same as with `askGemini`. |
|
|
58
|
+
| Your own loop, with `files.prepare()` and `files.tools()` | You already run a tool loop, such as an agent framework, and want only the documents in it. `prepare()` gives the plan, the text or card of each document and the system instruction; `tools()` gives the tool declarations and runs the calls. | The loop: sending requests, retries, keeping the request inside the window, limits, usage, evidence and history. `withRetry`, `parseSseJson`, `evidenceOf`, `stubResult` and `UsageMeter` help with parts of it. |
|
|
59
|
+
|
|
60
|
+
`askGemini` is `askWithFiles` with a `gemini()` adapter for the endpoint, and a second one for its
|
|
61
|
+
explorer model when the endpoint names one. Both return the same `AskResult`. Here are the three
|
|
62
|
+
ways in; the third stops where your own loop takes over:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { askWithFiles, createLargeFiles, FileDocumentStore } from "llm-large-files";
|
|
66
|
+
import { askGemini, gemini, vertexAi } from "llm-large-files/gemini";
|
|
67
|
+
|
|
68
|
+
// Assumed: getAccessToken() returns an OAuth access token for Vertex AI (see the Vertex guide),
|
|
69
|
+
// and documentId is the `id` that files.ingest() returned for an upload.
|
|
70
|
+
const files = createLargeFiles({ store: new FileDocumentStore("./data/large-files") });
|
|
71
|
+
const endpoint = vertexAi({
|
|
72
|
+
project: process.env.GOOGLE_CLOUD_PROJECT!,
|
|
73
|
+
location: "global",
|
|
74
|
+
model: "gemini-3.8-flash",
|
|
75
|
+
accessToken: getAccessToken,
|
|
76
|
+
});
|
|
77
|
+
const documentIds = [documentId];
|
|
78
|
+
const messages = [{ role: "user" as const, text: "What caused the outage, and when? Cite lines." }];
|
|
79
|
+
|
|
80
|
+
// 1. askGemini: the endpoint says where the model is.
|
|
81
|
+
const first = await askGemini({ files, endpoint, documentIds, messages });
|
|
82
|
+
|
|
83
|
+
// 2. askWithFiles: the same loop, with the model as an adapter you can swap or wrap.
|
|
84
|
+
const model = gemini(endpoint);
|
|
85
|
+
const second = await askWithFiles({ files, model, documentIds, messages });
|
|
86
|
+
console.log(first.text, second.steps, second.usage);
|
|
87
|
+
|
|
88
|
+
// 3. Your own loop: the plan, the cards and the tools, for a loop you already have.
|
|
89
|
+
// The second argument is the size of the rest of your request: system prompt and messages.
|
|
90
|
+
const context = await files.prepare(documentIds, { tokens: 1_000, bytes: 4_000 });
|
|
91
|
+
// By default, the instruction and the cards offer analyze_whole_document for a file that can be
|
|
92
|
+
// read whole. The tool exists only when you pass `generate` (here the Gemini adapter's own).
|
|
93
|
+
// Without it, pass { wholeDocumentAnalysis: false } as prepare's third argument, so that the
|
|
94
|
+
// instruction and the cards do not offer the tool.
|
|
95
|
+
const tools = files.tools(context.plan.searchable, { generate: model.generateText });
|
|
96
|
+
// Put context.instruction in your system prompt and context.blocks (a text for each document) in
|
|
97
|
+
// the user turn, offer tools.declarations to your model, and run each call with tools.execute().
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
[Getting started](./getting-started.md) has a quickstart that runs. The third way is explained in
|
|
101
|
+
[your own adapter and loop](./guides/own-adapter-and-loop.md).
|
|
102
|
+
|
|
103
|
+
## Glossary
|
|
104
|
+
|
|
105
|
+
Each term links to the page that explains it. The defaults and limits are on those pages.
|
|
106
|
+
|
|
107
|
+
- **Adapter**: a `ModelAdapter`, the object through which the loop talks to one model: an `id`,
|
|
108
|
+
its `capabilities` (at least `toolFiles` and `pageTokens`) and `send()`, plus `generateText()`
|
|
109
|
+
when it can do whole-file reads. Built in: `gemini()`, `openAiCompatible()` and `anthropic()`.
|
|
110
|
+
See [`ModelAdapter`](./reference/ask.md#modeladapter) and
|
|
111
|
+
[your own adapter and loop](./guides/own-adapter-and-loop.md).
|
|
112
|
+
- **Budget**: the sizes one request must fit (`Budget`): the model's context window
|
|
113
|
+
(`contextTokens`), the largest request body (`maxRequestBytes`), and the shares inside them:
|
|
114
|
+
document text sent whole, tokens kept free, the part size of a whole-file read, one tool result.
|
|
115
|
+
`askWithFiles` fits the budget to the window and body size each adapter declares, and the
|
|
116
|
+
built-in adapters declare a window only when you give them `contextTokens`. See
|
|
117
|
+
[`Budget`](./reference/library.md#budget) and [costs and limits](./guides/costs-and-limits.md).
|
|
118
|
+
- **Card**: what the model sees of a document that is not inline: its name and `document_id`, its
|
|
119
|
+
format and size, for a text file that was not valid UTF-8 the encoding it was read in or how
|
|
120
|
+
many of its characters were not valid, for a log its levels, time range and most frequent
|
|
121
|
+
problems, the start of its outline, and its first lines, numbered. It tells the model to use the
|
|
122
|
+
tools for the rest. See [how it works](./how-it-works.md).
|
|
123
|
+
- **Document**: a file after `files.ingest()`: its extracted text, which the tools read by line
|
|
124
|
+
number, and its metadata (`DocumentMeta`), kept in the store under an ID the library makes
|
|
125
|
+
(`doc_` and 32 hex characters). It expires after `ttlMs`. The uploaded file itself is kept only
|
|
126
|
+
for the formats in `keepOriginals`. See [storage](./guides/storage.md).
|
|
127
|
+
- **Evidence**: `AskResult.evidence`, one entry for each tool call that showed the model part of a
|
|
128
|
+
document: which document, and which lines or pages, as ranges (`Evidence`). A whole-file read is
|
|
129
|
+
marked `whole: true`. Keep it with the answer for citations or an audit trail. See
|
|
130
|
+
[`AskResult`](./reference/ask.md#askresult).
|
|
131
|
+
- **Events**: what a question or an ingest does as it runs, as typed data in order (`AskEvent`,
|
|
132
|
+
`IngestEvent`): each model request, tool call, piece of text and notice, numbered by `seq`, and
|
|
133
|
+
last `run.finish` or `run.error` (`ingest.finish` or `ingest.error`). Get them with `onEvent`,
|
|
134
|
+
or with `askStream` as an async iterable, and send them to a browser with `writeSseEvents`. New
|
|
135
|
+
in 0.7.0. See [events](./reference/events.md).
|
|
136
|
+
- **Explorer model**: an optional second model (`explorer` in `askWithFiles`, `explorerModel` in
|
|
137
|
+
`vertexAi()` and `geminiApi()`) that makes the tool calls and does the whole-file reads. The
|
|
138
|
+
answering model then gets what the tools returned, not what the explorer wrote, and writes the
|
|
139
|
+
answer in a request of its own. Without one, one model does both. See
|
|
140
|
+
[an explorer model](./guides/explorer-model.md).
|
|
141
|
+
- **Inline**: a document whose whole text goes into the prompt because it fits the budget, between
|
|
142
|
+
two frame lines that carry a mark made from its ID, which the file's own lines cannot copy. By
|
|
143
|
+
default (`documentPlacement: "first"`) it goes at the start of the first user turn, where a
|
|
144
|
+
provider's prompt cache can reuse it on follow-up questions. See [how it works](./how-it-works.md).
|
|
145
|
+
- **Limits**: `AskLimits`, how much work one question may do: chat requests (`toolTurns`), tool
|
|
146
|
+
calls in one turn (`callsPerTurn`), whole-file reads of each document (`wholeDocumentReads`),
|
|
147
|
+
and optional ceilings on input tokens (`inputTokens`) and requests (`requests`). The budget is
|
|
148
|
+
about size; the limits are about work, and so about cost. See
|
|
149
|
+
[`AskLimits`](./reference/ask.md#asklimits) and [costs and limits](./guides/costs-and-limits.md).
|
|
150
|
+
- **Owner**: a string you set at ingest, usually the ID of the user or tenant. It must not be
|
|
151
|
+
empty: `ingest` refuses `""`, a string of spaces and `null`. Every later call for the document
|
|
152
|
+
must pass the same string; with another one, the document is treated as missing and
|
|
153
|
+
`askWithFiles` throws `DocumentsNotFoundError`. A document without an owner can be used by anyone
|
|
154
|
+
who has its ID. The library only compares the strings: chat sessions, and which documents
|
|
155
|
+
belong to one, are your application's to keep. See [storage](./guides/storage.md) and
|
|
156
|
+
[security](./security.md).
|
|
157
|
+
- **Plan**: the split of a question's documents into inline and searchable (`DocumentPlan`, also in
|
|
158
|
+
`AskResult.plan`). The smallest documents go in whole first, while they fit the budget's room for
|
|
159
|
+
document text and the request size; the others get a card and the tools. `files.prepare()` makes
|
|
160
|
+
it for each question. See [`DocumentPlan`](./reference/library.md#documentplan) and
|
|
161
|
+
[how it works](./how-it-works.md).
|
|
162
|
+
- **Pointer**: a short result (`already_shown: true`) given in place of running a tool call again,
|
|
163
|
+
when an earlier result still in the conversation holds in full what the call would return. The
|
|
164
|
+
earlier result may be from this question or from an earlier one passed back as tool turns. It
|
|
165
|
+
saves room in the request. See [conversations](./guides/conversations.md).
|
|
166
|
+
- **Question**: one call of `askGemini` or `askWithFiles`: the user's latest message and every
|
|
167
|
+
model request made to answer it. Limits, usage and whole-file reads count per question. See
|
|
168
|
+
[`askWithFiles`](./reference/ask.md#askwithfilesoptions).
|
|
169
|
+
- **Stand-in**: a short result put in place of an older tool result when the request runs out of
|
|
170
|
+
room (`dropped: true`). It names the document and the lines or pages that were shown, so the
|
|
171
|
+
model can read them again. When a model of the question may only grow its conversation
|
|
172
|
+
(`appendOnly`, as Claude's), no older result is replaced to make room: when the room runs out,
|
|
173
|
+
the question is answered with what it has. A look at pages kept in `toolTurns`, and a pointer
|
|
174
|
+
whose result is gone, are still stand-ins. See
|
|
175
|
+
[conversations](./guides/conversations.md) and [how it works](./how-it-works.md).
|
|
176
|
+
- **Steps**: one short line for each tool call, in order, such as
|
|
177
|
+
`Search app.log (exact) for “timeout” — 12 matching lines`, and lines for what the loop itself
|
|
178
|
+
did, such as `Older tool results were shortened to make room in the request`. They arrive live
|
|
179
|
+
through `onStep`, and all together in `AskResult.steps`. Each is one line of plain text that can
|
|
180
|
+
quote the model's words: show it as plain text, never as markdown or HTML. See
|
|
181
|
+
[`AskResult`](./reference/ask.md#askresult) and [web app](./guides/web-app.md).
|
|
182
|
+
- **Store**: a `DocumentStore`, where the text and metadata of documents live and, when the store
|
|
183
|
+
supports it, their original files and line indexes. Built in: `MemoryDocumentStore` and
|
|
184
|
+
`FileDocumentStore`; write your own for a database or object storage. Servers that share a store
|
|
185
|
+
share the documents. See [storage](./guides/storage.md) and
|
|
186
|
+
[`DocumentStore`](./reference/library.md#documentstore).
|
|
187
|
+
- **Tool turns**: `AskResult.toolTurns`, the tool rounds of a question as plain JSON (`ToolTurn`),
|
|
188
|
+
each call with its result. Store them with the chat and pass them back in `messages`, between
|
|
189
|
+
that question and its answer: a later question then sees what was found and need not search
|
|
190
|
+
again. Pages that were shown are not in them. See [conversations](./guides/conversations.md) and
|
|
191
|
+
[`ToolTurn`](./reference/ask.md#toolturn). Not the same as `limits.toolTurns` and the
|
|
192
|
+
`tool_turns_left` field of each result, which count the chat requests of a question (see
|
|
193
|
+
**Limits**).
|
|
194
|
+
- **Tools**: what the model calls to reach the documents: `search_document`, `read_document`,
|
|
195
|
+
`get_document_overview`, `analyze_whole_document` (a whole-file read) and `view_pages` (the pages
|
|
196
|
+
of a PDF whose original is kept). A tool set reaches only the documents it was made for. See
|
|
197
|
+
[tools](./reference/tools.md).
|
|
198
|
+
- **Usage**: `AskResult.usage` (`UsageTotals`), the requests and tokens of a whole question (input,
|
|
199
|
+
cached input, output, thinking), whole-file part reads included, in total and for each model
|
|
200
|
+
(`byModel`). Multiply by your prices for the cost of a question. See
|
|
201
|
+
[costs and limits](./guides/costs-and-limits.md) and
|
|
202
|
+
[`UsageTotals`](./reference/ask.md#usagetotals).
|
|
203
|
+
- **Whole-file read (map-reduce)**: the `analyze_whole_document` tool. The file is cut into parts
|
|
204
|
+
of up to `mapChunkTokens`, each part is read by a model request of its own, several at a time,
|
|
205
|
+
and their notes are merged into one answer. A file that would need more than `maxMapChunks` parts
|
|
206
|
+
is refused. `askWithFiles` offers it only when the adapter that makes the tool calls has
|
|
207
|
+
`generateText` and `wholeDocumentAnalysis` is not `false`; in your own loop, only when you pass
|
|
208
|
+
`generate` to `files.tools()`. Without `generate`, pass `wholeDocumentAnalysis: false` to
|
|
209
|
+
`files.prepare()`, so that the instruction does not name it and the cards do not offer it. See
|
|
210
|
+
[tools](./reference/tools.md) and [how it works](./how-it-works.md).
|
|
211
|
+
|
|
212
|
+
## Guides
|
|
213
|
+
|
|
214
|
+
One task each, with samples:
|
|
215
|
+
|
|
216
|
+
- [Gemini API and Vertex AI](./guides/vertex-and-gemini.md): the Gemini API and Vertex AI in
|
|
217
|
+
production: endpoints, access tokens, `gemini()` and `askGemini` setup, thinking, whole-file
|
|
218
|
+
reads, pages, gateways, Vertex quotas and errors.
|
|
219
|
+
- [OpenAI-compatible endpoints](./guides/openai-compatible.md): recipes for OpenAI, Azure OpenAI,
|
|
220
|
+
DeepSeek, OpenRouter, vLLM, Ollama, LiteLLM and llama.cpp.
|
|
221
|
+
- [Claude](./guides/anthropic.md): setup, thinking, streaming, conversations that may only grow,
|
|
222
|
+
gateways.
|
|
223
|
+
- [An explorer model](./guides/explorer-model.md): a second, cheaper model that explores the
|
|
224
|
+
documents while another answers: who does what, what changes for your app, cost, any pair of
|
|
225
|
+
providers.
|
|
226
|
+
- [Web app](./guides/web-app.md): uploads (`createDocumentHandlers`, direct `ingest`, the
|
|
227
|
+
browser), answers and progress streamed over server-sent events, cancelling.
|
|
228
|
+
- [Conversations](./guides/conversations.md): the message format, keeping tool turns, history
|
|
229
|
+
across requests and servers, staying inside the window, converters, pointers for repeated calls,
|
|
230
|
+
mixing providers.
|
|
231
|
+
- [Storage](./guides/storage.md): the `DocumentStore` contract and writing your own, the built-in
|
|
232
|
+
stores, owners and a layout per user and per session, retention, original files, the cache.
|
|
233
|
+
- [Deployment](./guides/deployment.md): several servers, memory sizing, sweeps, proxies and
|
|
234
|
+
timeouts for streams, rolling upgrades, Node.js and ESM.
|
|
235
|
+
- [Errors and reliability](./guides/errors-and-reliability.md): every error and its kind and what
|
|
236
|
+
to show a user, retries, waits on a silent model, deadlines, requests too large, empty or broken
|
|
237
|
+
turns, `partialResultOf`.
|
|
238
|
+
- [Costs and limits](./guides/costs-and-limits.md): `AskLimits`, the budget for each model, usage
|
|
239
|
+
totals, cost per user or session, what costs most.
|
|
240
|
+
- [PDFs and other formats](./guides/pdfs.md): formats and their optional dependencies, PDF tables,
|
|
241
|
+
pictures, the page marker, `view_pages`, scanned PDFs, `toolFilePlacement`, your own extractors
|
|
242
|
+
and OCR.
|
|
243
|
+
- [Your own adapter and loop](./guides/own-adapter-and-loop.md): writing or wrapping a
|
|
244
|
+
`ModelAdapter`, your own loop with `prepare()` and `tools()`, `parseSseJson`, `withRetry`.
|
|
245
|
+
- [Testing an integration](./guides/testing.md): tests without a real model: a scripted model, the
|
|
246
|
+
real adapters with a fake `fetch`, errors, expiry and owners, and a few cheap live tests.
|
|
247
|
+
|
|
248
|
+
## Reference by module
|
|
249
|
+
|
|
250
|
+
Every export and option, one page per part of the package. The first column is the name you
|
|
251
|
+
import from.
|
|
252
|
+
|
|
253
|
+
| Import from | Reference | What is there |
|
|
254
|
+
|---|---|---|
|
|
255
|
+
| `llm-large-files` | [The library and its documents](./reference/library.md) | `createLargeFiles`, `LargeFiles` and its options, the budget, stores, extractors, document types, text helpers |
|
|
256
|
+
| | [The tool loop and the adapter contract](./reference/ask.md) | `askWithFiles`, its options, limits and result, conversation types, the `ModelAdapter` contract, usage, evidence |
|
|
257
|
+
| | [Errors, retries and streams](./reference/errors-and-retries.md) | `ModelRequestError` and error kinds, `withRetry`, timeouts, `parseSseJson` |
|
|
258
|
+
| | [Tools](./reference/tools.md) | each tool the model sees: name, arguments, results, limits; `ToolSet` and its types |
|
|
259
|
+
| | [Events](./reference/events.md) | `askStream`, `eventStream`, the events of a question (`AskEvent`) and of an ingest (`IngestEvent`), `EventError` |
|
|
260
|
+
| `llm-large-files/gemini` | [Gemini](./reference/gemini.md) | `askGemini`, `gemini()`, `geminiApi()`, `vertexAi()` and the other Gemini exports |
|
|
261
|
+
| `llm-large-files/openai` | [OpenAI-compatible](./reference/openai.md) | `openAiCompatible()` and the other OpenAI exports |
|
|
262
|
+
| `llm-large-files/anthropic` | [Claude](./reference/anthropic.md) | `anthropic()` and the other Anthropic exports |
|
|
263
|
+
| `llm-large-files/node` | [Node HTTP handlers](./reference/node.md) | `createDocumentHandlers`: routes, requests, responses and statuses; `writeSseEvents` and `sseMessageOf`, events as Server-Sent Events |
|
|
264
|
+
|
|
265
|
+
## Internals and measurements
|
|
266
|
+
|
|
267
|
+
- [How it works](./how-it-works.md): the internals end to end: ingest, text encodings, the plan,
|
|
268
|
+
the frame and the cards, room in the request, token estimates, the tools, whole-file reads, the
|
|
269
|
+
loop.
|
|
270
|
+
- [Security](./security.md): owners and scoping, prompt injection (the frame around a file,
|
|
271
|
+
characters that show nothing, hidden text, older encodings), retention, original files, PDFs,
|
|
272
|
+
uploads, regular expressions, cost, storage errors, what the library logs.
|
|
273
|
+
- [Measurements](./measurements.md): every live result and measurement, with its date.
|
|
274
|
+
- [Troubleshooting](./troubleshooting.md): symptom, cause, fix.
|
|
275
|
+
|
|
276
|
+
Older links: [api.md](./api.md) and [configuration.md](./configuration.md) keep their old
|
|
277
|
+
headings, each pointing to its new home.
|
|
278
|
+
|
|
279
|
+
## Maintainers
|
|
280
|
+
|
|
281
|
+
- [Publishing](./publishing.md): releasing a version to npm.
|
|
282
|
+
- [Contributing](https://github.com/renanbazinin/llm-large-files/blob/main/CONTRIBUTING.md): how to work on the code and its tests.
|
|
283
|
+
|
|
284
|
+
## Changelog
|
|
285
|
+
|
|
286
|
+
[CHANGELOG.md](../CHANGELOG.md) says what changed in each version. From 0.6.0 on, each version
|
|
287
|
+
starts with what you must change when you upgrade, then what you can add, what works differently
|
|
288
|
+
and what was fixed.
|