@metreeca/llms-google 0.0.0-stage → 0.3.1
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/LICENSE +201 -0
- package/README.md +38 -2
- package/dist/index.d.ts +119 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +485 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @metreeca/llms-google
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@metreeca/llms-google)
|
|
4
|
+
|
|
5
|
+
Google model connectors for [@metreeca/llms](https://github.com/metreeca/llms).
|
|
6
|
+
|
|
7
|
+
Connects AI jobs to Google models, ready to work alongside any other task in a pipeline. Long runs proceed reliably to
|
|
8
|
+
completion, and every result a job receives from a model can be trusted as complete.
|
|
9
|
+
|
|
10
|
+
# Installation
|
|
11
|
+
|
|
12
|
+
```shell
|
|
13
|
+
npm install @metreeca/gear # the job executor
|
|
14
|
+
npm install @metreeca/llms # AI tasks and shared services
|
|
15
|
+
npm install @metreeca/llms-google # this package
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
> [!IMPORTANT]
|
|
19
|
+
>
|
|
20
|
+
> Node.js 22 or later is required.
|
|
21
|
+
|
|
22
|
+
> [!WARNING]
|
|
23
|
+
>
|
|
24
|
+
> TypeScript consumers must use `"moduleResolution": "nodenext"/"node16"/"bundler"` in `tsconfig.json`.
|
|
25
|
+
> The legacy `"node"` resolver is not supported.
|
|
26
|
+
|
|
27
|
+
# Usage
|
|
28
|
+
|
|
29
|
+
See the [API reference](https://metreeca.github.io/llms/modules/_metreeca_llms-google.html).
|
|
30
|
+
|
|
31
|
+
# Support
|
|
32
|
+
|
|
33
|
+
- open an [issue](https://github.com/metreeca/llms/issues) to report a problem or to suggest a new feature
|
|
34
|
+
- start a [discussion](https://github.com/metreeca/llms/discussions) to ask a how-to question or to share an idea
|
|
35
|
+
|
|
36
|
+
# License
|
|
37
|
+
|
|
38
|
+
This project is licensed under the Apache 2.0 License –
|
|
39
|
+
see [LICENSE](https://github.com/metreeca/llms?tab=Apache-2.0-1-ov-file) file for details.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google model connectors.
|
|
3
|
+
*
|
|
4
|
+
* Connects AI jobs to Google models, ready to work alongside any other task in a pipeline. Long runs proceed reliably
|
|
5
|
+
* to completion, and every result a job receives from a model can be trusted as complete.
|
|
6
|
+
*
|
|
7
|
+
* @module index
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://ai.google.dev/gemini-api/docs Gemini API documentation}
|
|
10
|
+
* @see {@link https://googleapis.github.io/js-genai/release_docs/index.html Google GenAI SDK}
|
|
11
|
+
*/
|
|
12
|
+
import type { Vector } from "@metreeca/llms";
|
|
13
|
+
import { Content, EmbedContentResponse, GenerateContentResponse, GoogleGenAI, GoogleGenAIOptions } from "@google/genai";
|
|
14
|
+
import { type Value } from "@metreeca/core";
|
|
15
|
+
/**
|
|
16
|
+
* Creates a Gemini API client that works around known API limitations.
|
|
17
|
+
*
|
|
18
|
+
* The client exposes the full {@link GoogleGenAI} surface. Model methods issuing requests are paced against the
|
|
19
|
+
* published rate quotas, and content generation honours a requested response schema on every model, even when
|
|
20
|
+
* function calling is involved and the model itself rejects a schema alongside tools.
|
|
21
|
+
*
|
|
22
|
+
* @param options The client options, as accepted by the {@link GoogleGenAI} constructor; if omitted, the SDK defaults
|
|
23
|
+
* apply, reading the API key for the Gemini API from the environment. Vertex AI is reached instead by
|
|
24
|
+
* setting `vertexai`, `project` and `location`, with Google Cloud project credentials. Unless
|
|
25
|
+
* `httpOptions.retryOptions` is set, a request failing transiently is attempted up to 5 times in total
|
|
26
|
+
*
|
|
27
|
+
* @returns A client sharing throttling, logging and structured output support among requests to the same model;
|
|
28
|
+
* models are told apart by their exact id, so the bare and `models/`-prefixed forms of an id are paced
|
|
29
|
+
* separately, even though both draw on the same project quota and may overrun it together
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
*
|
|
33
|
+
* A client is meant to be configured once by the consumer binding it, so that credentials and endpoint are settled for
|
|
34
|
+
* a whole execution rather than repeated by each job that draws on the same models.
|
|
35
|
+
*
|
|
36
|
+
* The client takes over three concerns the API and the SDK leave to the caller:
|
|
37
|
+
*
|
|
38
|
+
* - **Quota control**: every request is paced against a per-model adaptive throttle. A request rejected over the rate
|
|
39
|
+
* quota is resumed after the `RetryInfo` delay the API advertises, so a long run keeps within the quota instead of
|
|
40
|
+
* failing on 429 errors. Other transient failures, such as an overloaded model, are retried as stated by `options`,
|
|
41
|
+
* so a run survives a spike in demand on the model rather than aborting on the first one.
|
|
42
|
+
*
|
|
43
|
+
* - **Function calling**: when a request declares `tools`, the client resolves function calls itself, issuing one
|
|
44
|
+
* throttled request per turn. Turns are unlimited unless `automaticFunctionCalling.maximumRemoteCalls` bounds them,
|
|
45
|
+
* and only `CallableTool` tools are invoked. A request disabling automatic function calling is submitted once, and
|
|
46
|
+
* its function calls are returned to the caller. The request fails with an {@link !Error Error} if a response
|
|
47
|
+
* carries no model content, if the model calls a function while no callable tool is declared, or if the turn limit
|
|
48
|
+
* runs out before a final response; in every case the error carries no partial conversation.
|
|
49
|
+
*
|
|
50
|
+
* - **Structured output**: a requested response schema is honoured on every model. The API accepts a response schema
|
|
51
|
+
* alongside `tools` only from the Gemini 3 generation onwards. Earlier models reply in prose, and an extra request
|
|
52
|
+
* to `gemini-2.5-flash-lite` converts the reply into JSON conforming to the schema, at the cost of one additional
|
|
53
|
+
* generation. A model rejecting the schema is switched to the conversion route for the lifetime of the client.
|
|
54
|
+
*
|
|
55
|
+
* @see {@link https://ai.google.dev/gemini-api/docs/function-calling Function calling}
|
|
56
|
+
* @see {@link https://ai.google.dev/gemini-api/docs/structured-output Structured output}
|
|
57
|
+
* @see {@link https://ai.google.dev/gemini-api/docs/rate-limits Rate limits}
|
|
58
|
+
* @see {@link https://github.com/googleapis/js-genai/issues/727 js-genai#727}
|
|
59
|
+
*/
|
|
60
|
+
export declare function createGoogleAI(options?: GoogleGenAIOptions): GoogleGenAI & {
|
|
61
|
+
models: import("@google/genai").Models & {
|
|
62
|
+
generateContent: (params: import("@google/genai").GenerateContentParameters) => Promise<GenerateContentResponse | {
|
|
63
|
+
candidates: import("@google/genai").Candidate[] | undefined;
|
|
64
|
+
sdkHttpResponse?: import("@google/genai").HttpResponse;
|
|
65
|
+
createTime?: string;
|
|
66
|
+
automaticFunctionCallingHistory?: Content[];
|
|
67
|
+
modelVersion?: string;
|
|
68
|
+
promptFeedback?: import("@google/genai").GenerateContentResponsePromptFeedback;
|
|
69
|
+
responseId?: string;
|
|
70
|
+
usageMetadata?: import("@google/genai").GenerateContentResponseUsageMetadata;
|
|
71
|
+
modelStatus?: import("@google/genai").ModelStatus;
|
|
72
|
+
}>;
|
|
73
|
+
generateContentStream: (params: import("@google/genai").GenerateContentParameters) => Promise<AsyncGenerator<GenerateContentResponse, any, any>>;
|
|
74
|
+
embedContent: (params: import("@google/genai").EmbedContentParameters) => Promise<EmbedContentResponse>;
|
|
75
|
+
countTokens: (params: import("@google/genai").CountTokensParameters) => Promise<import("@google/genai").CountTokensResponse>;
|
|
76
|
+
computeTokens: (params: import("@google/genai").ComputeTokensParameters) => Promise<import("@google/genai").ComputeTokensResponse>;
|
|
77
|
+
generateImages: (params: import("@google/genai").GenerateImagesParameters) => Promise<import("@google/genai").GenerateImagesResponse>;
|
|
78
|
+
generateVideos: (params: import("@google/genai").GenerateVideosParameters) => Promise<import("@google/genai").GenerateVideosOperation>;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Extracts the output text of a Gemini API response.
|
|
83
|
+
*
|
|
84
|
+
* Thinking parts and function calls are skipped, so only the text generated for the caller is returned. A response
|
|
85
|
+
* without output text is rejected as an empty generation. The error names the finish reason, so a generation the model
|
|
86
|
+
* withheld, for instance for `RECITATION`, can be told apart from a malformed payload.
|
|
87
|
+
*
|
|
88
|
+
* @param response The response of a `generateContent` request
|
|
89
|
+
*
|
|
90
|
+
* @returns The trimmed output text of `response`, joining the text of multiple parts with blank lines
|
|
91
|
+
*
|
|
92
|
+
* @throws {@link !Error Error} If `response` carries no output text, naming the finish reason of the response
|
|
93
|
+
*/
|
|
94
|
+
export declare function text(response: GenerateContentResponse): string;
|
|
95
|
+
/**
|
|
96
|
+
* Extracts the output text of a Gemini API response as a JSON payload.
|
|
97
|
+
*
|
|
98
|
+
* The payload is parsed from the output text produced under the requested response schema, and typed as `T` without
|
|
99
|
+
* further validation: callers needing guarantees on its shape must validate it themselves.
|
|
100
|
+
*
|
|
101
|
+
* @typeParam T The expected shape of the JSON payload
|
|
102
|
+
*
|
|
103
|
+
* @param response The response of a `generateContent` request carrying a response schema
|
|
104
|
+
*
|
|
105
|
+
* @returns The JSON payload parsed from the output text of `response`
|
|
106
|
+
*
|
|
107
|
+
* @throws {@link !Error Error} If `response` carries no output text (see {@link text}), or if its text is not
|
|
108
|
+
* well-formed JSON, for instance because the reply was cut short by an exhausted output budget
|
|
109
|
+
*/
|
|
110
|
+
export declare function json<T extends Value = Value>(response: GenerateContentResponse): T;
|
|
111
|
+
/**
|
|
112
|
+
* Extracts the embedding of a Gemini API response.
|
|
113
|
+
*
|
|
114
|
+
* @param response The response of an `embedContent` request
|
|
115
|
+
*
|
|
116
|
+
* @returns The {@link Vector} embedded for the first content of `response`, or an empty array if it carries none
|
|
117
|
+
*/
|
|
118
|
+
export declare function embedding(response: EmbedContentResponse): Vector;
|
|
119
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAGN,OAAO,EAEP,oBAAoB,EACpB,uBAAuB,EACvB,WAAW,EACX,kBAAkB,EAElB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAgBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,kBAAuB;;;;;;;;;;;;;;;;;;;;EAqf9D;AAKD;;;;;;;;;;;;GAYG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,CAS9D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EAAE,QAAQ,EAAE,uBAAuB,GAAG,CAAC,CAclF;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAIhE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { ApiError, GoogleGenAI } from "@google/genai";
|
|
17
|
+
import { error, isString, memo } from "@metreeca/core";
|
|
18
|
+
import { createThrottle } from "@metreeca/core/async";
|
|
19
|
+
import { markdown } from "@metreeca/core/strings";
|
|
20
|
+
import { BadRequest, TooManyRequests } from "@metreeca/http";
|
|
21
|
+
import { log, report } from "@metreeca/tape";
|
|
22
|
+
/**
|
|
23
|
+
* The number of attempts a request is submitted for, the initial one included, before a transient rejection is handed
|
|
24
|
+
* over to the throttle (see {@link createGoogleAI}).
|
|
25
|
+
*/
|
|
26
|
+
const attempts = 5;
|
|
27
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
28
|
+
/**
|
|
29
|
+
* Creates a Gemini API client that works around known API limitations.
|
|
30
|
+
*
|
|
31
|
+
* The client exposes the full {@link GoogleGenAI} surface. Model methods issuing requests are paced against the
|
|
32
|
+
* published rate quotas, and content generation honours a requested response schema on every model, even when
|
|
33
|
+
* function calling is involved and the model itself rejects a schema alongside tools.
|
|
34
|
+
*
|
|
35
|
+
* @param options The client options, as accepted by the {@link GoogleGenAI} constructor; if omitted, the SDK defaults
|
|
36
|
+
* apply, reading the API key for the Gemini API from the environment. Vertex AI is reached instead by
|
|
37
|
+
* setting `vertexai`, `project` and `location`, with Google Cloud project credentials. Unless
|
|
38
|
+
* `httpOptions.retryOptions` is set, a request failing transiently is attempted up to 5 times in total
|
|
39
|
+
*
|
|
40
|
+
* @returns A client sharing throttling, logging and structured output support among requests to the same model;
|
|
41
|
+
* models are told apart by their exact id, so the bare and `models/`-prefixed forms of an id are paced
|
|
42
|
+
* separately, even though both draw on the same project quota and may overrun it together
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
*
|
|
46
|
+
* A client is meant to be configured once by the consumer binding it, so that credentials and endpoint are settled for
|
|
47
|
+
* a whole execution rather than repeated by each job that draws on the same models.
|
|
48
|
+
*
|
|
49
|
+
* The client takes over three concerns the API and the SDK leave to the caller:
|
|
50
|
+
*
|
|
51
|
+
* - **Quota control**: every request is paced against a per-model adaptive throttle. A request rejected over the rate
|
|
52
|
+
* quota is resumed after the `RetryInfo` delay the API advertises, so a long run keeps within the quota instead of
|
|
53
|
+
* failing on 429 errors. Other transient failures, such as an overloaded model, are retried as stated by `options`,
|
|
54
|
+
* so a run survives a spike in demand on the model rather than aborting on the first one.
|
|
55
|
+
*
|
|
56
|
+
* - **Function calling**: when a request declares `tools`, the client resolves function calls itself, issuing one
|
|
57
|
+
* throttled request per turn. Turns are unlimited unless `automaticFunctionCalling.maximumRemoteCalls` bounds them,
|
|
58
|
+
* and only `CallableTool` tools are invoked. A request disabling automatic function calling is submitted once, and
|
|
59
|
+
* its function calls are returned to the caller. The request fails with an {@link !Error Error} if a response
|
|
60
|
+
* carries no model content, if the model calls a function while no callable tool is declared, or if the turn limit
|
|
61
|
+
* runs out before a final response; in every case the error carries no partial conversation.
|
|
62
|
+
*
|
|
63
|
+
* - **Structured output**: a requested response schema is honoured on every model. The API accepts a response schema
|
|
64
|
+
* alongside `tools` only from the Gemini 3 generation onwards. Earlier models reply in prose, and an extra request
|
|
65
|
+
* to `gemini-2.5-flash-lite` converts the reply into JSON conforming to the schema, at the cost of one additional
|
|
66
|
+
* generation. A model rejecting the schema is switched to the conversion route for the lifetime of the client.
|
|
67
|
+
*
|
|
68
|
+
* @see {@link https://ai.google.dev/gemini-api/docs/function-calling Function calling}
|
|
69
|
+
* @see {@link https://ai.google.dev/gemini-api/docs/structured-output Structured output}
|
|
70
|
+
* @see {@link https://ai.google.dev/gemini-api/docs/rate-limits Rate limits}
|
|
71
|
+
* @see {@link https://github.com/googleapis/js-genai/issues/727 js-genai#727}
|
|
72
|
+
*/
|
|
73
|
+
export function createGoogleAI(options = {}) {
|
|
74
|
+
const ai = new GoogleGenAI({
|
|
75
|
+
...options,
|
|
76
|
+
httpOptions: {
|
|
77
|
+
// the SDK retries a transient rejection only where retry options are stated, otherwise
|
|
78
|
+
// failing the request outright: a spike in demand on the model would abort a whole run
|
|
79
|
+
retryOptions: { attempts },
|
|
80
|
+
...options.httpOptions
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves the request channel shared by all requests to a model, opening it on first request.
|
|
85
|
+
*
|
|
86
|
+
* Channels are memoised by model id exactly as supplied, so the bare and `models/`-prefixed forms of the same
|
|
87
|
+
* model are throttled and logged independently, each under a category naming the model alone rather than this
|
|
88
|
+
* module, so that a run reads as a list of models rather than of repeated module paths. The `structured` flag
|
|
89
|
+
* records whether the model is currently expected to accept a response schema alongside tools: the Gemini API
|
|
90
|
+
* supports the combination from the Gemini 3 generation onwards, so the generation read from the `gemini-` segment
|
|
91
|
+
* of the id, whichever prefix it carries, seeds the flag, while a rejection clears it in place (see {@link retry}).
|
|
92
|
+
*
|
|
93
|
+
* @param model The target model name
|
|
94
|
+
*
|
|
95
|
+
* @returns The channel registered for `model`, retained for the lifetime of the client (see {@link memo})
|
|
96
|
+
*
|
|
97
|
+
* @see {@link https://ai.google.dev/gemini-api/docs/structured-output Structured output}
|
|
98
|
+
*/
|
|
99
|
+
const channels = memo(model => {
|
|
100
|
+
const generation = Number(model.match(/(?:^|\/)gemini-(\d+)/)?.[1] ?? 0);
|
|
101
|
+
return {
|
|
102
|
+
structured: generation >= 3,
|
|
103
|
+
logger: log(["/", model]),
|
|
104
|
+
// !!! the floor is a magic 600 rpm: derive it from the rpm published for the model, that is as
|
|
105
|
+
// !!! `60_000/rpm`, so that the pace is stated by the quota rather than guessed
|
|
106
|
+
// !!! a floor states requests per minute only: the token and daily quotas are not a function of
|
|
107
|
+
// !!! elapsed time and are left unguarded
|
|
108
|
+
// !!! quotas are enforced per project, while channels are opened per model: models running
|
|
109
|
+
// !!! concurrently overrun a shared quota, each pacing correctly on its own
|
|
110
|
+
throttle: createThrottle({
|
|
111
|
+
minimum: 100,
|
|
112
|
+
maximum: 60 * 1000,
|
|
113
|
+
buildup: 1.10,
|
|
114
|
+
backoff: 1.10,
|
|
115
|
+
recover: 0.95
|
|
116
|
+
})
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
return Object.assign(ai, {
|
|
120
|
+
models: Object.assign(ai.models, {
|
|
121
|
+
generateContent: (generateContent => {
|
|
122
|
+
return async (...[{ config, ...params }, ...rest]) => {
|
|
123
|
+
const channel = channels(params.model);
|
|
124
|
+
return config?.tools
|
|
125
|
+
? await structure(await execute())
|
|
126
|
+
: await submit(params.model, () => generateContent({ ...params, config }, ...rest));
|
|
127
|
+
/**
|
|
128
|
+
* Resolves a request carrying tools, driving function calling under quota throttling.
|
|
129
|
+
*
|
|
130
|
+
* The SDK resolves function calls through an internal loop that neither throttles its requests
|
|
131
|
+
* nor recovers from quota exhaustion, so long tool sessions fail with unexpected 429 errors:
|
|
132
|
+
* function declarations count towards the token limit, every turn issues a further request, and
|
|
133
|
+
* tools such as Browser MCP or Google Search resubmit massive contexts on each one of them, as
|
|
134
|
+
* reported for other SDKs:
|
|
135
|
+
*
|
|
136
|
+
* - googleapis/python-genai#17: 429 errors with the Google Search tool
|
|
137
|
+
* - google/adk-python#1057: 1.5M tokens in ~20 requests with Browser MCP, which sends the
|
|
138
|
+
* entire DOM as context
|
|
139
|
+
*
|
|
140
|
+
* Turns are driven by {@link afc} instead, one throttled request at a time (see {@link retry}),
|
|
141
|
+
* and a requested response schema is submitted with them wherever the model accepts it. Requests
|
|
142
|
+
* that disable automatic function calling take the same throttled route, but are submitted once
|
|
143
|
+
* and handed over as they come, function calls included.
|
|
144
|
+
*
|
|
145
|
+
* @returns The final response of the function calling loop, or the single response to a request
|
|
146
|
+
* that disables it
|
|
147
|
+
*
|
|
148
|
+
* @throws {@link !Error Error} If the function calling loop cannot be completed (see {@link afc})
|
|
149
|
+
*/
|
|
150
|
+
async function execute() {
|
|
151
|
+
const { tools, automaticFunctionCalling: { disable = false, maximumRemoteCalls = 0 } = {}, responseSchema, responseJsonSchema, responseMimeType, ...configWithoutSchema } = config ?? {};
|
|
152
|
+
if (disable) { // caller will handle function calling
|
|
153
|
+
return await retry(params.contents);
|
|
154
|
+
}
|
|
155
|
+
else { // automatic function calling loop with quota throttling
|
|
156
|
+
return await afc();
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Drives the function calling loop until the model returns a final response.
|
|
160
|
+
*
|
|
161
|
+
* Normalises the request contents into a conversation history, then alternates throttled
|
|
162
|
+
* model requests (see {@link retry}) with tool dispatch: the function calls requested by the
|
|
163
|
+
* model are submitted to every `CallableTool` declared in the request and the resulting
|
|
164
|
+
* parts are appended to the history for the next turn, until a response reports no call.
|
|
165
|
+
*
|
|
166
|
+
* @returns The final model response, with the conversation history attached as
|
|
167
|
+
* `automaticFunctionCallingHistory`
|
|
168
|
+
*
|
|
169
|
+
* @throws {@link !Error Error} If a response carries no model content, if a function is
|
|
170
|
+
* requested while no callable tool is declared, or if `maximumRemoteCalls` turns
|
|
171
|
+
* are exhausted without a final response
|
|
172
|
+
*/
|
|
173
|
+
async function afc() {
|
|
174
|
+
const callables = tools?.filter((tool) => typeof tool === "object" && tool !== null && "callTool" in tool
|
|
175
|
+
&& typeof tool.callTool === "function") ?? [];
|
|
176
|
+
const history = (Array.isArray(params.contents)
|
|
177
|
+
? params.contents
|
|
178
|
+
: [params.contents]).map(content => isString(content) ? { role: "user", parts: [{ text: content }] }
|
|
179
|
+
: "role" in content && "parts" in content ? content
|
|
180
|
+
: { role: "user", parts: [content] });
|
|
181
|
+
for (let turn = 0; maximumRemoteCalls === 0 || turn < maximumRemoteCalls; turn++) {
|
|
182
|
+
const response = await retry(history);
|
|
183
|
+
if (!response.candidates?.[0]?.content) {
|
|
184
|
+
throw new Error("no model content in response");
|
|
185
|
+
}
|
|
186
|
+
const calls = (response.candidates[0]?.content?.parts ?? [])
|
|
187
|
+
.map(part => part.functionCall)
|
|
188
|
+
.filter((call) => call !== undefined);
|
|
189
|
+
if (calls.length === 0) {
|
|
190
|
+
return Object.assign(response, {
|
|
191
|
+
automaticFunctionCallingHistory: history
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
if (callables.length === 0) {
|
|
196
|
+
throw new Error(`no callable tools available to fulfill model requests <${calls.map(call => call.name).join(", ")}>`);
|
|
197
|
+
}
|
|
198
|
+
history.push(response.candidates[0].content, {
|
|
199
|
+
role: "user",
|
|
200
|
+
parts: (await Promise.all(callables.map(tool => tool.callTool(calls)))).flat()
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
throw new Error(`maximum turns (${maximumRemoteCalls}) reached without completion`);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Submits a single model request under the throttle of the target model.
|
|
208
|
+
*
|
|
209
|
+
* Every request carrying tools is submitted here, with the SDK function calling loop always
|
|
210
|
+
* disabled, so each call performs exactly one request and turn management stays with
|
|
211
|
+
* {@link afc}. A requested response schema is submitted only to models expected to accept it
|
|
212
|
+
* alongside tools, leaving the conversion to {@link structure} on the others. A 429 rejection
|
|
213
|
+
* is retried after the delay advertised by the API; a 400 rejection received while a response
|
|
214
|
+
* schema is being submitted is taken as the model refusing it, closing the channel to schemas
|
|
215
|
+
* (see {@link channels}) and retrying the same request at once without one.
|
|
216
|
+
*
|
|
217
|
+
* @param contents The conversation to submit
|
|
218
|
+
*
|
|
219
|
+
* @returns The model response to `contents`
|
|
220
|
+
*
|
|
221
|
+
* @throws {ApiError} If the request fails for a reason the throttle cannot recover from
|
|
222
|
+
*/
|
|
223
|
+
async function retry(contents) {
|
|
224
|
+
return await submit(params.model, () => generateContent({
|
|
225
|
+
...params,
|
|
226
|
+
contents,
|
|
227
|
+
config: {
|
|
228
|
+
...configWithoutSchema,
|
|
229
|
+
tools,
|
|
230
|
+
// disable the SDK loop: it would resolve function calls without throttling,
|
|
231
|
+
// leaving this loop with nothing but the final response
|
|
232
|
+
automaticFunctionCalling: { disable: true },
|
|
233
|
+
// submit the response schema only to models accepting it alongside tools,
|
|
234
|
+
// leaving the conversion to `structure` on the others
|
|
235
|
+
...(channel.structured ? { responseMimeType, responseSchema, responseJsonSchema } : {})
|
|
236
|
+
}
|
|
237
|
+
}, ...rest), schema);
|
|
238
|
+
/**
|
|
239
|
+
* States the delay a request rejected over its response schema is to be retried after.
|
|
240
|
+
*
|
|
241
|
+
* @param error The rejection to recover from
|
|
242
|
+
*
|
|
243
|
+
* @returns 0, retrying at once without the schema, if `error` reports the model refusing
|
|
244
|
+
* it; undefined otherwise, leaving the rejection to the quota recovery of
|
|
245
|
+
* {@link submit}
|
|
246
|
+
*/
|
|
247
|
+
function schema(error) {
|
|
248
|
+
if (error instanceof ApiError && error.status === BadRequest && channel.structured) {
|
|
249
|
+
// the model doesn't accept a response schema alongside tools: close the channel to
|
|
250
|
+
// schemas and immediately retry the same request without one, leaving the
|
|
251
|
+
// conversion to `structure`
|
|
252
|
+
channel.structured = false;
|
|
253
|
+
channel.logger.warning `response schema rejected with tools: converting separately`;
|
|
254
|
+
return 0;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Converts a final textual response into the requested structured JSON.
|
|
264
|
+
*
|
|
265
|
+
* Models earlier than the Gemini 3 generation reject a `responseMimeType` of `"application/json"`
|
|
266
|
+
* alongside `tools`, so they are served without the response schema and reply in prose: a
|
|
267
|
+
* separate `gemini-2.5-flash-lite` request converts it into JSON conforming to the requested
|
|
268
|
+
* schema, at the cost of one extra generation. Models that accept the schema with the request
|
|
269
|
+
* produce the JSON themselves and bypass the conversion (see {@link channels}).
|
|
270
|
+
*
|
|
271
|
+
* @param response The model response to post-process
|
|
272
|
+
*
|
|
273
|
+
* @returns `response` with its candidates replaced by the converted JSON, or `response` as it
|
|
274
|
+
* stands if the model applied the schema itself, if no schema was requested, or if the
|
|
275
|
+
* response is still awaiting tool execution
|
|
276
|
+
*
|
|
277
|
+
* @throws {@link !Error Error} If the response to convert carries no text
|
|
278
|
+
*
|
|
279
|
+
* @see {@link https://github.com/googleapis/js-genai/issues/727 js-genai#727}
|
|
280
|
+
*/
|
|
281
|
+
async function structure(response) {
|
|
282
|
+
const { responseSchema, responseJsonSchema } = config ?? {};
|
|
283
|
+
const hasFunctionCalls = response.candidates?.[0]?.content?.parts?.some(part => part.functionCall);
|
|
284
|
+
if (channel.structured || !(responseSchema || responseJsonSchema) || hasFunctionCalls) {
|
|
285
|
+
return response;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
const input = text(response);
|
|
289
|
+
if (!input || !input.trim()) {
|
|
290
|
+
throw new Error("empty model response: unable to extract structured data");
|
|
291
|
+
}
|
|
292
|
+
const urls = [...new Set(input.match(/https?:\/\/[^\s\[\]()<>]+/g) || [])];
|
|
293
|
+
const converter = "gemini-2.5-flash-lite";
|
|
294
|
+
const data = await submit(converter, () => generateContent({
|
|
295
|
+
model: converter,
|
|
296
|
+
contents: [input, urls.length > 0
|
|
297
|
+
? markdown `REFERENCE URLs found in source (use EXACTLY as written):
|
|
298
|
+
${urls.map(url => `- ${url}`).join("\n")}
|
|
299
|
+
`
|
|
300
|
+
: "REFERENCE URLs found in source: (none identified)"
|
|
301
|
+
],
|
|
302
|
+
config: {
|
|
303
|
+
seed: 0,
|
|
304
|
+
temperature: 0,
|
|
305
|
+
systemInstruction: markdown `
|
|
306
|
+
|
|
307
|
+
# ROLE
|
|
308
|
+
|
|
309
|
+
You are a data engineer.
|
|
310
|
+
|
|
311
|
+
# INPUT
|
|
312
|
+
|
|
313
|
+
You will be provided with a textual report and a reference list of URLs
|
|
314
|
+
extracted from it.
|
|
315
|
+
|
|
316
|
+
# GOAL
|
|
317
|
+
|
|
318
|
+
Your task is to convert it into a structured machine-readable representation.
|
|
319
|
+
|
|
320
|
+
# OUTPUT
|
|
321
|
+
|
|
322
|
+
Reply with a structured JSON object; unless otherwise required by the
|
|
323
|
+
provided schema:
|
|
324
|
+
|
|
325
|
+
- ALWAYS omit undefined scalar values
|
|
326
|
+
- ALWAYS omit empty object values
|
|
327
|
+
- ALWAYS omit empty array values
|
|
328
|
+
- ALWAYS omit fields with value "Not defined" or similar placeholder text
|
|
329
|
+
- ALWAYS omit fields with error messages or system artifacts
|
|
330
|
+
|
|
331
|
+
# CRITICAL
|
|
332
|
+
|
|
333
|
+
When including URLs in the output:
|
|
334
|
+
|
|
335
|
+
- ALWAYS copy-paste them EXACTLY from the REFERENCE URLs list
|
|
336
|
+
- NEVER modify domain names (e.g., 'ec2u' must remain 'ec2u', NOT 'ec22')
|
|
337
|
+
- NEVER modify path components
|
|
338
|
+
|
|
339
|
+
`,
|
|
340
|
+
responseMimeType: "application/json",
|
|
341
|
+
responseSchema,
|
|
342
|
+
responseJsonSchema
|
|
343
|
+
}
|
|
344
|
+
}));
|
|
345
|
+
return {
|
|
346
|
+
...response,
|
|
347
|
+
candidates: data.candidates
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
})(ai.models.generateContent.bind(ai.models)),
|
|
353
|
+
generateContentStream: throttled(ai.models.generateContentStream.bind(ai.models)),
|
|
354
|
+
embedContent: throttled(ai.models.embedContent.bind(ai.models)),
|
|
355
|
+
countTokens: throttled(ai.models.countTokens.bind(ai.models)),
|
|
356
|
+
computeTokens: throttled(ai.models.computeTokens.bind(ai.models)),
|
|
357
|
+
generateImages: throttled(ai.models.generateImages.bind(ai.models)),
|
|
358
|
+
generateVideos: throttled(ai.models.generateVideos.bind(ai.models))
|
|
359
|
+
})
|
|
360
|
+
});
|
|
361
|
+
/**
|
|
362
|
+
* Submits a request under the throttle of the model it targets.
|
|
363
|
+
*
|
|
364
|
+
* Requests to the same model are paced against a shared adaptive throttle, so that concurrent consumers of a model
|
|
365
|
+
* keep within its published rate quota, and a rejection reporting a `RetryInfo` delay is retried after the delay
|
|
366
|
+
* the API advertises rather than at a pace of the client's own.
|
|
367
|
+
*
|
|
368
|
+
* @param model The target model name, keying the channel the request is paced against (see {@link channels})
|
|
369
|
+
* @param request The request to submit
|
|
370
|
+
* @param recover The recovery to attempt before the quota one, if any
|
|
371
|
+
*
|
|
372
|
+
* @returns The value `request` resolves to
|
|
373
|
+
*
|
|
374
|
+
* @throws {ApiError} If the request fails for a reason neither `recover` nor the quota recovery handles
|
|
375
|
+
*/
|
|
376
|
+
function submit(model, request, recover) {
|
|
377
|
+
const { throttle, logger: mlogger } = channels(model);
|
|
378
|
+
return throttle.retry(request, {
|
|
379
|
+
recover: error => recover?.(error) ?? quota(error),
|
|
380
|
+
monitor: (attempt, attempts, elapsed) => {
|
|
381
|
+
const count = attempts > 0 ? `${attempt + 1}/${attempts}` : `${attempt + 1}`;
|
|
382
|
+
if (elapsed === undefined) {
|
|
383
|
+
mlogger.error `request attempt ${count} aborted`;
|
|
384
|
+
}
|
|
385
|
+
else if (attempt > 0) {
|
|
386
|
+
mlogger.warning `request attempt ${count} rejected with delay ${elapsed} ms`;
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
mlogger.info `request attempt ${count} submitted with delay ${elapsed} ms`;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* States the delay a request rejected over the rate quota is to be retried after.
|
|
396
|
+
*
|
|
397
|
+
* @param error The rejection to recover from
|
|
398
|
+
*
|
|
399
|
+
* @returns The delay advertised by the API, in ms, if `error` reports an exhausted quota alongside a `RetryInfo`
|
|
400
|
+
* detail; undefined otherwise, leaving the rejection to the caller
|
|
401
|
+
*
|
|
402
|
+
* @see {@link https://ai.google.dev/gemini-api/docs/rate-limits Rate limits}
|
|
403
|
+
*/
|
|
404
|
+
function quota(error) {
|
|
405
|
+
if (error instanceof ApiError && error.status === TooManyRequests) {
|
|
406
|
+
const delay = error.error?.details
|
|
407
|
+
?.find(detail => `${detail["@type"]}`.includes("RetryInfo"))?.["retryDelay"];
|
|
408
|
+
const match = `${delay}`.match(/^(\d+(?:\.\d+)?)s$/);
|
|
409
|
+
return match ? Math.ceil(parseFloat(match[1]) * 1000) : undefined;
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Adapts a model method into one submitting its requests under the throttle of the model they target.
|
|
417
|
+
*
|
|
418
|
+
* @typeParam P The type of the request parameters, naming the target model
|
|
419
|
+
* @typeParam V The type of the value the method resolves to
|
|
420
|
+
*
|
|
421
|
+
* @param method The model method to adapt
|
|
422
|
+
*
|
|
423
|
+
* @returns A method submitting the requests of `method` through {@link submit}
|
|
424
|
+
*/
|
|
425
|
+
function throttled(method) {
|
|
426
|
+
return params => submit(params.model, () => method(params));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
430
|
+
/**
|
|
431
|
+
* Extracts the output text of a Gemini API response.
|
|
432
|
+
*
|
|
433
|
+
* Thinking parts and function calls are skipped, so only the text generated for the caller is returned. A response
|
|
434
|
+
* without output text is rejected as an empty generation. The error names the finish reason, so a generation the model
|
|
435
|
+
* withheld, for instance for `RECITATION`, can be told apart from a malformed payload.
|
|
436
|
+
*
|
|
437
|
+
* @param response The response of a `generateContent` request
|
|
438
|
+
*
|
|
439
|
+
* @returns The trimmed output text of `response`, joining the text of multiple parts with blank lines
|
|
440
|
+
*
|
|
441
|
+
* @throws {@link !Error Error} If `response` carries no output text, naming the finish reason of the response
|
|
442
|
+
*/
|
|
443
|
+
export function text(response) {
|
|
444
|
+
const candidate = response.candidates?.[0];
|
|
445
|
+
const parts = (candidate?.content?.parts ?? []).filter(part => part.text && !part.thought);
|
|
446
|
+
return parts.length > 0 ? parts
|
|
447
|
+
.map(part => part.text)
|
|
448
|
+
.join("\n\n")
|
|
449
|
+
.trim() : error(`empty generation <${candidate?.finishReason}>`);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Extracts the output text of a Gemini API response as a JSON payload.
|
|
453
|
+
*
|
|
454
|
+
* The payload is parsed from the output text produced under the requested response schema, and typed as `T` without
|
|
455
|
+
* further validation: callers needing guarantees on its shape must validate it themselves.
|
|
456
|
+
*
|
|
457
|
+
* @typeParam T The expected shape of the JSON payload
|
|
458
|
+
*
|
|
459
|
+
* @param response The response of a `generateContent` request carrying a response schema
|
|
460
|
+
*
|
|
461
|
+
* @returns The JSON payload parsed from the output text of `response`
|
|
462
|
+
*
|
|
463
|
+
* @throws {@link !Error Error} If `response` carries no output text (see {@link text}), or if its text is not
|
|
464
|
+
* well-formed JSON, for instance because the reply was cut short by an exhausted output budget
|
|
465
|
+
*/
|
|
466
|
+
export function json(response) {
|
|
467
|
+
const output = text(response);
|
|
468
|
+
try {
|
|
469
|
+
return JSON.parse(output);
|
|
470
|
+
}
|
|
471
|
+
catch (e) {
|
|
472
|
+
throw new Error(`malformed model response: ${report(e)}`);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Extracts the embedding of a Gemini API response.
|
|
477
|
+
*
|
|
478
|
+
* @param response The response of an `embedContent` request
|
|
479
|
+
*
|
|
480
|
+
* @returns The {@link Vector} embedded for the first content of `response`, or an empty array if it carries none
|
|
481
|
+
*/
|
|
482
|
+
export function embedding(response) {
|
|
483
|
+
return response.embeddings?.[0]?.values ?? [];
|
|
484
|
+
}
|
|
485
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAeH,OAAO,EACN,QAAQ,EAMR,WAAW,EAGX,MAAM,eAA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@metreeca/llms.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typescript",
|
|
7
|
+
"pipeline",
|
|
8
|
+
"ai",
|
|
9
|
+
"llm",
|
|
10
|
+
"gemini"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://metreeca.github.io/llms/",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/metreeca/llms/issues",
|
|
15
|
+
"email": "info@metreeca.com"
|
|
16
|
+
},
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Metreeca",
|
|
20
|
+
"email": "info@metreeca.com",
|
|
21
|
+
"url": "https://www.metreeca.com/"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/metreeca/llms.git",
|
|
26
|
+
"directory": "packages/llms-google"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"@metreeca/source": "./src/index.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE",
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22.22.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"clean": "rm dist docs node_modules",
|
|
46
|
+
"build": "rm dist && tsc -p tsconfig.build.json",
|
|
47
|
+
"check": "npx vitest --typecheck run"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@google/genai": "^2.28.0",
|
|
51
|
+
"@metreeca/core": "^0.13.0",
|
|
52
|
+
"@metreeca/http": "^0.5.0",
|
|
53
|
+
"@metreeca/llms": "^0.3.1",
|
|
54
|
+
"@metreeca/tape": "^0.12.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^25.9.3",
|
|
58
|
+
"typescript": "^5.9.3",
|
|
59
|
+
"vitest": "^4.0.13"
|
|
60
|
+
}
|
|
61
|
+
}
|