llm-large-files 0.7.0 → 0.8.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 +319 -1
- package/README.md +10 -8
- package/dist/analyze.d.ts +3 -1
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +109 -14
- package/dist/analyze.js.map +1 -1
- package/dist/anthropic/adapter.d.ts.map +1 -1
- package/dist/anthropic/adapter.js +4 -1
- package/dist/anthropic/adapter.js.map +1 -1
- package/dist/ask.d.ts +3 -3
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +72 -17
- package/dist/ask.js.map +1 -1
- package/dist/decode.d.ts +19 -0
- package/dist/decode.d.ts.map +1 -0
- package/dist/decode.js +97 -0
- package/dist/decode.js.map +1 -0
- package/dist/errors.d.ts +55 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +65 -0
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +6 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +5 -1
- package/dist/events.js.map +1 -1
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +6 -0
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +7 -20
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +49 -751
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +9 -5
- package/dist/gemini/adapter.js.map +1 -1
- package/dist/gemini/endpoints.d.ts +5 -1
- package/dist/gemini/endpoints.d.ts.map +1 -1
- package/dist/gemini/endpoints.js +11 -2
- package/dist/gemini/endpoints.js.map +1 -1
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +20 -3
- package/dist/gemini/generate.js.map +1 -1
- package/dist/groups.d.ts +54 -0
- package/dist/groups.d.ts.map +1 -0
- package/dist/groups.js +136 -0
- package/dist/groups.js.map +1 -0
- package/dist/html.d.ts +11 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +1112 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +48 -12
- package/dist/library.js.map +1 -1
- package/dist/limiter.d.ts +2 -1
- package/dist/limiter.d.ts.map +1 -1
- package/dist/limiter.js +3 -2
- package/dist/limiter.js.map +1 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -1
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +69 -15
- 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/ingest-child.d.ts +38 -0
- package/dist/node/ingest-child.d.ts.map +1 -0
- package/dist/node/ingest-child.js +42 -0
- package/dist/node/ingest-child.js.map +1 -0
- package/dist/node/isolated.d.ts +88 -0
- package/dist/node/isolated.d.ts.map +1 -0
- package/dist/node/isolated.js +381 -0
- package/dist/node/isolated.js.map +1 -0
- package/dist/office.d.ts +105 -0
- package/dist/office.d.ts.map +1 -0
- package/dist/office.js +1092 -0
- package/dist/office.js.map +1 -0
- package/dist/openai/adapter.d.ts.map +1 -1
- package/dist/openai/adapter.js +15 -1
- package/dist/openai/adapter.js.map +1 -1
- package/dist/pdf-pages.d.ts.map +1 -1
- package/dist/pdf-pages.js +2 -6
- package/dist/pdf-pages.js.map +1 -1
- package/dist/peers.d.ts +8 -0
- package/dist/peers.d.ts.map +1 -0
- package/dist/peers.js +32 -0
- package/dist/peers.js.map +1 -0
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +1 -1
- package/dist/plan.js.map +1 -1
- package/dist/ranged.d.ts.map +1 -1
- package/dist/ranged.js +4 -2
- package/dist/ranged.js.map +1 -1
- package/dist/search.d.ts +99 -22
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +744 -140
- package/dist/search.js.map +1 -1
- package/dist/text-index.d.ts +3 -1
- package/dist/text-index.d.ts.map +1 -1
- package/dist/text-index.js +3 -1
- package/dist/text-index.js.map +1 -1
- package/dist/text.d.ts +27 -3
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +225 -23
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +200 -12
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/word-styles.d.ts +102 -0
- package/dist/word-styles.d.ts.map +1 -0
- package/dist/word-styles.js +419 -0
- package/dist/word-styles.js.map +1 -0
- package/dist/xlsx.d.ts +23 -0
- package/dist/xlsx.d.ts.map +1 -0
- package/dist/xlsx.js +511 -0
- package/dist/xlsx.js.map +1 -0
- package/dist/xml-stream.d.ts +55 -0
- package/dist/xml-stream.d.ts.map +1 -0
- package/dist/xml-stream.js +235 -0
- package/dist/xml-stream.js.map +1 -0
- package/docs/README.md +8 -8
- package/docs/getting-started.md +1 -1
- package/docs/guides/costs-and-limits.md +7 -5
- package/docs/guides/deployment.md +95 -29
- package/docs/guides/errors-and-reliability.md +23 -10
- package/docs/guides/pdfs.md +127 -74
- package/docs/guides/storage.md +1 -1
- package/docs/guides/testing.md +5 -1
- package/docs/guides/web-app.md +10 -9
- package/docs/how-it-works.md +73 -50
- package/docs/reference/ask.md +26 -8
- package/docs/reference/errors-and-retries.md +5 -3
- package/docs/reference/events.md +14 -6
- package/docs/reference/gemini.md +6 -2
- package/docs/reference/library.md +205 -74
- package/docs/reference/node.md +200 -22
- package/docs/reference/openai.md +1 -1
- package/docs/reference/tools.md +170 -22
- package/docs/security.md +114 -69
- package/docs/troubleshooting.md +40 -20
- package/package.json +6 -2
- package/src/analyze.ts +117 -13
- package/src/anthropic/adapter.ts +4 -1
- package/src/ask.ts +73 -17
- package/src/decode.ts +89 -0
- package/src/errors.ts +108 -0
- package/src/events.ts +10 -1
- package/src/evidence.ts +6 -0
- package/src/extract.ts +52 -709
- package/src/gemini/adapter.ts +9 -5
- package/src/gemini/endpoints.ts +12 -2
- package/src/gemini/generate.ts +19 -3
- package/src/groups.ts +162 -0
- package/src/html.ts +1071 -0
- package/src/index.ts +2 -1
- package/src/library.ts +43 -12
- package/src/limiter.ts +6 -1
- package/src/model.ts +8 -1
- package/src/node/handlers.ts +66 -16
- package/src/node/index.ts +2 -0
- package/src/node/ingest-child.ts +61 -0
- package/src/node/isolated.ts +464 -0
- package/src/office.ts +1047 -0
- package/src/openai/adapter.ts +14 -1
- package/src/pdf-pages.ts +2 -5
- package/src/peers.ts +29 -0
- package/src/plan.ts +2 -0
- package/src/ranged.ts +4 -2
- package/src/search.ts +738 -146
- package/src/text-index.ts +4 -2
- package/src/text.ts +214 -23
- package/src/tools.ts +192 -12
- package/src/types.ts +3 -3
- package/src/word-styles.ts +420 -0
- package/src/xlsx.ts +478 -0
- package/src/xml-stream.ts +224 -0
package/docs/how-it-works.md
CHANGED
|
@@ -47,14 +47,21 @@ question ─► plan the documents for the room left in the request, smallest fi
|
|
|
47
47
|
`[No text on this page. It may be a scan, a photo, or a chart.]`.
|
|
48
48
|
- **A PDF without any text** (a scan) is refused, unless its original is kept: then one of up
|
|
49
49
|
to `scannedPdfPages` (30) pages is stored, to be read by looking at its pages.
|
|
50
|
-
- **PPTX**: a `## Slide N` heading for each slide,
|
|
51
|
-
|
|
50
|
+
- **PPTX**: a `## Slide N` heading for each slide, numbered in the order of the slide show,
|
|
51
|
+
with its tables as `| cell | cell |` rows and its speaker notes after `[Speaker notes]`, and
|
|
52
|
+
the slide count as the document's `pages`. A slide that the slide show skips is headed
|
|
52
53
|
`## Slide N (hidden, not shown in the slide show)`, and its text is kept. **DOCX**: the body,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
with its headings as Markdown headings, list numbers as Word shows them (`2.1`, `(a)`) and
|
|
55
|
+
tables as rows of cells, then the footnotes, endnotes, comments, headers and footers, each
|
|
56
|
+
under a heading of its own (a repeated header once). The text of a run that Word hides comes
|
|
57
|
+
after the text of its paragraph that shows, each of its lines starting with
|
|
58
|
+
`[Hidden text, not shown in the document]`, and a long line is cut into pieces, each marked.
|
|
59
|
+
Text hidden through a style is not told apart
|
|
60
|
+
([Security](./security.md#hidden-text-in-word-powerpoint-and-html)). **XLSX**: a `## Sheet N: name`
|
|
61
|
+
section for each sheet, a `Columns:` line, then a line a row, `Row 12: | East | 1200.5 |`,
|
|
62
|
+
and the sheet count as `pages`. **HTML**: the text a browser shows, with headings, lists,
|
|
63
|
+
tables and the addresses of links; text the page hides (the `hidden` attribute, an inline
|
|
64
|
+
`display: none` or `visibility: hidden`) comes after its line, marked as Word's is. DOCX, PPTX and XLSX need the optional `jszip`.
|
|
58
65
|
- **Text, logs, Markdown, JSON and CSV** are read as UTF-8, or as UTF-16 when they start with a
|
|
59
66
|
byte-order mark or about half of their first bytes are zeros. A file that is not valid UTF-8
|
|
60
67
|
is read in the older encoding it was saved in, or as UTF-8 with its characters that are not
|
|
@@ -64,15 +71,15 @@ question ─► plan the documents for the room left in the request, smallest fi
|
|
|
64
71
|
read, and one whose page tree lists a page twice as soon as it does. With `@cantoo/pdf-lib`,
|
|
65
72
|
the same reading of the file that finds the pictures first adds up what each page would make
|
|
66
73
|
pdf.js run (its content, each form every time it is painted, the glyph programs of its Type3
|
|
67
|
-
fonts), and refuses a page that would hold the server for more than about 1.5 s, or 32
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
it is read, a PDF page by page and
|
|
71
|
-
refused once it passes `maxTextBytes` (100 MB by default, or `maxUploadBytes` when
|
|
72
|
-
larger); a PDF also past 100 times its size in text (after the first 16 MB); a DOCX
|
|
73
|
-
also past 32 million
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
fonts), and refuses a page that would hold the server for more than about 1.5 s, or 32 times
|
|
75
|
+
the size of the file in content when that is more, before pdf.js reads any page ([Pages that
|
|
76
|
+
would hold the server](./guides/pdfs.md#pages-that-would-hold-the-server)). The text is counted
|
|
77
|
+
as it is read, a PDF page by page and an Office file paragraph by paragraph or row by row, and
|
|
78
|
+
the file is refused once it passes `maxTextBytes` (100 MB by default, or `maxUploadBytes` when
|
|
79
|
+
that is larger); a PDF also past 100 times its size in text (after the first 16 MB); a DOCX,
|
|
80
|
+
PPTX or XLSX also past 32 million characters of text, 1,000,000 paragraphs with text,
|
|
81
|
+
paragraphs nested 32 deep, or 20,000 parts. The text of any other extractor, yours included, is
|
|
82
|
+
checked when it returns.
|
|
76
83
|
|
|
77
84
|
Formats, tables, the picture line, the refusals and your own extractors:
|
|
78
85
|
[PDFs and other formats](./guides/pdfs.md).
|
|
@@ -89,20 +96,22 @@ question ─► plan the documents for the room left in the request, smallest fi
|
|
|
89
96
|
mainframe file converted to UTF-8, and is removed in any other text. Right after
|
|
90
97
|
U+0080-U+00FF it is part of a UTF-8 letter read as Latin-1, and is removed there too.
|
|
91
98
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
"app.log did not contain
|
|
99
|
+
Then the text is composed (NFC): "e" followed by a combining accent becomes "é", as a model
|
|
100
|
+
writes it in a query (since 0.8.0). No line break is added or removed, but for U+0085 in a text
|
|
101
|
+
with no line feed. A text without these characters is kept as it is, and a line of megabytes is
|
|
102
|
+
cleaned in pieces of 256K characters. Then lines over 2,000 characters are split, after a space
|
|
103
|
+
or one of `,;}` near the end of a piece when there is one. A line that lost characters can be
|
|
104
|
+
split into fewer pieces than 0.5.0 split it, which moves the lines after it. Every line-based
|
|
105
|
+
tool then returns bounded output. A file with no text left is refused: "app.log did not contain
|
|
106
|
+
any text."
|
|
99
107
|
4. **Profile.**
|
|
100
108
|
- Count lines and characters, [estimate tokens](#token-estimates), and measure two sizes: the
|
|
101
109
|
UTF-8 bytes, and the bytes the text takes as a string in a JSON request body (`jsonBytes`),
|
|
102
110
|
which is what a request limit counts. Quotes, backslashes, tabs and line breaks take two bytes
|
|
103
111
|
there; the planner uses this size.
|
|
104
112
|
- A file detected as plain text becomes a **log** when it has at least 5 non-empty lines and at
|
|
105
|
-
least 40% of the first 200 of them start with a timestamp or a level
|
|
113
|
+
least 40% of the first 200 of them start with a timestamp or a level, or have the shape of an
|
|
114
|
+
access log, a JSON log line, klog or logfmt.
|
|
106
115
|
- Build an **outline**: headings with their line numbers. Markdown headings; after a blank
|
|
107
116
|
line, lines that start with Chapter, Part, Book, Section or Appendix, or the Hebrew words for
|
|
108
117
|
chapter, part and appendix, numbered headings such as `2.1 Scope`, and short lines in
|
|
@@ -110,28 +119,31 @@ question ─► plan the documents for the room left in the request, smallest fi
|
|
|
110
119
|
to 400 of them, each once and in order; otherwise 400 taken at even steps over the file,
|
|
111
120
|
from the top-level headings when there are more than 400 of them, or from all the headings
|
|
112
121
|
when there are fewer than 20 (see [`OutlineEntry`](./reference/library.md#outlineentry)).
|
|
113
|
-
Logs, JSON and CSV get no outline.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
122
|
+
Logs, JSON and CSV get no outline. No heading is taken from a fenced code block, and in a
|
|
123
|
+
plain text file that reads as code (a script, a configuration file) a `#` line is a comment,
|
|
124
|
+
not a heading; in other plain text, only one after a blank line and not followed by another.
|
|
125
|
+
- For a log, build a **profile**: lines by level (ERR counts as ERROR, WARNING as WARN, CRITICAL
|
|
126
|
+
as FATAL; since 0.8.0 also a level in lower case in brackets, after `level=` or in a JSON
|
|
127
|
+
field, pino's numbers and klog's letter), the first and last timestamp, and the ERROR, FATAL
|
|
128
|
+
and WARN lines grouped by shape. Timestamps are removed, and UUIDs, IP addresses, hex, quoted
|
|
129
|
+
values and numbers become `<id>`, `<ip>`, `<hex>`, `<s>` and `<n>`. So 81 timeouts to three
|
|
130
|
+
hosts become one entry, `[ERROR ×81, L6] ERROR Connection timeout after <n>ms to <ip>`: the
|
|
131
|
+
level, the count, the first line, and the template, which keeps the level word. The profile
|
|
132
|
+
keeps 15 entries, FATAL first, then ERROR, then WARN, each by count.
|
|
121
133
|
5. **Store**, in this order: the uploaded file (when its format is in `keepOriginals` and the store
|
|
122
134
|
has `putOriginal`), the line index (when the store has `putIndex`), then the text and its
|
|
123
135
|
metadata (`put`). A document exists once its metadata does; if a write fails, what was written
|
|
124
136
|
is deleted. The ID is `doc_` and 32 hex characters, and `expiresAt` is `ttlMs` (72 hours) later.
|
|
125
137
|
|
|
126
|
-
Steps 2 to 4 share the server with other requests. Each works in slices of about 12 ms, with a
|
|
127
|
-
|
|
138
|
+
Steps 2 to 4 share the server with other requests. Each works in slices of about 12 ms, with a pause
|
|
139
|
+
between two slices: the PDF extractor and the picture marks between pages, the DOCX, PPTX and XLSX
|
|
128
140
|
extractors as they unpack, the text extractor as it decodes a file that is not UTF-8, and then the
|
|
129
|
-
normalizing, the measures, the outline, the log profile and the line index. Ingests that run at
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
141
|
+
normalizing, the measures, the outline, the log profile and the line index. Ingests that run at once
|
|
142
|
+
take turns, one slice each. They run under one signal, aborted by the caller's `signal` or after
|
|
143
|
+
`ingestTimeoutMs` (2 minutes): `ingest` then throws, and nothing is stored. A step under way when it
|
|
144
|
+
aborts, such as one page of pdf.js, runs to its end in the background, and holds the server while it
|
|
145
|
+
runs: pdf.js reads a page without a pause. [Security](./security.md#uploads) has the limits and the
|
|
146
|
+
stalls measured.
|
|
135
147
|
|
|
136
148
|
The **line index** holds, for each line, where it starts in the UTF-8 bytes and in the string, which
|
|
137
149
|
lines start a passage for keyword search (about 1,500 characters or 40 lines), and which lines are
|
|
@@ -263,7 +275,7 @@ First lines:
|
|
|
263
275
|
A card holds:
|
|
264
276
|
|
|
265
277
|
- The name and `document_id`.
|
|
266
|
-
- The format, size, line count, page count (a PDF's pages, a PPTX's slides) and estimated tokens.
|
|
278
|
+
- The format, size, line count, page count (a PDF's pages, a PPTX's slides, an XLSX's sheets) and estimated tokens.
|
|
267
279
|
- A line that says the file is not in the model's context. When a whole-file read would be refused
|
|
268
280
|
(the file is estimated at more than `maxMapChunks` parts, with 5% leeway), it says instead that
|
|
269
281
|
the file can be searched and read by line ranges, and is too large to be analyzed whole. When
|
|
@@ -393,7 +405,7 @@ characters per token is right for a novel and three times too low for a log. The
|
|
|
393
405
|
| A run of ASCII punctuation | 0.85, for its first character only |
|
|
394
406
|
| A line break | 2.2 |
|
|
395
407
|
| A tab | 1 |
|
|
396
|
-
| A space | 0 before a letter, 0.2 before anything else |
|
|
408
|
+
| A space | 0 before a letter, 0.2 before anything else (once for a run of spaces). A run of spaces also costs 1 for each 16 spaces after its first, so 10,000 spaces are about 625 tokens; until 0.8.0 they cost nothing |
|
|
397
409
|
| Latin letters with accents (é, ü, ß) | 0.6 |
|
|
398
410
|
| Greek, Cyrillic | 0.4, 0.3 |
|
|
399
411
|
| Hebrew, Arabic | 0.52, 0.41 |
|
|
@@ -436,12 +448,19 @@ rules every tool follows, are in the [tools reference](./reference/tools.md).
|
|
|
436
448
|
|
|
437
449
|
- **`search_document`** finds lines. In `keywords` mode (the default) it ranks the passages of the
|
|
438
450
|
line index by BM25, computed when the search runs from substring hits: there is no term index to
|
|
439
|
-
build or keep up to date, it works in any language, and "timeout" also matches "timeouts".
|
|
451
|
+
build or keep up to date, it works in any language, and "timeout" also matches "timeouts". The
|
|
452
|
+
words of a query are split the way each script writes them (Chinese, Japanese and Thai have no
|
|
453
|
+
spaces), and a Hebrew word with prefix letters also searches its stem. In
|
|
440
454
|
`exact` and `regex` modes it returns the first `max_results` matching lines and the last one in
|
|
441
455
|
the file (with the lines around each when `context_lines` asks for them; none by default), and
|
|
442
456
|
`total_matching_lines` counts every matching line in the file, not only those shown; a line with
|
|
443
|
-
several matches counts once. When not all are shown, a note says how many of how many
|
|
444
|
-
`
|
|
457
|
+
several matches counts once. When not all are shown, a note says how many of how many, and
|
|
458
|
+
`next_from_line` where to go on:
|
|
459
|
+
`21 of the 442 matching lines are shown: the first 20 and the last (line 15269). To see the ones in between, search again with from_line 3108, or count them with group_by.`
|
|
460
|
+
It can also search a range of lines (`from_line`, `to_line`), show the last matches
|
|
461
|
+
(`order: "last"`), or count the matching lines per hour, per code or per message shape and show
|
|
462
|
+
none (`group_by`): a question about errors per hour is one call. In regex mode `\w` and `\b`
|
|
463
|
+
know the letters of every script.
|
|
445
464
|
The last match is there for a question about when something last happened: shown only the first
|
|
446
465
|
ones and the count, a model named a wrong line as the last
|
|
447
466
|
([Measurements](./measurements.md#reading-a-whole-file)). The count is exact unless the scan
|
|
@@ -471,7 +490,9 @@ that and 40,000 characters). In the loop it is cut further, never below 600 char
|
|
|
471
490
|
share of the room left in the request or, for the answer of a whole-file read, to the room the
|
|
472
491
|
other results of its turn left ([Room in the request](#room-in-the-request)). A list loses
|
|
473
492
|
entries from its end (an exact or regex search loses them from the end of its first matches, and
|
|
474
|
-
keeps the last one
|
|
493
|
+
keeps the last one; with `order: "last"` it loses the earliest; with `group_by` it loses its
|
|
494
|
+
smallest groups, and by time keeps the others in time order), a read loses lines, and the result
|
|
495
|
+
says what was cut and where to go on.
|
|
475
496
|
|
|
476
497
|
## Looking at pages
|
|
477
498
|
|
|
@@ -588,9 +609,9 @@ output tokens it billed besides its text.
|
|
|
588
609
|
a complete list or an exact count, `search_document` in exact or regex mode is the reliable tool: it
|
|
589
610
|
reports `total_matching_lines`. The tool guide says so, and keeps the whole-file read for what
|
|
590
611
|
needs meaning: a summary, a timeline, items that must be judged one by one. A search shows the
|
|
591
|
-
first `max_results` matching lines (50 at most) and the last one
|
|
592
|
-
|
|
593
|
-
[Measurements](./measurements.md).
|
|
612
|
+
first `max_results` matching lines (50 at most) and the last one; a longer list is read on with
|
|
613
|
+
`next_from_line`, its end with `order: "last"`, and counted by group with `group_by`, which shows
|
|
614
|
+
up to 200 groups. The live checks are in [Measurements](./measurements.md).
|
|
594
615
|
|
|
595
616
|
## The loop (`askWithFiles`)
|
|
596
617
|
|
|
@@ -762,7 +783,9 @@ end the question:
|
|
|
762
783
|
|
|
763
784
|
- **Shorten and send again.** The loop takes the provider's numbers for the rest of the question:
|
|
764
785
|
its count of the request raises the estimate (up to 8 times), and the window it names lowers the
|
|
765
|
-
limit of the room.
|
|
786
|
+
limit of the room. A later report of the input tokens, which otherwise moves the estimate within
|
|
787
|
+
twice the estimate, does not take that back (since 0.7.1; before, the next good reply brought it
|
|
788
|
+
down to twice, and the turn after filled the window and was refused again). It then replaces older results with stand-ins, the latest round too if needed,
|
|
766
789
|
and sends the request again. `steps` says "The request was larger than the model takes: older tool
|
|
767
790
|
results were shortened, and it was sent again". That happens at most twice a question, and once
|
|
768
791
|
for any one request. When any model of the question may only grow its conversation (Claude),
|
package/docs/reference/ask.md
CHANGED
|
@@ -114,12 +114,13 @@ allowance as the window, and its steps say so.
|
|
|
114
114
|
|---|---|---|
|
|
115
115
|
| `Error`: "budget.… must be a number above 0, and is …", or "budget.reservedTokens (…) must be smaller than budget.contextTokens (…)…" (the same for `mapChunkTokens`) | A field of `options.budget` is not a number above 0, or the fields cannot work together. Before any request. See [`resolveBudget`](./library.md#resolvebudgetbudget-limits). | undefined |
|
|
116
116
|
| `Error`: "The last message must be the user's." | `messages` is empty, or its last message is not a user turn. | undefined |
|
|
117
|
+
| `RangeError`: "limits.… must be a number, and is NaN. Leave it out for the default.", or `TypeError`: "limits.… must be a number, and is …" | A field of `options.limits` is NaN, or not a number. Before any request. New in 0.7.1. | undefined |
|
|
117
118
|
| [`DocumentStoreError`](./library.md#documentstoreerror) | The store could not be read while the documents were planned. The documents are not gone: try again. A store that fails during a tool call is not thrown: the model gets the message as the tool's `error`. | undefined |
|
|
118
119
|
| [`DocumentsNotFoundError`](#documentsnotfounderror) | A document of `documentIds` was never stored, has expired or been deleted, or belongs to another `owner`. Before any request. | undefined |
|
|
119
120
|
| [`ModelRequestError`](./errors-and-retries.md#modelrequesterror), or the adapter's subclass (`GeminiRequestError`, `OpenAiRequestError`, `AnthropicRequestError`) | A chat request failed, and was not worth another try, still failed after `retry.retries` more, asked for a longer wait than `retry.maxDelayMs`, or had already shown text. A `context_overflow` that the recovery above did not mend. | What the question had done |
|
|
120
121
|
| Any other error of an adapter | Thrown as it came. An error without a numeric `status` is not sent again. | What the question had done |
|
|
121
122
|
| What a listener threw | `onEvent`, `onText`, `onActivity` or `onStep` threw. The question stops: the calls of the turn still running stop, and no request follows. New in 0.7.0 for a throw during a whole-file read (`onActivity` on its progress, `onEvent` on its events): 0.6.0 reported it to the model as the tool's error, and went on. | What the question had done, when the error is an object and the question was under way |
|
|
122
|
-
| The signal's reason | `signal` aborted. Nothing is sent or retried after that, no part of a whole-file read either. It is thrown at once, also while an adapter (or a part reader) that does not look at the signal is still at work, and also when the adapter then fails with its own error. Text that such an adapter sends later is not shown. | What the question had done, when the reason is an object |
|
|
123
|
+
| The signal's reason | `signal` aborted. Nothing is sent or retried after that, no part of a whole-file read either. It is thrown at once, also while an adapter (or a part reader) that does not look at the signal is still at work, and also when the adapter then fails with its own error. Text that such an adapter sends later is not shown. | What the question had done, when the reason is an object that no other question threw too (see [`partialResultOf`](#partialresultoferror)) |
|
|
123
124
|
|
|
124
125
|
When the documents were planned again after an overflow and the second plan fails before it sends
|
|
125
126
|
anything, the first overflow error is thrown, with what the first try had done. A whole-file part
|
|
@@ -256,7 +257,11 @@ Guides: [conversations](../guides/conversations.md) (`messages`, `documentPlacem
|
|
|
256
257
|
|
|
257
258
|
### `AskLimits`
|
|
258
259
|
|
|
259
|
-
The limits of one question: `AskOptions.limits`. Every field is optional.
|
|
260
|
+
The limits of one question: `AskOptions.limits`. Every field is optional. A field that is NaN
|
|
261
|
+
(what `Number(process.env.X)` gives for a variable that is not set) throws a `RangeError`, and one
|
|
262
|
+
that is not a number a `TypeError`, before any request: since 0.7.1, as a budget field does. NaN
|
|
263
|
+
used to fail every comparison, so it turned off the ceilings and the cap on whole-file reads, or
|
|
264
|
+
every tool. `Infinity` sets no ceiling.
|
|
260
265
|
|
|
261
266
|
| Field | Type | Default | What it does |
|
|
262
267
|
|---|---|---|---|
|
|
@@ -311,6 +316,14 @@ counted. It returns `undefined` for an error that did not come from a question u
|
|
|
311
316
|
document, a budget that cannot work, a store that could not be read while planning) and for a
|
|
312
317
|
value that is not an object. The sample under [`askWithFiles`](#askwithfilesoptions) uses it.
|
|
313
318
|
|
|
319
|
+
One error object can be thrown by several questions: the reason of a signal they share, such as
|
|
320
|
+
one controller for a batch, or a server's shutdown signal that each question joins with
|
|
321
|
+
`AbortSignal.any` (it passes the reason on as it is). Since 0.7.1, `partialResultOf` then returns
|
|
322
|
+
`undefined` for it, rather than the result of whichever question failed last, which held another
|
|
323
|
+
user's tool rounds and usage. Each question's `run.error` event still carries its own `partial`.
|
|
324
|
+
To get the result from `partialResultOf`, give each question a signal whose reason is its own:
|
|
325
|
+
`const own = new AbortController(); shared.addEventListener("abort", () => own.abort(new DOMException("Stopped.", "AbortError")), { once: true });`.
|
|
326
|
+
|
|
314
327
|
The `run.error` event carries the same result as `partial`, as an `EventResult`: without
|
|
315
328
|
`toolTurns`, and with a plan that names the documents only (both hold text of the documents),
|
|
316
329
|
unless `eventResults` is set; and
|
|
@@ -359,14 +372,14 @@ The user turn at the end of the request for the answer, when a document is reach
|
|
|
359
372
|
and tool calls were answered:
|
|
360
373
|
|
|
361
374
|
> Stop using tools now. Answer my question using only what the tools returned above, with line
|
|
362
|
-
> citations. Say plainly what you could not find.
|
|
375
|
+
> citations. Say plainly what you could not find. Answer in the language of my question.
|
|
363
376
|
|
|
364
377
|
### `FINAL_ANSWER_AFTER_PAGES`
|
|
365
378
|
|
|
366
379
|
The same, when every document went in whole and the only tool was `view_pages`:
|
|
367
380
|
|
|
368
381
|
> Stop using tools now. Answer my question from the text of the files and the pages you looked at.
|
|
369
|
-
> Say plainly what you could not see or find.
|
|
382
|
+
> Say plainly what you could not see or find. Answer in the language of my question.
|
|
370
383
|
|
|
371
384
|
### `FINAL_ANSWER_WITHOUT_TOOLS`
|
|
372
385
|
|
|
@@ -374,7 +387,12 @@ The same, when no tool call was answered in the question (an explorer called non
|
|
|
374
387
|
was empty, or no turn was left for tools), so there is no tool result to answer from:
|
|
375
388
|
|
|
376
389
|
> Answer my question now, from what is in this conversation. No tools are available for this reply:
|
|
377
|
-
> if the answer needs a part of a file that is not shown here, say so plainly.
|
|
390
|
+
> if the answer needs a part of a file that is not shown here, say so plainly. Answer in the language
|
|
391
|
+
> of my question.
|
|
392
|
+
|
|
393
|
+
The three end with "Answer in the language of my question." since 0.8.0: a model asked in Hebrew
|
|
394
|
+
answered in English after an English closing request. To have answers in one language whatever
|
|
395
|
+
the question, say so in `system`.
|
|
378
396
|
|
|
379
397
|
None of the three is kept in the conversation or in `toolTurns`. Nor is the note of the answer's
|
|
380
398
|
second try, which is not exported (new in 0.6.0): "Your last reply had no text. No tool can be
|
|
@@ -466,7 +484,7 @@ A model provider, as the tool loop sees it.
|
|
|
466
484
|
| `capabilities` | yes | What the model can take: see [`ModelCapabilities`](#modelcapabilities). |
|
|
467
485
|
| `send(request, hooks?)` | yes | One chat request. Returns a [`ModelReply`](#modelreply). Throw a [`ModelRequestError`](./errors-and-retries.md#modelrequesterror) for an HTTP error, with status 0 for a connection that failed. The loop reads `status`, `kind`, `retryAfterMs`, `limitTokens` and `requestedTokens` from the error, and sends again the ones worth it. |
|
|
468
486
|
| `requestBytes?(request)` | no | The size in bytes of the body `send` would post for `request`. The loop calls it before it shows the pages of a PDF in a turn, with the turn whose calls are being run as a round with no `answers` yet. With it the room for the pages is exact; without it, it is estimated. |
|
|
469
|
-
| `generateText` | no | A plain completion for the parts of a whole-file read: see [`GenerateText`](#generatetext). The one of the model that explores is used. Without it, `analyze_whole_document` is not offered. |
|
|
487
|
+
| `generateText` | no | A plain completion for the parts of a whole-file read: see [`GenerateText`](#generatetext). The one of the model that explores is used. Without it, `analyze_whole_document` is not offered. It is called on its adapter, as `send` is, so a method of a class may use `this` (since 0.7.1; before, every part read of such a method failed). |
|
|
470
488
|
| `estimateTokens?(text)` | no | Deprecated, and never called: `askWithFiles` sizes every request with the library's `estimateTokens`, scaled by `tokenScale`. Set `capabilities.tokenScale` for a model that counts differently. It is kept so that adapters that set it still compile, and a later version may remove it. |
|
|
471
489
|
|
|
472
490
|
What `send` must do with the request:
|
|
@@ -531,8 +549,8 @@ reference page.
|
|
|
531
549
|
|---|---|---|---|
|
|
532
550
|
| `contextTokens` | `number` | none | The context window, in the model's tokens. The window of a question is the smallest of the library's `budget.contextTokens` and those its models declare. |
|
|
533
551
|
| `maxRequestBytes` | `number` | none | The largest request body, in bytes. A question's `budget.maxRequestBytes` is the smallest of the library's and those its models declare. |
|
|
534
|
-
| `toolFiles` | `"inside" \| "beside" \| "none"` | required | Where `send` puts a file that a tool returned (the pages of `view_pages`): `"inside"` the tool result, `"beside"` it in a user turn of its own, or `"none"` for a model that cannot be sent one. When any model of the question says `"none"`, `view_pages` is not offered. |
|
|
535
|
-
| `pageTokens` | `number` | required | About what the model bills for one PDF page it is shown, in its tokens. The question counts the largest of its models': the pages of a question may take up to half of `budget.reservedTokens`. |
|
|
552
|
+
| `toolFiles` | `"inside" \| "beside" \| "none"` | required | Where `send` puts a file that a tool returned (the pages of `view_pages`): `"inside"` the tool result, `"beside"` it in a user turn of its own, or `"none"` for a model that cannot be sent one. When any model of the question says `"none"`, `view_pages` is not offered. Since 0.7.1 a value that is none of the three (left out by an adapter written in JavaScript) counts as `"none"`. |
|
|
553
|
+
| `pageTokens` | `number` | required | About what the model bills for one PDF page it is shown, in its tokens. The question counts the largest of its models': the pages of a question may take up to half of `budget.reservedTokens`. Since 0.7.1 a value that is missing, NaN, negative or not finite counts as 1,000, as `openAiCompatible()` declares by default: before, it took away the question's limit of pages and, once a page was shown, every count of the room left. |
|
|
536
554
|
| `tokenScale` | `number` | 1 | How many of this model's tokens one token of the library's estimate (`estimateTokens`, fitted to Gemini) comes to. A model that counts a third more for the same text says 1.33, and its window is that much smaller in the library's tokens. The question uses the largest of its models'. A value that is not above 0 counts as 1. |
|
|
537
555
|
| `outputTokens` | `number` | none | Tokens set aside for the reply, when they come out of the same window as the prompt (Claude's `max_tokens`). The largest of the models' is kept free, but at least a quarter of the window is left for the prompt. |
|
|
538
556
|
| `appendOnly` | `boolean` | `false` | True for a model whose earlier turns may not be rewritten (Claude ties its thinking blocks to the turns they were written in). When any model of the question says so, old tool results are not shortened to make room: when the room runs out, the question is answered with what it has, and an overflow is mended only by planning the documents again. When the model that explores is append-only, a note the loop adds after an empty or broken reply stays in its conversation for the rest of the question. |
|
|
@@ -308,7 +308,7 @@ errorKindOf({ kind: "quota" }); // "quota": any
|
|
|
308
308
|
### Other error classes
|
|
309
309
|
|
|
310
310
|
The adapters' errors are `ModelRequestError`s, so `instanceof ModelRequestError` and
|
|
311
|
-
`errorKindOf` work for all three. The
|
|
311
|
+
`errorKindOf` work for all three. The three errors of the documents are not, and have no `kind`.
|
|
312
312
|
|
|
313
313
|
| Class | Exported from | Extends | Fields of its own | Reference |
|
|
314
314
|
|---|---|---|---|---|
|
|
@@ -317,11 +317,12 @@ The adapters' errors are `ModelRequestError`s, so `instanceof ModelRequestError`
|
|
|
317
317
|
| `AnthropicRequestError` | `llm-large-files/anthropic` | `ModelRequestError` | `type` | [anthropic.md](./anthropic.md) |
|
|
318
318
|
| `DocumentsNotFoundError` | `llm-large-files`, `llm-large-files/gemini` | `Error` | `ids` | [ask.md](./ask.md#documentsnotfounderror) |
|
|
319
319
|
| `DocumentStoreError` | `llm-large-files` | `Error` | `code`, `syscall`, and the caught error as `cause` | [library.md](./library.md#documentstoreerror) |
|
|
320
|
+
| `IngestError` | `llm-large-files` | `Error` | `code`, `status`, `retryAfterMs`, and the extractor's error as `cause`. New in 0.8.0 | [library.md](./library.md#ingesterror) |
|
|
320
321
|
|
|
321
322
|
### Errors in events: `EventError`
|
|
322
323
|
|
|
323
324
|
```ts
|
|
324
|
-
type EventError = { message: string; kind?: ModelErrorKind; status?: number; name?: string };
|
|
325
|
+
type EventError = { message: string; kind?: ModelErrorKind; status?: number; name?: string; code?: IngestErrorCode };
|
|
325
326
|
```
|
|
326
327
|
|
|
327
328
|
New in 0.7.0. An error as the events of a question or an ingest carry it ([events](./events.md)):
|
|
@@ -334,7 +335,8 @@ included: log that one.
|
|
|
334
335
|
| `message` | `string` | Words your users may see. A model error is told by its kind and status, never in the provider's words, which can name projects, hosts or keys: "The model was busy (HTTP 429).", "The model's quota has run out (HTTP 429).", "The model could not be reached.", "The model refused the key or token it was sent (HTTP 401)." A Node system error is told by its code ("The file could not be read from storage (ENOENT)."), a `DocumentStoreError` by its own message, which names only its code, and a store that failed to write in `ingest.error` as "The document could not be stored. Try again later.". The library's own errors (a refused file, `DocumentsNotFoundError`, an abort, the error a listener threw) keep their message, and so does any other `Error` without a `kind` or a numeric `status`, such as one an adapter or a token function of your own throws: give such errors a status, or words of your own. A value that is not an `Error` is "Something went wrong.". |
|
|
335
336
|
| `kind` | [`ModelErrorKind`](#modelerrorkind), optional | For a model error: its kind, as [`errorKindOf`](#errorkindoferror) reads it. |
|
|
336
337
|
| `status` | `number`, optional | For an HTTP error: its status. 0 when no answer came. |
|
|
337
|
-
| `name` | `string`, optional | The error's class name: `"ModelRequestError"`, `"GeminiRequestError"`, `"AbortError"`, `"DocumentsNotFoundError"`… |
|
|
338
|
+
| `name` | `string`, optional | The error's class name: `"ModelRequestError"`, `"GeminiRequestError"`, `"AbortError"`, `"DocumentsNotFoundError"`, `"IngestError"`… |
|
|
339
|
+
| `code` | [`IngestErrorCode`](./library.md#ingesterror), optional | For a file `ingest` could not read: why (`"too_large"`, `"no_text"`, `"busy"`…). New in 0.8.0. |
|
|
338
340
|
|
|
339
341
|
To show your own words, map the error by `kind`, `status` or `name`, as you would the thrown one
|
|
340
342
|
(see [Errors and reliability](../guides/errors-and-reliability.md)).
|
package/docs/reference/events.md
CHANGED
|
@@ -191,7 +191,7 @@ and then `run.error`.
|
|
|
191
191
|
| `name` | `string` | The file name. |
|
|
192
192
|
| `format` | `DocumentFormat` | `"text"`, `"log"`, `"pdf"`… |
|
|
193
193
|
| `estimatedTokens` | `number` | The library's estimate of the document's tokens. |
|
|
194
|
-
| `pages` | `number`, optional | For a PDF or
|
|
194
|
+
| `pages` | `number`, optional | For a PDF, a PPTX or an XLSX (its sheets). |
|
|
195
195
|
|
|
196
196
|
#### `request.start`
|
|
197
197
|
|
|
@@ -436,7 +436,8 @@ An error in an event is plain data, safe to send to a browser:
|
|
|
436
436
|
| `message` | `string` | A message your users may see. |
|
|
437
437
|
| `kind` | `ModelErrorKind`, optional | For a model error: what kind it is (`errorKindOf`): `"rate_limit"`, `"timeout"`, `"auth"`… |
|
|
438
438
|
| `status` | `number`, optional | For an HTTP error: its status. 0 when no answer came. |
|
|
439
|
-
| `name` | `string`, optional | The error's class name: `"ModelRequestError"`, `"AbortError"`, `"DocumentsNotFoundError"`… |
|
|
439
|
+
| `name` | `string`, optional | The error's class name: `"ModelRequestError"`, `"AbortError"`, `"DocumentsNotFoundError"`, `"IngestError"`… |
|
|
440
|
+
| `code` | `IngestErrorCode`, optional | For a file `ingest` could not read: why, as [`IngestError.code`](./library.md#ingesterror) (`"too_large"`, `"no_text"`, `"hostile"`, `"busy"`…), so that a page can say it in its own words. New in 0.8.0. |
|
|
440
441
|
|
|
441
442
|
How `message` is written:
|
|
442
443
|
|
|
@@ -453,6 +454,12 @@ How `message` is written:
|
|
|
453
454
|
or give them a `status`.
|
|
454
455
|
- **Anything that is not an `Error`** is told as "Something went wrong.".
|
|
455
456
|
|
|
457
|
+
An [`IngestError`](./library.md#ingesterror) is told by its message, with `name: "IngestError"` and
|
|
458
|
+
its `code`, and with its `status` only for `"too_large"` (413) and `"busy"` (503): that status is the
|
|
459
|
+
answer of an upload, not of a model, and the others are all 422. Until 0.8.0 the same refusals were
|
|
460
|
+
plain `Error`s, and their events said `name: "Error"`; a test that expects that needs
|
|
461
|
+
`"IngestError"`. A store that failed, an abort and a listener that threw have no `code`.
|
|
462
|
+
|
|
456
463
|
Where errors appear: `retry.error`, `request.end.error`, `run.error.error` and `ingest.error.error`
|
|
457
464
|
are `EventError`s. `tool.end.error` is a string: the error the model was sent, or, for a call
|
|
458
465
|
ended because its turn failed, the `message` of the turn's error. An ingest whose store failed to
|
|
@@ -460,7 +467,7 @@ write the document says only "The document could not be stored. Try again later.
|
|
|
460
467
|
store threw.
|
|
461
468
|
|
|
462
469
|
To show your own words, map the error by `kind` and `name`, as `examples/server.ts` does in its
|
|
463
|
-
`userMessage`. [Errors and reliability](../guides/errors-and-reliability.md) says what each kind
|
|
470
|
+
`userMessage`, and the error of an ingest by `code`. [Errors and reliability](../guides/errors-and-reliability.md) says what each kind
|
|
464
471
|
means.
|
|
465
472
|
|
|
466
473
|
### Documents: `eventResults` and `EventResult`
|
|
@@ -792,9 +799,9 @@ this order, and each stage ends before the next starts:
|
|
|
792
799
|
| Stage | Unit | `total` | What it counts | When |
|
|
793
800
|
|---|---|---|---|---|
|
|
794
801
|
| `"check"` | pages | the pages | Pages checked before their text is read. | A PDF, with `@cantoo/pdf-lib` installed and `checkPages` on. |
|
|
795
|
-
| `"extract"` | pages, or parts | the pages, or the parts | Text read: each page of a PDF; each part of a DOCX (body,
|
|
802
|
+
| `"extract"` | pages, or parts | the pages, or the parts | Text read: each page of a PDF; each part of a DOCX (body, footnotes, headers…), each slide of a PPTX or each sheet of an XLSX. | A PDF, DOCX, PPTX or XLSX, or an extractor of your own that reports it. Not a text file. |
|
|
796
803
|
| `"pictures"` | pages | the pages | Pages looked at for pictures. | A PDF, with `@cantoo/pdf-lib` installed and `pictures` on. |
|
|
797
|
-
| `"decode"` | bytes | the bytes | One event when the file is decoded. | A text file that is not UTF-8. |
|
|
804
|
+
| `"decode"` | bytes | the bytes | One event when the file is decoded. | A text file that is not UTF-8, and every HTML file. |
|
|
798
805
|
| `"prepare"` | characters | the characters | The text cleaned before it is cut into lines. | Every file. |
|
|
799
806
|
| `"index"` | characters | the characters | The line index built. | A store with `putIndex`, such as `FileDocumentStore`. |
|
|
800
807
|
| `"store"` | parts | the writes | Each write to the store, once done: the original file (`keepOriginals`), the line index, then the text. | Every file. |
|
|
@@ -826,7 +833,8 @@ not only through a wildcard such as `*/*` or `text/*`.
|
|
|
826
833
|
- `ingest.error`, whose `error` is `{ message, status }`, the message and status a JSON answer
|
|
827
834
|
would have: `422` with the reason for a file that cannot be read ("empty.txt is empty."),
|
|
828
835
|
`500` "Upload failed." for a store that failed, and so on, as in the
|
|
829
|
-
[node reference](./node.md#uploadrequest-response).
|
|
836
|
+
[node reference](./node.md#uploadrequest-response). For a file that could not be read, it also
|
|
837
|
+
has `code`, the `IngestError` code (`"empty"`, `"busy"`…; new in 0.8.0).
|
|
830
838
|
3. When the client goes away, the ingest stops and nothing is stored.
|
|
831
839
|
|
|
832
840
|
It always ends with `ingest.finish` or `ingest.error`, even with a `LargeFiles` of your own whose
|
package/docs/reference/gemini.md
CHANGED
|
@@ -109,7 +109,7 @@ The endpoint of a Gemini model on Vertex AI, signed in with an OAuth access toke
|
|
|
109
109
|
| `project` | `string` | required | The Google Cloud project ID. URL-encoded into the path. |
|
|
110
110
|
| `model` | `string` | required | The model that answers, under `publishers/google/models/`. Without an explorer it also makes the tool calls. |
|
|
111
111
|
| `explorerModel` | `string \| undefined` | none | A second model that explores the documents, with the same rules as in [`geminiApi()`](#geminiapioptions). It is in the same project and location. |
|
|
112
|
-
| `location` | `string` | `"global"` | Where the requests are served. It picks the host ([`vertexHost()`](#vertexhostlocation)) and is the `locations/{location}` segment of the path,
|
|
112
|
+
| `location` | `string` | `"global"` | Where the requests are served. It picks the host ([`vertexHost()`](#vertexhostlocation)) and is the `locations/{location}` segment of the path. It must be lowercase letters, digits and single hyphens (`"global"`, `"us"`, `"europe-west4"`): anything else throws a `TypeError`, since 0.7.1. |
|
|
113
113
|
| `accessToken` | `string \| (() => string \| Promise<string>)` | required | Sent as `Authorization: Bearer {token}`. A function is called before every request, chat requests and part reads of both models alike, so it can return a renewed token. |
|
|
114
114
|
| `apiVersion` | `string` | `"v1"` | The version segment of the path. |
|
|
115
115
|
|
|
@@ -150,7 +150,10 @@ Guide: [Gemini API and Vertex AI](../guides/vertex-and-gemini.md), which covers
|
|
|
150
150
|
declare function vertexHost(location: string): string;
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
The Vertex AI host of a location, as `vertexAi()` uses it.
|
|
153
|
+
The Vertex AI host of a location, as `vertexAi()` uses it. Since 0.7.1 the location is checked: one
|
|
154
|
+
that is not lowercase letters and digits joined by single hyphens throws a `TypeError` ("location
|
|
155
|
+
must be a Vertex AI location such as "global", "us" or "europe-west4", and is …"). With `/`, `?`,
|
|
156
|
+
`#` or `@` in it, it would have named another host, and that host would have got the access token.
|
|
154
157
|
|
|
155
158
|
| `location` | Host |
|
|
156
159
|
|---|---|
|
|
@@ -583,6 +586,7 @@ first request to a `url` goes alone: requests to it that arrive meanwhile wait f
|
|
|
583
586
|
| A body that is not JSON | `GeminiRequestError`: "Gemini's reply could not be read: it was not JSON (text/html). A proxy or gateway may have answered in its place.", the response's `status`, kind `"invalid"`, the `SyntaxError` as `cause`. Until 0.6.0, the `SyntaxError` itself. |
|
|
584
587
|
| `timeoutMs` passed, or `signal` aborted | The abort error, as it is, with no status |
|
|
585
588
|
| A reply with no text | `Error`: "The model returned no text." or, with its `finishReason`, "The model returned no text (SAFETY)." |
|
|
589
|
+
| A prompt Gemini blocked: HTTP 200 with `promptFeedback.blockReason` and no candidate | `Error`: "The model returned no text (PROHIBITED_CONTENT).", with the block reason. It is not sent again: it would be blocked again. Before 0.7.1 it had no reason, and a whole-file read sent it once more. |
|
|
586
590
|
|
|
587
591
|
A whole-file read tries a part once more after an error with no status. It tells the model why a
|
|
588
592
|
part failed by the error's kind and status, never by Gemini's message: "The model took too long to
|