llm-large-files 0.4.1 → 0.5.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 +127 -0
- package/README.md +48 -8
- package/dist/anthropic/adapter.d.ts +106 -0
- package/dist/anthropic/adapter.d.ts.map +1 -0
- package/dist/anthropic/adapter.js +391 -0
- package/dist/anthropic/adapter.js.map +1 -0
- package/dist/anthropic/index.d.ts +3 -0
- package/dist/anthropic/index.d.ts.map +1 -0
- package/dist/anthropic/index.js +2 -0
- package/dist/anthropic/index.js.map +1 -0
- package/dist/ask.d.ts +144 -0
- package/dist/ask.d.ts.map +1 -0
- package/dist/ask.js +540 -0
- package/dist/ask.js.map +1 -0
- package/dist/budget.d.ts +23 -0
- package/dist/budget.d.ts.map +1 -0
- package/dist/budget.js +64 -0
- package/dist/budget.js.map +1 -0
- package/dist/evidence.d.ts +40 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +137 -0
- package/dist/evidence.js.map +1 -0
- package/dist/gemini/adapter.d.ts +50 -0
- package/dist/gemini/adapter.d.ts.map +1 -0
- package/dist/gemini/adapter.js +179 -0
- package/dist/gemini/adapter.js.map +1 -0
- package/dist/gemini/chat.d.ts +31 -75
- package/dist/gemini/chat.d.ts.map +1 -1
- package/dist/gemini/chat.js +38 -300
- package/dist/gemini/chat.js.map +1 -1
- package/dist/gemini/errors.d.ts +11 -0
- package/dist/gemini/errors.d.ts.map +1 -0
- package/dist/gemini/errors.js +14 -0
- package/dist/gemini/errors.js.map +1 -0
- package/dist/gemini/generate.d.ts +9 -20
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +43 -92
- package/dist/gemini/generate.js.map +1 -1
- package/dist/gemini/index.d.ts +3 -1
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/gemini/index.js +2 -1
- package/dist/gemini/index.js.map +1 -1
- package/dist/gemini/sse.d.ts +1 -2
- package/dist/gemini/sse.d.ts.map +1 -1
- package/dist/gemini/sse.js +1 -38
- package/dist/gemini/sse.js.map +1 -1
- package/dist/http.d.ts +20 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +55 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts +29 -3
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +10 -12
- package/dist/library.js.map +1 -1
- package/dist/map-reduce.d.ts +9 -0
- package/dist/map-reduce.d.ts.map +1 -1
- package/dist/map-reduce.js +25 -19
- package/dist/map-reduce.js.map +1 -1
- package/dist/model.d.ts +196 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +41 -0
- package/dist/model.js.map +1 -0
- package/dist/openai/adapter.d.ts +85 -0
- package/dist/openai/adapter.d.ts.map +1 -0
- package/dist/openai/adapter.js +293 -0
- package/dist/openai/adapter.js.map +1 -0
- package/dist/openai/index.d.ts +3 -0
- package/dist/openai/index.d.ts.map +1 -0
- package/dist/openai/index.js +2 -0
- package/dist/openai/index.js.map +1 -0
- package/dist/output-limit.d.ts +30 -0
- package/dist/output-limit.d.ts.map +1 -0
- package/dist/output-limit.js +92 -0
- package/dist/output-limit.js.map +1 -0
- package/dist/retry.d.ts +54 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +111 -0
- package/dist/retry.js.map +1 -0
- package/dist/sse.d.ts +3 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +39 -0
- package/dist/sse.js.map +1 -0
- package/dist/tools.d.ts +11 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +85 -31
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +28 -3
- package/dist/types.d.ts.map +1 -1
- package/docs/api.md +245 -27
- package/docs/configuration.md +83 -9
- package/docs/getting-started.md +67 -16
- package/docs/how-it-works.md +38 -2
- package/docs/security.md +18 -0
- package/package.json +21 -3
- package/src/anthropic/adapter.ts +454 -0
- package/src/anthropic/index.ts +2 -0
- package/src/ask.ts +675 -0
- package/src/budget.ts +71 -0
- package/src/evidence.ts +162 -0
- package/src/gemini/adapter.ts +218 -0
- package/src/gemini/chat.ts +61 -353
- package/src/gemini/errors.ts +15 -0
- package/src/gemini/generate.ts +50 -90
- package/src/gemini/index.ts +3 -1
- package/src/gemini/sse.ts +1 -34
- package/src/http.ts +59 -0
- package/src/index.ts +33 -4
- package/src/library.ts +39 -13
- package/src/map-reduce.ts +22 -16
- package/src/model.ts +200 -0
- package/src/openai/adapter.ts +345 -0
- package/src/openai/index.ts +2 -0
- package/src/output-limit.ts +99 -0
- package/src/retry.ts +132 -0
- package/src/sse.ts +34 -0
- package/src/tools.ts +91 -34
- package/src/types.ts +24 -3
package/dist/gemini/chat.d.ts
CHANGED
|
@@ -1,38 +1,16 @@
|
|
|
1
|
+
import { type AskLimits, type AskResult } from "../ask.js";
|
|
1
2
|
import type { LargeFiles } from "../library.js";
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type
|
|
12
|
-
|
|
13
|
-
text: string;
|
|
14
|
-
};
|
|
15
|
-
/** Sent (invisibly to the user) when the model must stop using tools and answer. */
|
|
16
|
-
export declare const FINAL_ANSWER_REQUEST = "Stop using tools now. Answer my question using only what the tools returned above, with line citations. Say plainly what you could not find.";
|
|
17
|
-
/** The same, when the only tool was `view_pages`: the text of the files is in the prompt, not in tool results. */
|
|
18
|
-
export declare const FINAL_ANSWER_AFTER_PAGES = "Stop using tools now. Answer my question from the text of the files and the pages you looked at. Say plainly what you could not see or find.";
|
|
19
|
-
/** Sent to the answering model when an explorer model used no tool, so there is no tool result to answer from. */
|
|
20
|
-
export declare const FINAL_ANSWER_WITHOUT_TOOLS = "Answer my question now, from what is in this conversation. No tools are available for this reply: if the answer needs a part of a file that is not shown here, say so plainly.";
|
|
21
|
-
/**
|
|
22
|
-
* Added to the system instruction of an explorer model's requests: it gathers what the answer
|
|
23
|
-
* needs, and the other model writes the answer.
|
|
24
|
-
*/
|
|
25
|
-
export declare const EXPLORER_INSTRUCTION = "You only gather material in this conversation: another model writes the answer. It sees this conversation and what your tool calls returned, not what you thought or wrote. So call the tools until their results hold everything the answer needs from the files. Then, or at once if no tool is needed, reply with the single word DONE instead of an answer.";
|
|
26
|
-
/** Some document IDs were never uploaded, have expired, or belong to another owner. */
|
|
27
|
-
export declare class DocumentsNotFoundError extends Error {
|
|
28
|
-
readonly ids: string[];
|
|
29
|
-
constructor(ids: string[]);
|
|
30
|
-
}
|
|
31
|
-
/** Gemini answered with an HTTP error. */
|
|
32
|
-
export declare class GeminiRequestError extends Error {
|
|
33
|
-
readonly status: number;
|
|
34
|
-
constructor(message: string, status: number);
|
|
35
|
-
}
|
|
3
|
+
import type { ChatTurn, ToolTurn } from "../model.js";
|
|
4
|
+
import type { RetryOptions } from "../retry.js";
|
|
5
|
+
import type { Budget } from "../types.js";
|
|
6
|
+
import { type GeminiContent } from "./adapter.js";
|
|
7
|
+
import type { GeminiEndpoint } from "./endpoints.js";
|
|
8
|
+
import type { GeminiToolFilePlacement } from "./generate.js";
|
|
9
|
+
export { DocumentsNotFoundError } from "../model.js";
|
|
10
|
+
export { EXPLORER_INSTRUCTION, FINAL_ANSWER_AFTER_PAGES, FINAL_ANSWER_REQUEST, FINAL_ANSWER_WITHOUT_TOOLS } from "../ask.js";
|
|
11
|
+
export type { ChatTurn } from "../model.js";
|
|
12
|
+
export type { GeminiContent, GeminiPart } from "./adapter.js";
|
|
13
|
+
export { GeminiRequestError } from "./errors.js";
|
|
36
14
|
export type AskGeminiOptions = {
|
|
37
15
|
files: LargeFiles;
|
|
38
16
|
/**
|
|
@@ -51,8 +29,11 @@ export type AskGeminiOptions = {
|
|
|
51
29
|
* did; the document then moves on every turn and is billed in full each time.
|
|
52
30
|
*/
|
|
53
31
|
documentPlacement?: "first" | "last";
|
|
54
|
-
/**
|
|
55
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Plain chat history; the last turn must be the user's question. It may hold the tool rounds of
|
|
34
|
+
* earlier questions (`toolTurns` of their results). Use this or `contents`.
|
|
35
|
+
*/
|
|
36
|
+
messages?: Array<ChatTurn | ToolTurn>;
|
|
56
37
|
/** Your own Gemini `contents` (with images, inline PDFs, etc.). The last turn must be the user's. */
|
|
57
38
|
contents?: GeminiContent[];
|
|
58
39
|
system?: string;
|
|
@@ -66,18 +47,16 @@ export type AskGeminiOptions = {
|
|
|
66
47
|
explorerGenerationConfig?: Record<string, unknown>;
|
|
67
48
|
/** The user asking. Documents ingested with a different owner are treated as missing. */
|
|
68
49
|
owner?: string;
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
* must answer. Defaults to 12. With an explorer model the answer is always a request of its
|
|
73
|
-
* own, the last one, so the explorer has one less than this.
|
|
74
|
-
*/
|
|
50
|
+
/** The limits of the question: tool turns, calls in a turn, whole-file reads, tokens and requests. */
|
|
51
|
+
limits?: AskLimits;
|
|
52
|
+
/** `limits.toolTurns`, under the name it had before 0.5.0. Defaults to 12. */
|
|
75
53
|
maxToolTurns?: number;
|
|
76
|
-
/**
|
|
77
|
-
* The most tool calls of one model turn that are run. A turn with more gets an error for each
|
|
78
|
-
* of the others, which tells the model to send it again if it is still needed. Defaults to 8.
|
|
79
|
-
*/
|
|
54
|
+
/** `limits.callsPerTurn`, under the name it had before 0.5.0. Defaults to 8. */
|
|
80
55
|
maxToolCallsPerTurn?: number;
|
|
56
|
+
/** How a request that failed is sent again. Defaults to three more tries, with a wait that doubles. */
|
|
57
|
+
retry?: RetryOptions;
|
|
58
|
+
/** Budget fields for this question, in place of the library's. */
|
|
59
|
+
budget?: Partial<Budget>;
|
|
81
60
|
/** Offer `analyze_whole_document`, which reads a whole file in many model calls. Defaults to true. */
|
|
82
61
|
wholeDocumentAnalysis?: boolean;
|
|
83
62
|
/**
|
|
@@ -107,36 +86,13 @@ export type AskGeminiOptions = {
|
|
|
107
86
|
fetch?: typeof fetch;
|
|
108
87
|
signal?: AbortSignal;
|
|
109
88
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
* Everything the model wrote, including any remark it made before calling a tool. With an
|
|
113
|
-
* explorer model, only what the answering model wrote: the explorer's words are not shown.
|
|
114
|
-
*/
|
|
115
|
-
text: string;
|
|
116
|
-
/**
|
|
117
|
-
* False when the model's last turn had no text: the prompt was blocked, the reply was cut off
|
|
118
|
-
* before any text, or the model produced a malformed tool call. `text` may then be empty or
|
|
119
|
-
* hold only an earlier remark, so show your own message instead of treating it as the answer.
|
|
120
|
-
*/
|
|
121
|
-
answered: boolean;
|
|
122
|
-
/** Why Gemini refused the prompt (`promptFeedback.blockReason`), when it did. */
|
|
123
|
-
blockReason?: string;
|
|
124
|
-
/** Every tool step taken, in order (also delivered through `onStep`). */
|
|
125
|
-
steps: string[];
|
|
126
|
-
/** Which documents went in whole and which were searched. */
|
|
127
|
-
plan: DocumentPlan;
|
|
128
|
-
/** Model requests made for the chat itself, an explorer model's among them (whole-document part reads not included). */
|
|
129
|
-
turns: number;
|
|
130
|
-
finishReason?: string;
|
|
131
|
-
/** Usage metadata of the last model response. */
|
|
132
|
-
usage?: Record<string, unknown>;
|
|
133
|
-
};
|
|
89
|
+
/** What `askWithFiles` returns. `usage` is summed over the whole question; Gemini's own `usageMetadata` of the last response is `lastUsage`. */
|
|
90
|
+
export type AskGeminiResult = AskResult;
|
|
134
91
|
/**
|
|
135
|
-
* Answers a chat turn about large documents with Gemini (Generate Content REST)
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* model writes the answer, in the tool-free turn.
|
|
92
|
+
* Answers a chat turn about large documents with Gemini (Generate Content REST): `askWithFiles`
|
|
93
|
+
* with a `gemini()` model for the endpoint, and a second one for its explorer model when it names
|
|
94
|
+
* one. Documents that fit go into the prompt whole; otherwise Gemini gets search and read tools
|
|
95
|
+
* and the tool loop runs, ending with a request without tools so there is always an answer.
|
|
140
96
|
*/
|
|
141
97
|
export declare function askGemini(options: AskGeminiOptions): Promise<AskGeminiResult>;
|
|
142
98
|
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/gemini/chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/gemini/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAA8B,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAE7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAC7H,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,UAAU,CAAC;IAClB;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AAE,MAAM,KAAK,IAAI,CAAC;IACpC,2FAA2F;IAC3F,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,gJAAgJ;AAChJ,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC;AAExC;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAiCnF"}
|
package/dist/gemini/chat.js
CHANGED
|
@@ -1,308 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { parseSseJson } from "./sse.js";
|
|
7
|
-
/** Sent (invisibly to the user) when the model must stop using tools and answer. */
|
|
8
|
-
export const FINAL_ANSWER_REQUEST = "Stop using tools now. Answer my question using only what the tools returned above, with line citations. Say plainly what you could not find.";
|
|
9
|
-
/** The same, when the only tool was `view_pages`: the text of the files is in the prompt, not in tool results. */
|
|
10
|
-
export const FINAL_ANSWER_AFTER_PAGES = "Stop using tools now. Answer my question from the text of the files and the pages you looked at. Say plainly what you could not see or find.";
|
|
11
|
-
/** Sent to the answering model when an explorer model used no tool, so there is no tool result to answer from. */
|
|
12
|
-
export const FINAL_ANSWER_WITHOUT_TOOLS = "Answer my question now, from what is in this conversation. No tools are available for this reply: if the answer needs a part of a file that is not shown here, say so plainly.";
|
|
1
|
+
import { askWithFiles } from "../ask.js";
|
|
2
|
+
import { fromGeminiContents, gemini } from "./adapter.js";
|
|
3
|
+
export { DocumentsNotFoundError } from "../model.js";
|
|
4
|
+
export { EXPLORER_INSTRUCTION, FINAL_ANSWER_AFTER_PAGES, FINAL_ANSWER_REQUEST, FINAL_ANSWER_WITHOUT_TOOLS } from "../ask.js";
|
|
5
|
+
export { GeminiRequestError } from "./errors.js";
|
|
13
6
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/** What Gemini bills for one PDF page it is shown (measured: 520 to 532). */
|
|
19
|
-
const PAGE_TOKENS = 530;
|
|
20
|
-
/** Some document IDs were never uploaded, have expired, or belong to another owner. */
|
|
21
|
-
export class DocumentsNotFoundError extends Error {
|
|
22
|
-
ids;
|
|
23
|
-
constructor(ids) {
|
|
24
|
-
super(`${ids.length === 1 ? "A document is" : `${ids.length} documents are`} no longer available: ${ids.join(", ")}. Upload ${ids.length === 1 ? "it" : "them"} again.`);
|
|
25
|
-
this.ids = ids;
|
|
26
|
-
this.name = "DocumentsNotFoundError";
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/** Gemini answered with an HTTP error. */
|
|
30
|
-
export class GeminiRequestError extends Error {
|
|
31
|
-
status;
|
|
32
|
-
constructor(message, status) {
|
|
33
|
-
super(message);
|
|
34
|
-
this.status = status;
|
|
35
|
-
this.name = "GeminiRequestError";
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function toContents(options) {
|
|
39
|
-
const contents = options.contents
|
|
40
|
-
? options.contents.map((content) => ({ role: content.role, parts: [...content.parts] }))
|
|
41
|
-
: (options.messages ?? []).map((turn) => ({ role: turn.role === "user" ? "user" : "model", parts: [{ text: turn.text }] }));
|
|
42
|
-
if (contents.at(-1)?.role !== "user")
|
|
43
|
-
throw new Error("The last message must be the user's.");
|
|
44
|
-
return contents;
|
|
45
|
-
}
|
|
46
|
-
function baseSize(contents, system) {
|
|
47
|
-
let tokens = estimateTokens(system ?? "") + 2_000;
|
|
48
|
-
let bytes = jsonBytes(system ?? "") + 8_000;
|
|
49
|
-
for (const content of contents) {
|
|
50
|
-
for (const part of content.parts) {
|
|
51
|
-
if (typeof part.text === "string") {
|
|
52
|
-
tokens += estimateTokens(part.text);
|
|
53
|
-
bytes += jsonBytes(part.text);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const size = JSON.stringify(part).length;
|
|
57
|
-
bytes += size;
|
|
58
|
-
// Media: Gemini bills about 258 tokens per image or PDF page; ~4 tokens/KB is a cautious stand-in.
|
|
59
|
-
tokens += Math.ceil(size / 256);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return { tokens, bytes };
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* A turn of an explorer model as the answering model gets it: the tool calls alone. A thought
|
|
67
|
-
* signature belongs to the model that wrote it, and the explorer's thoughts and remarks are not
|
|
68
|
-
* what the files say.
|
|
69
|
-
*/
|
|
70
|
-
function callsOnly(content) {
|
|
71
|
-
if (content.role !== "model")
|
|
72
|
-
return content;
|
|
73
|
-
return { role: "model", parts: content.parts.flatMap((part) => (part.functionCall ? [{ functionCall: part.functionCall }] : [])) };
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Answers a chat turn about large documents with Gemini (Generate Content REST).
|
|
77
|
-
* Documents that fit go into the prompt whole; otherwise Gemini gets search/read tools and this
|
|
78
|
-
* runs the tool loop, ending with a tool-free turn so there is always an answer.
|
|
79
|
-
* When the endpoint names an explorer model, that model runs the tool loop and the endpoint's own
|
|
80
|
-
* model writes the answer, in the tool-free turn.
|
|
7
|
+
* Answers a chat turn about large documents with Gemini (Generate Content REST): `askWithFiles`
|
|
8
|
+
* with a `gemini()` model for the endpoint, and a second one for its explorer model when it names
|
|
9
|
+
* one. Documents that fit go into the prompt whole; otherwise Gemini gets search and read tools
|
|
10
|
+
* and the tool loop runs, ending with a request without tools so there is always an answer.
|
|
81
11
|
*/
|
|
82
12
|
export async function askGemini(options) {
|
|
83
|
-
const
|
|
84
|
-
const { files, endpoint, signal } = options;
|
|
13
|
+
const { endpoint } = options;
|
|
85
14
|
// A second model for the requests that use tools. The answering model's own URL is not one.
|
|
86
15
|
const explorerUrl = endpoint.explorerUrl && endpoint.explorerUrl !== endpoint.url ? endpoint.explorerUrl : undefined;
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
text += delta;
|
|
116
|
-
options.onText?.(delta);
|
|
117
|
-
};
|
|
118
|
-
/**
|
|
119
|
-
* One model request. Text is emitted as it arrives; parts are kept as received.
|
|
120
|
-
* `wroteText` says whether this request produced any text of its own.
|
|
121
|
-
* Given `exploring`, the request is the explorer model's: that body goes to its URL, in one
|
|
122
|
-
* piece, and what it writes is not emitted, because the answer comes from the other model.
|
|
123
|
-
*/
|
|
124
|
-
const turn = async (exploring) => {
|
|
125
|
-
turns++;
|
|
126
|
-
const stream = streaming && !exploring;
|
|
127
|
-
const response = await fetchImpl(exploring ? explorerUrl : stream ? endpoint.streamUrl : endpoint.url, {
|
|
128
|
-
method: "POST",
|
|
129
|
-
headers,
|
|
130
|
-
body: JSON.stringify(exploring ?? body),
|
|
131
|
-
signal,
|
|
132
|
-
});
|
|
133
|
-
if (!response.ok) {
|
|
134
|
-
const data = await response.json().catch(() => null);
|
|
135
|
-
throw new GeminiRequestError(data?.error?.message ?? `Gemini returned HTTP ${response.status}.`, response.status);
|
|
136
|
-
}
|
|
137
|
-
const parts = [];
|
|
138
|
-
const calls = [];
|
|
139
|
-
let separated = text.length === 0;
|
|
140
|
-
let wroteText = false;
|
|
141
|
-
const take = (chunk) => {
|
|
142
|
-
if (chunk.error?.message)
|
|
143
|
-
throw new GeminiRequestError(chunk.error.message, response.status);
|
|
144
|
-
if (chunk.promptFeedback?.blockReason)
|
|
145
|
-
blockReason = chunk.promptFeedback.blockReason;
|
|
146
|
-
const candidate = chunk.candidates?.[0];
|
|
147
|
-
for (const part of candidate?.content?.parts ?? []) {
|
|
148
|
-
// Keep every part unchanged: Gemini 3 requires its thought signatures back.
|
|
149
|
-
parts.push(part);
|
|
150
|
-
if (typeof part.text === "string" && part.text && part.thought !== true) {
|
|
151
|
-
if (!exploring) {
|
|
152
|
-
if (!separated) {
|
|
153
|
-
emit("\n\n");
|
|
154
|
-
separated = true;
|
|
155
|
-
}
|
|
156
|
-
emit(part.text);
|
|
157
|
-
}
|
|
158
|
-
if (part.text.trim())
|
|
159
|
-
wroteText = true;
|
|
160
|
-
}
|
|
161
|
-
const call = part.functionCall;
|
|
162
|
-
if (call && typeof call.name === "string") {
|
|
163
|
-
const args = call.args && typeof call.args === "object" && !Array.isArray(call.args) ? call.args : {};
|
|
164
|
-
calls.push({ name: call.name, args, ...(typeof call.id === "string" ? { id: call.id } : {}) });
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
finishReason = candidate?.finishReason ?? finishReason;
|
|
168
|
-
usage = chunk.usageMetadata ?? usage;
|
|
169
|
-
};
|
|
170
|
-
if (stream) {
|
|
171
|
-
if (!response.body)
|
|
172
|
-
throw new GeminiRequestError("Gemini returned an empty stream.", response.status);
|
|
173
|
-
for await (const chunk of parseSseJson(response.body))
|
|
174
|
-
take(chunk);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
take(await response.json());
|
|
178
|
-
}
|
|
179
|
-
return { parts, calls, wroteText };
|
|
180
|
-
};
|
|
181
|
-
const result = (answered) => ({
|
|
182
|
-
text,
|
|
183
|
-
answered,
|
|
184
|
-
...(blockReason ? { blockReason } : {}),
|
|
185
|
-
steps,
|
|
186
|
-
plan: prepared.plan,
|
|
187
|
-
turns,
|
|
188
|
-
...(finishReason ? { finishReason } : {}),
|
|
189
|
-
...(usage ? { usage } : {}),
|
|
16
|
+
const shared = { toolFilePlacement: options.toolFilePlacement, analysisConfig: options.analysisConfig, fetch: options.fetch };
|
|
17
|
+
const model = gemini(endpoint, { ...shared, generationConfig: options.generationConfig });
|
|
18
|
+
// The explorer is called with the same headers, in one piece, with its own settings when it has any.
|
|
19
|
+
const explorer = explorerUrl
|
|
20
|
+
? gemini({ url: explorerUrl, headers: endpoint.headers }, { ...shared, generationConfig: options.explorerGenerationConfig ?? options.generationConfig })
|
|
21
|
+
: undefined;
|
|
22
|
+
return askWithFiles({
|
|
23
|
+
files: options.files,
|
|
24
|
+
model,
|
|
25
|
+
explorer,
|
|
26
|
+
documentIds: options.documentIds,
|
|
27
|
+
...(options.documentPlacement ? { documentPlacement: options.documentPlacement } : {}),
|
|
28
|
+
messages: options.contents ? fromGeminiContents(options.contents) : options.messages ?? [],
|
|
29
|
+
...(options.system !== undefined ? { system: options.system } : {}),
|
|
30
|
+
...(options.owner !== undefined ? { owner: options.owner } : {}),
|
|
31
|
+
limits: {
|
|
32
|
+
...(options.maxToolTurns !== undefined ? { toolTurns: options.maxToolTurns } : {}),
|
|
33
|
+
...(options.maxToolCallsPerTurn !== undefined ? { callsPerTurn: options.maxToolCallsPerTurn } : {}),
|
|
34
|
+
...options.limits,
|
|
35
|
+
},
|
|
36
|
+
...(options.retry ? { retry: options.retry } : {}),
|
|
37
|
+
...(options.budget ? { budget: options.budget } : {}),
|
|
38
|
+
...(options.wholeDocumentAnalysis !== undefined ? { wholeDocumentAnalysis: options.wholeDocumentAnalysis } : {}),
|
|
39
|
+
...(options.viewPages !== undefined ? { viewPages: options.viewPages } : {}),
|
|
40
|
+
...(options.onText ? { onText: options.onText } : {}),
|
|
41
|
+
...(options.onActivity ? { onActivity: options.onActivity } : {}),
|
|
42
|
+
...(options.onStep ? { onStep: options.onStep } : {}),
|
|
43
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
190
44
|
});
|
|
191
|
-
// Tools are needed for a file that is too large to send whole, and for a PDF whose pages can be
|
|
192
|
-
// looked at: that one may have its whole text in the prompt and still hide a chart from the model.
|
|
193
|
-
const { searchable } = prepared.plan;
|
|
194
|
-
const { viewable } = prepared;
|
|
195
|
-
if (searchable.length === 0 && viewable.length === 0)
|
|
196
|
-
return result((await turn()).wroteText);
|
|
197
|
-
const tools = files.tools(searchable, {
|
|
198
|
-
...(options.wholeDocumentAnalysis === false ? {} : {
|
|
199
|
-
// Reading a whole file in parts is exploring too: the explorer model's work, when there is one.
|
|
200
|
-
generate: createGeminiGenerateText({ url: explorerUrl ?? endpoint.url, headers, fetchImpl, ...(options.analysisConfig ? { generationConfig: options.analysisConfig } : {}) }),
|
|
201
|
-
}),
|
|
202
|
-
onProgress: (event) => options.onActivity?.(`${event.message}…`),
|
|
203
|
-
...(signal ? { signal } : {}),
|
|
204
|
-
...(viewable.length > 0 ? { viewPages: viewable } : {}),
|
|
205
|
-
});
|
|
206
|
-
// The request that uses the tools is the chat's own, or one for the explorer model: the same
|
|
207
|
-
// conversation (`contents` is one array, so it grows in both), that model's settings, and a
|
|
208
|
-
// line that says what its part is.
|
|
209
|
-
const explorerConfig = options.explorerGenerationConfig ?? options.generationConfig;
|
|
210
|
-
const exploring = explorerUrl ? {
|
|
211
|
-
contents,
|
|
212
|
-
systemInstruction: { parts: [{ text: `${system}\n\n${EXPLORER_INSTRUCTION}` }] },
|
|
213
|
-
...(explorerConfig ? { generationConfig: explorerConfig } : {}),
|
|
214
|
-
} : undefined;
|
|
215
|
-
const withTools = exploring ?? body;
|
|
216
|
-
withTools.tools = [{ functionDeclarations: tools.declarations }];
|
|
217
|
-
withTools.toolConfig = { functionCallingConfig: { mode: "AUTO" } };
|
|
218
|
-
// How many turns the conversation had as it was asked. What follows them is the tool loop's.
|
|
219
|
-
const asked = contents.length;
|
|
220
|
-
if (searchable.length > 0)
|
|
221
|
-
options.onActivity?.(`Too large to read at once: ${searchable.map((meta) => meta.name).join(", ")}. Searching instead…`);
|
|
222
|
-
// Pages the model looks at stay in the request until the question is answered, so they are
|
|
223
|
-
// counted twice: as bytes against the request limit, and as tokens against half of what the
|
|
224
|
-
// budget keeps free for tool results and the answer.
|
|
225
|
-
const { maxRequestBytes, reservedTokens } = files.budget;
|
|
226
|
-
const bytesKeptFree = Math.max(REQUEST_BYTES_MARGIN, Math.floor(maxRequestBytes / 10));
|
|
227
|
-
let pagesLeft = Math.floor(reservedTokens / 2 / PAGE_TOKENS);
|
|
228
|
-
const maxTurns = Math.max(1, options.maxToolTurns ?? 12);
|
|
229
|
-
const maxCalls = Math.max(1, Math.trunc(options.maxToolCallsPerTurn ?? 8));
|
|
230
|
-
let answered = false;
|
|
231
|
-
// Tools run in at most maxTurns - 1 requests. The last request is the tool-free one below, so a
|
|
232
|
-
// model that never stops calling tools does not cost a request whose calls are thrown away.
|
|
233
|
-
for (let round = 1; round < maxTurns; round++) {
|
|
234
|
-
const { parts, calls, wroteText } = await turn(exploring);
|
|
235
|
-
if (calls.length === 0) {
|
|
236
|
-
// Text from this turn is the answer. A remark made earlier, before a tool call, is not.
|
|
237
|
-
// Neither is anything an explorer model writes: the answer is asked for below.
|
|
238
|
-
answered = wroteText && !exploring;
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
body.contents.push({ role: "model", parts });
|
|
242
|
-
const responses = [];
|
|
243
|
-
// The size of the request as it stands, worked out when the first look at pages in this turn needs it.
|
|
244
|
-
let requestBytes;
|
|
245
|
-
for (const [index, call] of calls.entries()) {
|
|
246
|
-
// Every call must be answered, but not every call is run: a turn of sixty reads would build
|
|
247
|
-
// a request that no model accepts, and a file can ask a model for exactly that.
|
|
248
|
-
if (index >= maxCalls) {
|
|
249
|
-
responses.push({
|
|
250
|
-
call,
|
|
251
|
-
result: { error: `Not run: one turn runs at most ${maxCalls} tool calls. Send this call again if you still need it.`, tool_turns_left: maxTurns - round - 1 },
|
|
252
|
-
files: [],
|
|
253
|
-
});
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
const label = tools.has(call.name) ? tools.describe(call.name, call.args) : call.name;
|
|
257
|
-
options.onActivity?.(`${label}…`);
|
|
258
|
-
let limits;
|
|
259
|
-
if (call.name === TOOL_NAMES.view) {
|
|
260
|
-
requestBytes ??= Buffer.byteLength(JSON.stringify(withTools));
|
|
261
|
-
// Base64 turns three bytes into four characters.
|
|
262
|
-
limits = { maxFileBytes: Math.floor((maxRequestBytes - bytesKeptFree - requestBytes) * 3 / 4), maxPages: pagesLeft };
|
|
263
|
-
}
|
|
264
|
-
const output = await tools.executeWithFiles(call.name, call.args, limits);
|
|
265
|
-
for (const file of output.files)
|
|
266
|
-
requestBytes = (requestBytes ?? 0) + Math.ceil(file.bytes.length / 3) * 4 + 512;
|
|
267
|
-
if (output.files.length > 0)
|
|
268
|
-
pagesLeft -= pagesShown(output.result);
|
|
269
|
-
const step = `${label}${toolResultSummary(label, output.result)}`;
|
|
270
|
-
steps.push(step);
|
|
271
|
-
options.onStep?.(step);
|
|
272
|
-
responses.push({ call, result: { ...output.result, tool_turns_left: maxTurns - round - 1 }, files: output.files });
|
|
273
|
-
}
|
|
274
|
-
if (calls.length > maxCalls) {
|
|
275
|
-
const step = `${calls.length - maxCalls} more tool calls in this turn were not run (at most ${maxCalls} a turn)`;
|
|
276
|
-
steps.push(step);
|
|
277
|
-
options.onStep?.(step);
|
|
278
|
-
}
|
|
279
|
-
body.contents.push(...geminiFunctionResponseTurns(responses, { files: options.toolFilePlacement ?? "inside" }));
|
|
280
|
-
}
|
|
281
|
-
// Out of tool turns, or the last turn had no text (cut off, or a malformed tool call): ask once
|
|
282
|
-
// more with no tools declared at all. (Gemini can ignore functionCallingConfig mode NONE and
|
|
283
|
-
// keep calling tools.) A blocked prompt would only be blocked again.
|
|
284
|
-
// With an explorer model this request is always made: it is the one the answering model gets.
|
|
285
|
-
if (!answered && !blockReason) {
|
|
286
|
-
options.onActivity?.("Writing the answer…");
|
|
287
|
-
delete body.tools;
|
|
288
|
-
delete body.toolConfig;
|
|
289
|
-
let request = searchable.length > 0 ? FINAL_ANSWER_REQUEST : FINAL_ANSWER_AFTER_PAGES;
|
|
290
|
-
if (exploring) {
|
|
291
|
-
// The answering model gets the explorer's calls and what they returned, and nothing else of
|
|
292
|
-
// it. This request ends with a user message, as it must: a Gemini 3 model refuses a
|
|
293
|
-
// function call without its own thought signature in the turn it is still answering.
|
|
294
|
-
body.contents = [...contents.slice(0, asked), ...contents.slice(asked).map(callsOnly)];
|
|
295
|
-
if (steps.length === 0)
|
|
296
|
-
request = FINAL_ANSWER_WITHOUT_TOOLS;
|
|
297
|
-
}
|
|
298
|
-
body.contents.push({ role: "user", parts: [{ text: request }] });
|
|
299
|
-
answered = (await turn()).wroteText;
|
|
300
|
-
}
|
|
301
|
-
return result(answered);
|
|
302
|
-
}
|
|
303
|
-
/** How many pages a `view_pages` result showed: its `pages` is "12" or "12-14". */
|
|
304
|
-
function pagesShown(result) {
|
|
305
|
-
const [first, last] = String(result.pages ?? "").split("-").map(Number);
|
|
306
|
-
return Number.isFinite(first) ? (Number.isFinite(last) ? last - first + 1 : 1) : 0;
|
|
307
45
|
}
|
|
308
46
|
//# sourceMappingURL=chat.js.map
|
package/dist/gemini/chat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/gemini/chat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAuB,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,2BAA2B,EAAyD,MAAM,eAAe,CAAC;AAC7I,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAOxC,oFAAoF;AACpF,MAAM,CAAC,MAAM,oBAAoB,GAAG,8IAA8I,CAAC;AACnL,kHAAkH;AAClH,MAAM,CAAC,MAAM,wBAAwB,GAAG,8IAA8I,CAAC;AACvL,kH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CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModelRequestError } from "../model.js";
|
|
2
|
+
/** Gemini answered with an HTTP error, or could not be reached (`status` 0). */
|
|
3
|
+
export declare class GeminiRequestError extends ModelRequestError {
|
|
4
|
+
constructor(message: string, status: number, options?: {
|
|
5
|
+
retryAfterMs?: number;
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
/** What to say of a request that never got an answer: the reason, without the stack of the HTTP client. */
|
|
10
|
+
export declare function unreachable(error: unknown): GeminiRequestError;
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/gemini/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,gFAAgF;AAChF,qBAAa,kBAAmB,SAAQ,iBAAiB;gBAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;CAItG;AAED,2GAA2G;AAC3G,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,CAG9D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ModelRequestError } from "../model.js";
|
|
2
|
+
/** Gemini answered with an HTTP error, or could not be reached (`status` 0). */
|
|
3
|
+
export class GeminiRequestError extends ModelRequestError {
|
|
4
|
+
constructor(message, status, options = {}) {
|
|
5
|
+
super(message, status, options);
|
|
6
|
+
this.name = "GeminiRequestError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** What to say of a request that never got an answer: the reason, without the stack of the HTTP client. */
|
|
10
|
+
export function unreachable(error) {
|
|
11
|
+
const reason = error instanceof Error && error.message ? ` (${error.message})` : "";
|
|
12
|
+
return new GeminiRequestError(`Gemini could not be reached${reason}.`, 0, { cause: error });
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/gemini/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,gFAAgF;AAChF,MAAM,OAAO,kBAAmB,SAAQ,iBAAiB;IACvD,YAAY,OAAe,EAAE,MAAc,EAAE,UAAsD,EAAE;QACnG,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED,2GAA2G;AAC3G,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACpF,OAAO,IAAI,kBAAkB,CAAC,8BAA8B,MAAM,GAAG,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAC9F,CAAC"}
|