langchain 0.0.159 → 0.0.161

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.
Files changed (62) hide show
  1. package/dist/embeddings/bedrock.cjs +73 -0
  2. package/dist/embeddings/bedrock.d.ts +47 -0
  3. package/dist/embeddings/bedrock.js +69 -0
  4. package/dist/experimental/hubs/makersuite/googlemakersuitehub.cjs +297 -0
  5. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +183 -0
  6. package/dist/experimental/hubs/makersuite/googlemakersuitehub.js +291 -0
  7. package/dist/load/import_constants.cjs +2 -0
  8. package/dist/load/import_constants.js +2 -0
  9. package/dist/load/import_map.cjs +4 -1
  10. package/dist/load/import_map.d.ts +3 -0
  11. package/dist/load/import_map.js +3 -0
  12. package/dist/retrievers/chaindesk.cjs +71 -0
  13. package/dist/retrievers/chaindesk.d.ts +18 -0
  14. package/dist/retrievers/chaindesk.js +67 -0
  15. package/dist/retrievers/contextual_compression.cjs +2 -2
  16. package/dist/retrievers/contextual_compression.js +2 -2
  17. package/dist/retrievers/databerry.cjs +1 -0
  18. package/dist/retrievers/databerry.d.ts +1 -0
  19. package/dist/retrievers/databerry.js +1 -0
  20. package/dist/retrievers/document_compressors/embeddings_filter.cjs +78 -0
  21. package/dist/retrievers/document_compressors/embeddings_filter.d.ts +39 -0
  22. package/dist/retrievers/document_compressors/embeddings_filter.js +74 -0
  23. package/dist/retrievers/document_compressors/index.cjs +33 -1
  24. package/dist/retrievers/document_compressors/index.d.ts +14 -1
  25. package/dist/retrievers/document_compressors/index.js +31 -0
  26. package/dist/retrievers/document_compressors/test/document_compressor.int.test.cjs +28 -0
  27. package/dist/retrievers/document_compressors/test/document_compressor.int.test.d.ts +1 -0
  28. package/dist/retrievers/document_compressors/test/document_compressor.int.test.js +26 -0
  29. package/dist/retrievers/tavily_search_api.cjs +144 -0
  30. package/dist/retrievers/tavily_search_api.d.ts +38 -0
  31. package/dist/retrievers/tavily_search_api.js +140 -0
  32. package/dist/schema/runnable/base.cjs +3 -0
  33. package/dist/schema/runnable/base.d.ts +1 -0
  34. package/dist/schema/runnable/base.js +3 -0
  35. package/dist/text_splitter.cjs +22 -8
  36. package/dist/text_splitter.d.ts +1 -0
  37. package/dist/text_splitter.js +22 -8
  38. package/dist/types/googlevertexai-types.d.ts +7 -5
  39. package/dist/util/googlevertexai-connection.cjs +35 -27
  40. package/dist/util/googlevertexai-connection.d.ts +12 -8
  41. package/dist/util/googlevertexai-connection.js +33 -26
  42. package/dist/util/googlevertexai-webauth.d.ts +2 -2
  43. package/dist/vectorstores/googlevertexai.d.ts +4 -4
  44. package/dist/vectorstores/pinecone.cjs +21 -34
  45. package/dist/vectorstores/pinecone.d.ts +6 -9
  46. package/dist/vectorstores/pinecone.js +21 -34
  47. package/embeddings/bedrock.cjs +1 -0
  48. package/embeddings/bedrock.d.ts +1 -0
  49. package/embeddings/bedrock.js +1 -0
  50. package/experimental/hubs/makersuite/googlemakersuitehub.cjs +1 -0
  51. package/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -0
  52. package/experimental/hubs/makersuite/googlemakersuitehub.js +1 -0
  53. package/package.json +48 -3
  54. package/retrievers/chaindesk.cjs +1 -0
  55. package/retrievers/chaindesk.d.ts +1 -0
  56. package/retrievers/chaindesk.js +1 -0
  57. package/retrievers/document_compressors/embeddings_filter.cjs +1 -0
  58. package/retrievers/document_compressors/embeddings_filter.d.ts +1 -0
  59. package/retrievers/document_compressors/embeddings_filter.js +1 -0
  60. package/retrievers/tavily_search_api.cjs +1 -0
  61. package/retrievers/tavily_search_api.d.ts +1 -0
  62. package/retrievers/tavily_search_api.js +1 -0
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BedrockEmbeddings = void 0;
4
+ const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
5
+ const base_js_1 = require("./base.cjs");
6
+ /**
7
+ * Class that extends the Embeddings class and provides methods for
8
+ * generating embeddings using the Bedrock API.
9
+ */
10
+ class BedrockEmbeddings extends base_js_1.Embeddings {
11
+ constructor(fields) {
12
+ super(fields ?? {});
13
+ Object.defineProperty(this, "model", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: void 0
18
+ });
19
+ Object.defineProperty(this, "client", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+ this.model = fields?.model ?? "amazon.titan-embed-text-v1";
26
+ this.client =
27
+ fields?.client ??
28
+ new client_bedrock_runtime_1.BedrockRuntimeClient({
29
+ region: fields?.region,
30
+ credentials: fields?.credentials,
31
+ });
32
+ }
33
+ async _embedText(text) {
34
+ // replace newlines, which can negatively affect performance.
35
+ const cleanedText = text.replace(/\n/g, " ");
36
+ const res = await this.client.send(new client_bedrock_runtime_1.InvokeModelCommand({
37
+ modelId: this.model,
38
+ body: JSON.stringify({
39
+ inputText: cleanedText,
40
+ }),
41
+ contentType: "application/json",
42
+ accept: "application/json",
43
+ }));
44
+ try {
45
+ const body = new TextDecoder().decode(res.body);
46
+ return JSON.parse(body).embedding;
47
+ }
48
+ catch (e) {
49
+ throw new Error("An invalid response was returned by Bedrock.");
50
+ }
51
+ }
52
+ /**
53
+ * Method that takes a document as input and returns a promise that
54
+ * resolves to an embedding for the document. It calls the _embedText
55
+ * method with the document as the input.
56
+ * @param document Document for which to generate an embedding.
57
+ * @returns Promise that resolves to an embedding for the input document.
58
+ */
59
+ embedQuery(document) {
60
+ return this.caller.callWithOptions({}, this._embedText.bind(this), document);
61
+ }
62
+ /**
63
+ * Method that takes an array of documents as input and returns a promise
64
+ * that resolves to a 2D array of embeddings for each document. It calls
65
+ * the _embedText method for each document in the array.
66
+ * @param documents Array of documents for which to generate embeddings.
67
+ * @returns Promise that resolves to a 2D array of embeddings for each input document.
68
+ */
69
+ embedDocuments(documents) {
70
+ return Promise.all(documents.map((document) => this._embedText(document)));
71
+ }
72
+ }
73
+ exports.BedrockEmbeddings = BedrockEmbeddings;
@@ -0,0 +1,47 @@
1
+ import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
2
+ import { Embeddings, EmbeddingsParams } from "./base.js";
3
+ import type { CredentialType } from "../util/bedrock.js";
4
+ /**
5
+ * Interface that extends EmbeddingsParams and defines additional
6
+ * parameters specific to the BedrockEmbeddings class.
7
+ */
8
+ export interface BedrockEmbeddingsParams extends EmbeddingsParams {
9
+ /**
10
+ * Model Name to use. Defaults to `amazon.titan-embed-text-v1` if not provided
11
+ *
12
+ */
13
+ model?: string;
14
+ /**
15
+ * A client provided by the user that allows them to customze any
16
+ * SDK configuration options.
17
+ */
18
+ client?: BedrockRuntimeClient;
19
+ region?: string;
20
+ credentials?: CredentialType;
21
+ }
22
+ /**
23
+ * Class that extends the Embeddings class and provides methods for
24
+ * generating embeddings using the Bedrock API.
25
+ */
26
+ export declare class BedrockEmbeddings extends Embeddings implements BedrockEmbeddingsParams {
27
+ model: string;
28
+ client: BedrockRuntimeClient;
29
+ constructor(fields?: BedrockEmbeddingsParams);
30
+ protected _embedText(text: string): Promise<number[]>;
31
+ /**
32
+ * Method that takes a document as input and returns a promise that
33
+ * resolves to an embedding for the document. It calls the _embedText
34
+ * method with the document as the input.
35
+ * @param document Document for which to generate an embedding.
36
+ * @returns Promise that resolves to an embedding for the input document.
37
+ */
38
+ embedQuery(document: string): Promise<number[]>;
39
+ /**
40
+ * Method that takes an array of documents as input and returns a promise
41
+ * that resolves to a 2D array of embeddings for each document. It calls
42
+ * the _embedText method for each document in the array.
43
+ * @param documents Array of documents for which to generate embeddings.
44
+ * @returns Promise that resolves to a 2D array of embeddings for each input document.
45
+ */
46
+ embedDocuments(documents: string[]): Promise<number[][]>;
47
+ }
@@ -0,0 +1,69 @@
1
+ import { BedrockRuntimeClient, InvokeModelCommand, } from "@aws-sdk/client-bedrock-runtime";
2
+ import { Embeddings } from "./base.js";
3
+ /**
4
+ * Class that extends the Embeddings class and provides methods for
5
+ * generating embeddings using the Bedrock API.
6
+ */
7
+ export class BedrockEmbeddings extends Embeddings {
8
+ constructor(fields) {
9
+ super(fields ?? {});
10
+ Object.defineProperty(this, "model", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: void 0
15
+ });
16
+ Object.defineProperty(this, "client", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ this.model = fields?.model ?? "amazon.titan-embed-text-v1";
23
+ this.client =
24
+ fields?.client ??
25
+ new BedrockRuntimeClient({
26
+ region: fields?.region,
27
+ credentials: fields?.credentials,
28
+ });
29
+ }
30
+ async _embedText(text) {
31
+ // replace newlines, which can negatively affect performance.
32
+ const cleanedText = text.replace(/\n/g, " ");
33
+ const res = await this.client.send(new InvokeModelCommand({
34
+ modelId: this.model,
35
+ body: JSON.stringify({
36
+ inputText: cleanedText,
37
+ }),
38
+ contentType: "application/json",
39
+ accept: "application/json",
40
+ }));
41
+ try {
42
+ const body = new TextDecoder().decode(res.body);
43
+ return JSON.parse(body).embedding;
44
+ }
45
+ catch (e) {
46
+ throw new Error("An invalid response was returned by Bedrock.");
47
+ }
48
+ }
49
+ /**
50
+ * Method that takes a document as input and returns a promise that
51
+ * resolves to an embedding for the document. It calls the _embedText
52
+ * method with the document as the input.
53
+ * @param document Document for which to generate an embedding.
54
+ * @returns Promise that resolves to an embedding for the input document.
55
+ */
56
+ embedQuery(document) {
57
+ return this.caller.callWithOptions({}, this._embedText.bind(this), document);
58
+ }
59
+ /**
60
+ * Method that takes an array of documents as input and returns a promise
61
+ * that resolves to a 2D array of embeddings for each document. It calls
62
+ * the _embedText method for each document in the array.
63
+ * @param documents Array of documents for which to generate embeddings.
64
+ * @returns Promise that resolves to a 2D array of embeddings for each input document.
65
+ */
66
+ embedDocuments(documents) {
67
+ return Promise.all(documents.map((document) => this._embedText(document)));
68
+ }
69
+ }
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MakerSuiteHub = exports.DriveFileReadConnection = exports.MakerSuitePrompt = void 0;
4
+ const google_auth_library_1 = require("google-auth-library");
5
+ const googlepalm_js_1 = require("../../../llms/googlepalm.cjs");
6
+ const googlepalm_js_2 = require("../../../chat_models/googlepalm.cjs");
7
+ const index_js_1 = require("../../../prompts/index.cjs");
8
+ const async_caller_js_1 = require("../../../util/async_caller.cjs");
9
+ const googlevertexai_connection_js_1 = require("../../../util/googlevertexai-connection.cjs");
10
+ /**
11
+ * A class that represents the Prompt that has been created by MakerSuite
12
+ * and loaded from Google Drive. It exposes methods to turn this prompt
13
+ * into a Template, a Model, and into a chain consisting of these two elements.
14
+ * In general, this class should be created by the MakerSuiteHub class and
15
+ * not instantiated manually.
16
+ */
17
+ class MakerSuitePrompt {
18
+ constructor(promptData) {
19
+ Object.defineProperty(this, "promptType", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+ Object.defineProperty(this, "promptData", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ this.promptData = promptData;
32
+ this._determinePromptType();
33
+ }
34
+ _determinePromptType() {
35
+ if (Object.hasOwn(this.promptData, "textPrompt")) {
36
+ this.promptType = "text";
37
+ }
38
+ else if (Object.hasOwn(this.promptData, "dataPrompt")) {
39
+ this.promptType = "data";
40
+ }
41
+ else if (Object.hasOwn(this.promptData, "multiturnPrompt")) {
42
+ this.promptType = "chat";
43
+ }
44
+ else {
45
+ const error = new Error("Unable to identify prompt type.");
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ error.promptData = this.promptData;
48
+ throw error;
49
+ }
50
+ }
51
+ _promptValueText() {
52
+ return (this.promptData?.textPrompt?.value ?? "");
53
+ }
54
+ _promptValueData() {
55
+ const promptData = this
56
+ .promptData;
57
+ const dataPrompt = promptData?.dataPrompt;
58
+ let prompt = `${dataPrompt?.preamble}\n` || "";
59
+ dataPrompt?.rows.forEach((row) => {
60
+ // Add the data for each row, as long as it is listed as used
61
+ if (dataPrompt?.rowsUsed.includes(row.rowId)) {
62
+ // Add each input column
63
+ dataPrompt?.columns.forEach((column) => {
64
+ if (column.isInput) {
65
+ prompt += `${column.displayName} ${row.columnBindings[column.columnId]}\n`;
66
+ }
67
+ });
68
+ // Add each output column
69
+ dataPrompt?.columns.forEach((column) => {
70
+ if (!column.isInput) {
71
+ prompt += `${column.displayName} ${row.columnBindings[column.columnId]}\n`;
72
+ }
73
+ });
74
+ }
75
+ });
76
+ // Add the input column prompts
77
+ dataPrompt?.columns.forEach((column) => {
78
+ if (column.isInput) {
79
+ prompt += `${column.displayName} {${column.displayName.replace(":", "")}}\n`;
80
+ }
81
+ });
82
+ // Add just the first output column
83
+ const firstOutput = dataPrompt?.columns.find((column) => !column.isInput);
84
+ prompt += `${firstOutput?.displayName} `;
85
+ return prompt;
86
+ }
87
+ _promptValueChat() {
88
+ return (this.promptData?.multiturnPrompt
89
+ ?.preamble ?? "");
90
+ }
91
+ _promptValue() {
92
+ switch (this.promptType) {
93
+ case "text":
94
+ return this._promptValueText();
95
+ case "data":
96
+ return this._promptValueData();
97
+ case "chat":
98
+ return this._promptValueChat();
99
+ default:
100
+ throw new Error(`Invalid promptType: ${this.promptType}`);
101
+ }
102
+ }
103
+ /**
104
+ * Create a template from the prompt, including any "test input" specified
105
+ * in MakerSuite as a template parameter.
106
+ */
107
+ toTemplate() {
108
+ const value = this._promptValue();
109
+ const promptString = value.replaceAll(/{{.*:(.+):.*}}/g, "{$1}");
110
+ return index_js_1.PromptTemplate.fromTemplate(promptString);
111
+ }
112
+ _modelName() {
113
+ let ret = this.promptData?.runSettings?.model;
114
+ if (!ret) {
115
+ ret =
116
+ this.promptType === "chat"
117
+ ? "models/chat-bison-001"
118
+ : "models/text-bison-001";
119
+ }
120
+ return ret;
121
+ }
122
+ _examples() {
123
+ const promptData = this
124
+ .promptData;
125
+ const ret = promptData?.multiturnPrompt?.primingExchanges
126
+ .map((exchange) => {
127
+ const example = {};
128
+ if (exchange?.request) {
129
+ example.input = {
130
+ content: exchange.request,
131
+ };
132
+ }
133
+ if (exchange?.response) {
134
+ example.output = {
135
+ content: exchange.response,
136
+ };
137
+ }
138
+ return example;
139
+ })
140
+ .filter((value) => Object.keys(value).length);
141
+ return ret;
142
+ }
143
+ /**
144
+ * Create a model from the prompt with all the parameters (model name,
145
+ * temperature, etc) set as they were in MakerSuite.
146
+ */
147
+ toModel() {
148
+ const modelName = this._modelName();
149
+ const modelSettings = {
150
+ modelName,
151
+ ...this.promptData?.runSettings,
152
+ };
153
+ if (this.promptType === "chat") {
154
+ const examples = this._examples();
155
+ return new googlepalm_js_2.ChatGooglePaLM({
156
+ examples,
157
+ ...modelSettings,
158
+ });
159
+ }
160
+ else {
161
+ return new googlepalm_js_1.GooglePaLM(modelSettings);
162
+ }
163
+ }
164
+ /**
165
+ * Create a RunnableSequence based on the template and model that can
166
+ * be created from this prompt. The template will have parameters available
167
+ * based on the "test input" that was set in MakerSuite, and the model
168
+ * will have the parameters (model name, temperature, etc) from those in
169
+ * MakerSuite.
170
+ */
171
+ toChain() {
172
+ return this.toTemplate().pipe(this.toModel());
173
+ }
174
+ }
175
+ exports.MakerSuitePrompt = MakerSuitePrompt;
176
+ class DriveFileReadConnection extends googlevertexai_connection_js_1.GoogleConnection {
177
+ constructor(fields, caller) {
178
+ super(caller, new google_auth_library_1.GoogleAuth({
179
+ scopes: "https://www.googleapis.com/auth/drive.readonly",
180
+ ...fields.authOptions,
181
+ }));
182
+ Object.defineProperty(this, "endpoint", {
183
+ enumerable: true,
184
+ configurable: true,
185
+ writable: true,
186
+ value: void 0
187
+ });
188
+ Object.defineProperty(this, "apiVersion", {
189
+ enumerable: true,
190
+ configurable: true,
191
+ writable: true,
192
+ value: void 0
193
+ });
194
+ Object.defineProperty(this, "fileId", {
195
+ enumerable: true,
196
+ configurable: true,
197
+ writable: true,
198
+ value: void 0
199
+ });
200
+ this.endpoint = fields.endpoint ?? "www.googleapis.com";
201
+ this.apiVersion = fields.apiVersion ?? "v3";
202
+ this.fileId = fields.fileId;
203
+ }
204
+ async buildUrl() {
205
+ return `https://${this.endpoint}/drive/${this.apiVersion}/files/${this.fileId}?alt=media`;
206
+ }
207
+ buildMethod() {
208
+ return "GET";
209
+ }
210
+ async request(options) {
211
+ return this._request(undefined, options ?? {});
212
+ }
213
+ }
214
+ exports.DriveFileReadConnection = DriveFileReadConnection;
215
+ /**
216
+ * A class allowing access to MakerSuite prompts that have been saved in
217
+ * Google Drive.
218
+ * MakerSuite prompts are pulled based on their Google Drive ID (which is available
219
+ * from Google Drive or as part of the URL when the prompt is open in MakerSuite).
220
+ * There is a basic cache that will store the prompt in memory for a time specified
221
+ * in milliseconds. This defaults to 0, indicating the prompt should always be
222
+ * pulled from Google Drive.
223
+ */
224
+ class MakerSuiteHub {
225
+ constructor(config) {
226
+ Object.defineProperty(this, "cache", {
227
+ enumerable: true,
228
+ configurable: true,
229
+ writable: true,
230
+ value: {}
231
+ });
232
+ Object.defineProperty(this, "cacheTimeout", {
233
+ enumerable: true,
234
+ configurable: true,
235
+ writable: true,
236
+ value: void 0
237
+ });
238
+ Object.defineProperty(this, "caller", {
239
+ enumerable: true,
240
+ configurable: true,
241
+ writable: true,
242
+ value: void 0
243
+ });
244
+ this.cacheTimeout = config?.cacheTimeout ?? 0;
245
+ this.caller = config?.caller ?? new async_caller_js_1.AsyncCaller({});
246
+ }
247
+ /**
248
+ * Is the current cache entry valid, or does it need to be refreshed.
249
+ * It will need to be refreshed under any of the following conditions:
250
+ * - It does not currently exist in the cache
251
+ * - The cacheTimeout is 0
252
+ * - The cache was last updated longer ago than the cacheTimeout allows
253
+ * @param entry - The cache entry, including when this prompt was last refreshed
254
+ */
255
+ isValid(entry) {
256
+ // If we don't have a record, it can't be valid
257
+ // And if the cache timeout is 0, we will always refresh, so the cache is invalid
258
+ if (!entry || this.cacheTimeout === 0) {
259
+ return false;
260
+ }
261
+ const now = Date.now();
262
+ const expiration = entry.updated + this.cacheTimeout;
263
+ return expiration > now;
264
+ }
265
+ /**
266
+ * Get a MakerSuitePrompt that is specified by the Google Drive ID.
267
+ * This will always be loaded from Google Drive.
268
+ * @param id
269
+ * @return A MakerSuitePrompt which can be used to create a template, model, or chain.
270
+ */
271
+ async forcePull(id) {
272
+ const fields = {
273
+ fileId: id,
274
+ };
275
+ const connection = new DriveFileReadConnection(fields, this.caller);
276
+ const result = await connection.request();
277
+ const ret = new MakerSuitePrompt(result.data);
278
+ this.cache[id] = {
279
+ prompt: ret,
280
+ updated: Date.now(),
281
+ };
282
+ return ret;
283
+ }
284
+ /**
285
+ * Get a MakerSuitePrompt that is specified by the Google Drive ID. This may be
286
+ * loaded from Google Drive or, if there is a valid copy in the cache, the cached
287
+ * copy will be returned.
288
+ * @param id
289
+ * @return A MakerSuitePrompt which can be used to create a template, model, or chain.
290
+ */
291
+ async pull(id) {
292
+ const entry = this.cache[id];
293
+ const ret = this.isValid(entry) ? entry.prompt : await this.forcePull(id);
294
+ return ret;
295
+ }
296
+ }
297
+ exports.MakerSuiteHub = MakerSuiteHub;
@@ -0,0 +1,183 @@
1
+ import type { protos } from "@google-ai/generativelanguage";
2
+ import type { google } from "@google-ai/generativelanguage/build/protos/protos.js";
3
+ import { GoogleAuthOptions } from "google-auth-library";
4
+ import { PromptTemplate } from "../../../prompts/index.js";
5
+ import { BaseLanguageModel } from "../../../base_language/index.js";
6
+ import { AsyncCaller, AsyncCallerCallOptions } from "../../../util/async_caller.js";
7
+ import { GoogleResponse, GoogleVertexAIConnectionParams } from "../../../types/googlevertexai-types.js";
8
+ import { GoogleConnection } from "../../../util/googlevertexai-connection.js";
9
+ /**
10
+ * Configuration that allows us to load or pull a prompt that has been created
11
+ * by the Google MakerSuite site and saved in Google Drive.
12
+ *
13
+ * There is a simple in-memory cache of these prompts that is refreshed
14
+ * after the cacheTimeout specified in the configuration.
15
+ */
16
+ export interface MakerSuiteHubConfig {
17
+ /**
18
+ * How long, in milliseconds, before a prompt is assumed stale and should
19
+ * be refreshed from the copy in Google Drive.
20
+ */
21
+ cacheTimeout: number;
22
+ caller?: AsyncCaller;
23
+ }
24
+ type MakerSuitePromptType = "text" | "data" | "chat";
25
+ export interface MakerSuitePromptVariable {
26
+ variableId: string;
27
+ displayName: string;
28
+ }
29
+ export interface MakerSuiteRunSettings {
30
+ temperature?: number;
31
+ model: string;
32
+ candidateCount?: number;
33
+ topP?: number;
34
+ topK?: number;
35
+ maxOutputTokens: number;
36
+ safetySettings?: protos.google.ai.generativelanguage.v1beta2.ISafetySetting[];
37
+ }
38
+ export interface MakerSuiteTextPromptData {
39
+ textPrompt: {
40
+ value?: string;
41
+ variables?: MakerSuitePromptVariable[];
42
+ };
43
+ runSettings?: MakerSuiteRunSettings;
44
+ testExamples?: unknown;
45
+ }
46
+ export interface MakerSuiteDataPromptColumn {
47
+ columnId: string;
48
+ displayName: string;
49
+ isInput?: boolean;
50
+ }
51
+ export interface MakerSuiteDataPromptRow {
52
+ rowId: string;
53
+ columnBindings: Record<string, string>;
54
+ }
55
+ export interface MakerSuiteDataPromptData {
56
+ dataPrompt: {
57
+ preamble: string;
58
+ columns: MakerSuiteDataPromptColumn[];
59
+ rows: MakerSuiteDataPromptRow[];
60
+ rowsUsed: string[];
61
+ };
62
+ runSettings?: MakerSuiteRunSettings;
63
+ testExamples?: unknown;
64
+ }
65
+ export interface MakerSuiteChatExchange {
66
+ request?: string;
67
+ response?: string;
68
+ source: string;
69
+ id: string;
70
+ }
71
+ export interface MakerSuiteChatPromptData {
72
+ multiturnPrompt: {
73
+ preamble: string;
74
+ primingExchanges: MakerSuiteChatExchange[];
75
+ sessions: {
76
+ sessionExchanges: MakerSuiteChatExchange[];
77
+ }[];
78
+ };
79
+ runSettings?: MakerSuiteRunSettings;
80
+ }
81
+ /**
82
+ * These are the possible formats that the JSON generated by MakerSuite
83
+ * and saved in Google Drive can be.
84
+ */
85
+ export type MakerSuitePromptData = MakerSuiteTextPromptData | MakerSuiteDataPromptData | MakerSuiteChatPromptData;
86
+ /**
87
+ * A class that represents the Prompt that has been created by MakerSuite
88
+ * and loaded from Google Drive. It exposes methods to turn this prompt
89
+ * into a Template, a Model, and into a chain consisting of these two elements.
90
+ * In general, this class should be created by the MakerSuiteHub class and
91
+ * not instantiated manually.
92
+ */
93
+ export declare class MakerSuitePrompt {
94
+ promptType: MakerSuitePromptType;
95
+ promptData: MakerSuitePromptData;
96
+ constructor(promptData: MakerSuitePromptData);
97
+ _determinePromptType(): void;
98
+ _promptValueText(): string;
99
+ _promptValueData(): string;
100
+ _promptValueChat(): string;
101
+ _promptValue(): string;
102
+ /**
103
+ * Create a template from the prompt, including any "test input" specified
104
+ * in MakerSuite as a template parameter.
105
+ */
106
+ toTemplate(): PromptTemplate;
107
+ _modelName(): string;
108
+ _examples(): google.ai.generativelanguage.v1beta2.IExample[];
109
+ /**
110
+ * Create a model from the prompt with all the parameters (model name,
111
+ * temperature, etc) set as they were in MakerSuite.
112
+ */
113
+ toModel(): BaseLanguageModel;
114
+ /**
115
+ * Create a RunnableSequence based on the template and model that can
116
+ * be created from this prompt. The template will have parameters available
117
+ * based on the "test input" that was set in MakerSuite, and the model
118
+ * will have the parameters (model name, temperature, etc) from those in
119
+ * MakerSuite.
120
+ */
121
+ toChain(): import("../../../schema/runnable/base.js").RunnableSequence<any, any>;
122
+ }
123
+ interface DriveFileReadParams extends GoogleVertexAIConnectionParams<GoogleAuthOptions> {
124
+ fileId: string;
125
+ }
126
+ interface DriveCallOptions extends AsyncCallerCallOptions {
127
+ }
128
+ interface DriveFileMakerSuiteResponse extends GoogleResponse {
129
+ data: MakerSuitePromptData;
130
+ }
131
+ export declare class DriveFileReadConnection extends GoogleConnection<DriveCallOptions, DriveFileMakerSuiteResponse> implements DriveFileReadParams {
132
+ endpoint: string;
133
+ apiVersion: string;
134
+ fileId: string;
135
+ constructor(fields: DriveFileReadParams, caller: AsyncCaller);
136
+ buildUrl(): Promise<string>;
137
+ buildMethod(): string;
138
+ request(options?: DriveCallOptions): Promise<DriveFileMakerSuiteResponse>;
139
+ }
140
+ export interface CacheEntry {
141
+ updated: number;
142
+ prompt: MakerSuitePrompt;
143
+ }
144
+ /**
145
+ * A class allowing access to MakerSuite prompts that have been saved in
146
+ * Google Drive.
147
+ * MakerSuite prompts are pulled based on their Google Drive ID (which is available
148
+ * from Google Drive or as part of the URL when the prompt is open in MakerSuite).
149
+ * There is a basic cache that will store the prompt in memory for a time specified
150
+ * in milliseconds. This defaults to 0, indicating the prompt should always be
151
+ * pulled from Google Drive.
152
+ */
153
+ export declare class MakerSuiteHub {
154
+ cache: Record<string, CacheEntry>;
155
+ cacheTimeout: number;
156
+ caller: AsyncCaller;
157
+ constructor(config?: MakerSuiteHubConfig);
158
+ /**
159
+ * Is the current cache entry valid, or does it need to be refreshed.
160
+ * It will need to be refreshed under any of the following conditions:
161
+ * - It does not currently exist in the cache
162
+ * - The cacheTimeout is 0
163
+ * - The cache was last updated longer ago than the cacheTimeout allows
164
+ * @param entry - The cache entry, including when this prompt was last refreshed
165
+ */
166
+ isValid(entry: CacheEntry): boolean;
167
+ /**
168
+ * Get a MakerSuitePrompt that is specified by the Google Drive ID.
169
+ * This will always be loaded from Google Drive.
170
+ * @param id
171
+ * @return A MakerSuitePrompt which can be used to create a template, model, or chain.
172
+ */
173
+ forcePull(id: string): Promise<MakerSuitePrompt>;
174
+ /**
175
+ * Get a MakerSuitePrompt that is specified by the Google Drive ID. This may be
176
+ * loaded from Google Drive or, if there is a valid copy in the cache, the cached
177
+ * copy will be returned.
178
+ * @param id
179
+ * @return A MakerSuitePrompt which can be used to create a template, model, or chain.
180
+ */
181
+ pull(id: string): Promise<MakerSuitePrompt>;
182
+ }
183
+ export {};