langchain 0.0.147 → 0.0.148

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 (110) hide show
  1. package/chat_models/googlevertexai/web.cjs +1 -0
  2. package/chat_models/googlevertexai/web.d.ts +1 -0
  3. package/chat_models/googlevertexai/web.js +1 -0
  4. package/chat_models/googlevertexai.cjs +1 -1
  5. package/chat_models/googlevertexai.d.ts +1 -1
  6. package/chat_models/googlevertexai.js +1 -1
  7. package/dist/chains/constitutional_ai/constitutional_principle.cjs +272 -1
  8. package/dist/chains/constitutional_ai/constitutional_principle.js +272 -1
  9. package/dist/chat_models/{googlevertexai.cjs → googlevertexai/common.cjs} +14 -26
  10. package/dist/chat_models/{googlevertexai.d.ts → googlevertexai/common.d.ts} +13 -22
  11. package/dist/chat_models/{googlevertexai.js → googlevertexai/common.js} +12 -24
  12. package/dist/chat_models/googlevertexai/index.cjs +36 -0
  13. package/dist/chat_models/googlevertexai/index.d.ts +21 -0
  14. package/dist/chat_models/googlevertexai/index.js +31 -0
  15. package/dist/chat_models/googlevertexai/web.cjs +33 -0
  16. package/dist/chat_models/googlevertexai/web.d.ts +19 -0
  17. package/dist/chat_models/googlevertexai/web.js +28 -0
  18. package/dist/document_loaders/web/notionapi.cjs +93 -70
  19. package/dist/document_loaders/web/notionapi.d.ts +33 -1
  20. package/dist/document_loaders/web/notionapi.js +89 -71
  21. package/dist/embeddings/googlevertexai.cjs +5 -1
  22. package/dist/embeddings/googlevertexai.d.ts +2 -1
  23. package/dist/embeddings/googlevertexai.js +5 -1
  24. package/dist/evaluation/agents/index.cjs +17 -0
  25. package/dist/evaluation/agents/index.d.ts +1 -0
  26. package/dist/evaluation/agents/index.js +1 -0
  27. package/dist/evaluation/agents/prompt.cjs +132 -0
  28. package/dist/evaluation/agents/prompt.d.ts +6 -0
  29. package/dist/evaluation/agents/prompt.js +129 -0
  30. package/dist/evaluation/agents/trajectory.cjs +189 -0
  31. package/dist/evaluation/agents/trajectory.d.ts +54 -0
  32. package/dist/evaluation/agents/trajectory.js +184 -0
  33. package/dist/evaluation/base.cjs +274 -0
  34. package/dist/evaluation/base.d.ts +232 -0
  35. package/dist/evaluation/base.js +263 -0
  36. package/dist/evaluation/comparison/index.cjs +17 -0
  37. package/dist/evaluation/comparison/index.d.ts +1 -0
  38. package/dist/evaluation/comparison/index.js +1 -0
  39. package/dist/evaluation/comparison/pairwise.cjs +244 -0
  40. package/dist/evaluation/comparison/pairwise.d.ts +50 -0
  41. package/dist/evaluation/comparison/pairwise.js +238 -0
  42. package/dist/evaluation/comparison/prompt.cjs +74 -0
  43. package/dist/evaluation/comparison/prompt.d.ts +21 -0
  44. package/dist/evaluation/comparison/prompt.js +71 -0
  45. package/dist/evaluation/criteria/criteria.cjs +259 -0
  46. package/dist/evaluation/criteria/criteria.d.ts +73 -0
  47. package/dist/evaluation/criteria/criteria.js +253 -0
  48. package/dist/evaluation/criteria/index.cjs +17 -0
  49. package/dist/evaluation/criteria/index.d.ts +1 -0
  50. package/dist/evaluation/criteria/index.js +1 -0
  51. package/dist/evaluation/criteria/prompt.cjs +36 -0
  52. package/dist/evaluation/criteria/prompt.d.ts +12 -0
  53. package/dist/evaluation/criteria/prompt.js +33 -0
  54. package/dist/evaluation/embedding_distance/base.cjs +163 -0
  55. package/dist/evaluation/embedding_distance/base.d.ts +78 -0
  56. package/dist/evaluation/embedding_distance/base.js +156 -0
  57. package/dist/evaluation/embedding_distance/index.cjs +17 -0
  58. package/dist/evaluation/embedding_distance/index.d.ts +1 -0
  59. package/dist/evaluation/embedding_distance/index.js +1 -0
  60. package/dist/evaluation/index.cjs +6 -0
  61. package/dist/evaluation/index.d.ts +6 -0
  62. package/dist/evaluation/index.js +6 -0
  63. package/dist/evaluation/loader.cjs +60 -0
  64. package/dist/evaluation/loader.d.ts +27 -0
  65. package/dist/evaluation/loader.js +56 -0
  66. package/dist/evaluation/types.cjs +2 -0
  67. package/dist/evaluation/types.d.ts +35 -0
  68. package/dist/evaluation/types.js +1 -0
  69. package/dist/experimental/multimodal_embeddings/googlevertexai.cjs +5 -1
  70. package/dist/experimental/multimodal_embeddings/googlevertexai.d.ts +2 -1
  71. package/dist/experimental/multimodal_embeddings/googlevertexai.js +5 -1
  72. package/dist/llms/{googlevertexai.js → googlevertexai/common.cjs} +21 -17
  73. package/dist/llms/{googlevertexai.d.ts → googlevertexai/common.d.ts} +13 -23
  74. package/dist/llms/{googlevertexai.cjs → googlevertexai/common.js} +17 -21
  75. package/dist/llms/googlevertexai/index.cjs +34 -0
  76. package/dist/llms/googlevertexai/index.d.ts +26 -0
  77. package/dist/llms/googlevertexai/index.js +30 -0
  78. package/dist/llms/googlevertexai/web.cjs +31 -0
  79. package/dist/llms/googlevertexai/web.d.ts +24 -0
  80. package/dist/llms/googlevertexai/web.js +27 -0
  81. package/dist/load/import_constants.cjs +2 -0
  82. package/dist/load/import_constants.js +2 -0
  83. package/dist/load/import_map.cjs +2 -1
  84. package/dist/load/import_map.d.ts +1 -0
  85. package/dist/load/import_map.js +1 -0
  86. package/dist/load/serializable.cjs +23 -4
  87. package/dist/load/serializable.js +23 -4
  88. package/dist/retrievers/multi_query.cjs +140 -0
  89. package/dist/retrievers/multi_query.d.ts +33 -0
  90. package/dist/retrievers/multi_query.js +136 -0
  91. package/dist/types/googlevertexai-types.d.ts +11 -4
  92. package/dist/util/googlevertexai-connection.cjs +14 -15
  93. package/dist/util/googlevertexai-connection.d.ts +7 -7
  94. package/dist/util/googlevertexai-connection.js +14 -15
  95. package/dist/util/googlevertexai-webauth.cjs +56 -0
  96. package/dist/util/googlevertexai-webauth.d.ts +25 -0
  97. package/dist/util/googlevertexai-webauth.js +52 -0
  98. package/dist/vectorstores/googlevertexai.cjs +9 -8
  99. package/dist/vectorstores/googlevertexai.d.ts +8 -7
  100. package/dist/vectorstores/googlevertexai.js +9 -8
  101. package/llms/googlevertexai/web.cjs +1 -0
  102. package/llms/googlevertexai/web.d.ts +1 -0
  103. package/llms/googlevertexai/web.js +1 -0
  104. package/llms/googlevertexai.cjs +1 -1
  105. package/llms/googlevertexai.d.ts +1 -1
  106. package/llms/googlevertexai.js +1 -1
  107. package/package.json +32 -3
  108. package/retrievers/multi_query.cjs +1 -0
  109. package/retrievers/multi_query.d.ts +1 -0
  110. package/retrievers/multi_query.js +1 -0
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChatGoogleVertexAI = exports.GoogleVertexAIChatMessage = void 0;
4
- const base_js_1 = require("./base.cjs");
5
- const index_js_1 = require("../schema/index.cjs");
6
- const googlevertexai_connection_js_1 = require("../util/googlevertexai-connection.cjs");
3
+ exports.BaseChatGoogleVertexAI = exports.GoogleVertexAIChatMessage = void 0;
4
+ const base_js_1 = require("../base.cjs");
5
+ const index_js_1 = require("../../schema/index.cjs");
7
6
  /**
8
7
  * Represents a chat message in the Google Vertex AI chat model.
9
8
  */
@@ -85,22 +84,15 @@ class GoogleVertexAIChatMessage {
85
84
  }
86
85
  exports.GoogleVertexAIChatMessage = GoogleVertexAIChatMessage;
87
86
  /**
88
- * Enables calls to the Google Cloud's Vertex AI API to access
89
- * Large Language Models in a chat-like fashion.
90
- *
91
- * To use, you will need to have one of the following authentication
92
- * methods in place:
93
- * - You are logged into an account permitted to the Google Cloud project
94
- * using Vertex AI.
95
- * - You are running this on a machine using a service account permitted to
96
- * the Google Cloud project using Vertex AI.
97
- * - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
98
- * path of a credentials file for a service account permitted to the
99
- * Google Cloud project using Vertex AI.
87
+ * Base class for Google Vertex AI chat models.
88
+ * Implemented subclasses must provide a GoogleVertexAILLMConnection
89
+ * with appropriate auth client.
100
90
  */
101
- class ChatGoogleVertexAI extends base_js_1.BaseChatModel {
102
- static lc_name() {
103
- return "ChatGoogleVertexAI";
91
+ class BaseChatGoogleVertexAI extends base_js_1.BaseChatModel {
92
+ get lc_aliases() {
93
+ return {
94
+ model: "model_name",
95
+ };
104
96
  }
105
97
  constructor(fields) {
106
98
  super(fields ?? {});
@@ -158,10 +150,6 @@ class ChatGoogleVertexAI extends base_js_1.BaseChatModel {
158
150
  this.topP = fields?.topP ?? this.topP;
159
151
  this.topK = fields?.topK ?? this.topK;
160
152
  this.examples = fields?.examples ?? this.examples;
161
- this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({
162
- ...fields,
163
- ...this,
164
- }, this.caller);
165
153
  }
166
154
  _combineLLMOutput() {
167
155
  // TODO: Combine the safetyAttributes
@@ -177,13 +165,13 @@ class ChatGoogleVertexAI extends base_js_1.BaseChatModel {
177
165
  maxOutputTokens: this.maxOutputTokens,
178
166
  };
179
167
  const result = await this.connection.request([instance], parameters, options);
180
- const generations = result?.data?.predictions?.map((prediction) => ChatGoogleVertexAI.convertPrediction(prediction)) ?? [];
168
+ const generations = result?.data?.predictions?.map((prediction) => BaseChatGoogleVertexAI.convertPrediction(prediction)) ?? [];
181
169
  return {
182
170
  generations,
183
171
  };
184
172
  }
185
173
  _llmType() {
186
- return "googlevertexai";
174
+ return "vertexai";
187
175
  }
188
176
  /**
189
177
  * Creates an instance of the Google Vertex AI chat model.
@@ -238,4 +226,4 @@ class ChatGoogleVertexAI extends base_js_1.BaseChatModel {
238
226
  };
239
227
  }
240
228
  }
241
- exports.ChatGoogleVertexAI = ChatGoogleVertexAI;
229
+ exports.BaseChatGoogleVertexAI = BaseChatGoogleVertexAI;
@@ -1,8 +1,8 @@
1
- import { BaseChatModel } from "./base.js";
2
- import { BaseMessage, ChatGeneration, ChatMessage, ChatResult, LLMResult } from "../schema/index.js";
3
- import { GoogleVertexAILLMConnection } from "../util/googlevertexai-connection.js";
4
- import { GoogleVertexAIBaseLLMInput, GoogleVertexAIBasePrediction } from "../types/googlevertexai-types.js";
5
- import { BaseLanguageModelCallOptions } from "../base_language/index.js";
1
+ import { BaseChatModel } from "../base.js";
2
+ import { BaseMessage, ChatGeneration, ChatMessage, ChatResult, LLMResult } from "../../schema/index.js";
3
+ import { GoogleVertexAILLMConnection } from "../../util/googlevertexai-connection.js";
4
+ import { GoogleVertexAIBaseLLMInput, GoogleVertexAIBasePrediction } from "../../types/googlevertexai-types.js";
5
+ import { BaseLanguageModelCallOptions } from "../../base_language/index.js";
6
6
  /**
7
7
  * Represents a single "example" exchange that can be provided to
8
8
  * help illustrate what a model response should look like.
@@ -76,28 +76,18 @@ export interface GoogleVertexAIChatPrediction extends GoogleVertexAIBasePredicti
76
76
  /**
77
77
  * Defines the input to the Google Vertex AI chat model.
78
78
  */
79
- export interface GoogleVertexAIChatInput extends GoogleVertexAIBaseLLMInput {
79
+ export interface GoogleVertexAIChatInput<AuthOptions> extends GoogleVertexAIBaseLLMInput<AuthOptions> {
80
80
  /** Instructions how the model should respond */
81
81
  context?: string;
82
82
  /** Help the model understand what an appropriate response is */
83
83
  examples?: ChatExample[];
84
84
  }
85
85
  /**
86
- * Enables calls to the Google Cloud's Vertex AI API to access
87
- * Large Language Models in a chat-like fashion.
88
- *
89
- * To use, you will need to have one of the following authentication
90
- * methods in place:
91
- * - You are logged into an account permitted to the Google Cloud project
92
- * using Vertex AI.
93
- * - You are running this on a machine using a service account permitted to
94
- * the Google Cloud project using Vertex AI.
95
- * - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
96
- * path of a credentials file for a service account permitted to the
97
- * Google Cloud project using Vertex AI.
86
+ * Base class for Google Vertex AI chat models.
87
+ * Implemented subclasses must provide a GoogleVertexAILLMConnection
88
+ * with appropriate auth client.
98
89
  */
99
- export declare class ChatGoogleVertexAI extends BaseChatModel implements GoogleVertexAIChatInput {
100
- static lc_name(): string;
90
+ export declare class BaseChatGoogleVertexAI<AuthOptions> extends BaseChatModel implements GoogleVertexAIChatInput<AuthOptions> {
101
91
  lc_serializable: boolean;
102
92
  model: string;
103
93
  temperature: number;
@@ -105,8 +95,9 @@ export declare class ChatGoogleVertexAI extends BaseChatModel implements GoogleV
105
95
  topP: number;
106
96
  topK: number;
107
97
  examples: ChatExample[];
108
- connection: GoogleVertexAILLMConnection<BaseLanguageModelCallOptions, GoogleVertexAIChatInstance, GoogleVertexAIChatPrediction>;
109
- constructor(fields?: GoogleVertexAIChatInput);
98
+ connection: GoogleVertexAILLMConnection<BaseLanguageModelCallOptions, GoogleVertexAIChatInstance, GoogleVertexAIChatPrediction, AuthOptions>;
99
+ get lc_aliases(): Record<string, string>;
100
+ constructor(fields?: GoogleVertexAIChatInput<AuthOptions>);
110
101
  _combineLLMOutput(): LLMResult["llmOutput"];
111
102
  _generate(messages: BaseMessage[], options: this["ParsedCallOptions"]): Promise<ChatResult>;
112
103
  _llmType(): string;
@@ -1,6 +1,5 @@
1
- import { BaseChatModel } from "./base.js";
2
- import { AIMessage, ChatMessage, } from "../schema/index.js";
3
- import { GoogleVertexAILLMConnection } from "../util/googlevertexai-connection.js";
1
+ import { BaseChatModel } from "../base.js";
2
+ import { AIMessage, ChatMessage, } from "../../schema/index.js";
4
3
  /**
5
4
  * Represents a chat message in the Google Vertex AI chat model.
6
5
  */
@@ -81,22 +80,15 @@ export class GoogleVertexAIChatMessage {
81
80
  }
82
81
  }
83
82
  /**
84
- * Enables calls to the Google Cloud's Vertex AI API to access
85
- * Large Language Models in a chat-like fashion.
86
- *
87
- * To use, you will need to have one of the following authentication
88
- * methods in place:
89
- * - You are logged into an account permitted to the Google Cloud project
90
- * using Vertex AI.
91
- * - You are running this on a machine using a service account permitted to
92
- * the Google Cloud project using Vertex AI.
93
- * - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
94
- * path of a credentials file for a service account permitted to the
95
- * Google Cloud project using Vertex AI.
83
+ * Base class for Google Vertex AI chat models.
84
+ * Implemented subclasses must provide a GoogleVertexAILLMConnection
85
+ * with appropriate auth client.
96
86
  */
97
- export class ChatGoogleVertexAI extends BaseChatModel {
98
- static lc_name() {
99
- return "ChatGoogleVertexAI";
87
+ export class BaseChatGoogleVertexAI extends BaseChatModel {
88
+ get lc_aliases() {
89
+ return {
90
+ model: "model_name",
91
+ };
100
92
  }
101
93
  constructor(fields) {
102
94
  super(fields ?? {});
@@ -154,10 +146,6 @@ export class ChatGoogleVertexAI extends BaseChatModel {
154
146
  this.topP = fields?.topP ?? this.topP;
155
147
  this.topK = fields?.topK ?? this.topK;
156
148
  this.examples = fields?.examples ?? this.examples;
157
- this.connection = new GoogleVertexAILLMConnection({
158
- ...fields,
159
- ...this,
160
- }, this.caller);
161
149
  }
162
150
  _combineLLMOutput() {
163
151
  // TODO: Combine the safetyAttributes
@@ -173,13 +161,13 @@ export class ChatGoogleVertexAI extends BaseChatModel {
173
161
  maxOutputTokens: this.maxOutputTokens,
174
162
  };
175
163
  const result = await this.connection.request([instance], parameters, options);
176
- const generations = result?.data?.predictions?.map((prediction) => ChatGoogleVertexAI.convertPrediction(prediction)) ?? [];
164
+ const generations = result?.data?.predictions?.map((prediction) => BaseChatGoogleVertexAI.convertPrediction(prediction)) ?? [];
177
165
  return {
178
166
  generations,
179
167
  };
180
168
  }
181
169
  _llmType() {
182
- return "googlevertexai";
170
+ return "vertexai";
183
171
  }
184
172
  /**
185
173
  * Creates an instance of the Google Vertex AI chat model.
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GoogleVertexAIChatMessage = exports.ChatGoogleVertexAI = void 0;
4
+ const google_auth_library_1 = require("google-auth-library");
5
+ const common_js_1 = require("./common.cjs");
6
+ const googlevertexai_connection_js_1 = require("../../util/googlevertexai-connection.cjs");
7
+ /**
8
+ * Enables calls to the Google Cloud's Vertex AI API to access
9
+ * Large Language Models in a chat-like fashion.
10
+ *
11
+ * To use, you will need to have one of the following authentication
12
+ * methods in place:
13
+ * - You are logged into an account permitted to the Google Cloud project
14
+ * using Vertex AI.
15
+ * - You are running this on a machine using a service account permitted to
16
+ * the Google Cloud project using Vertex AI.
17
+ * - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
18
+ * path of a credentials file for a service account permitted to the
19
+ * Google Cloud project using Vertex AI.
20
+ */
21
+ class ChatGoogleVertexAI extends common_js_1.BaseChatGoogleVertexAI {
22
+ static lc_name() {
23
+ return "ChatVertexAI";
24
+ }
25
+ constructor(fields) {
26
+ super(fields);
27
+ const client = new google_auth_library_1.GoogleAuth({
28
+ scopes: "https://www.googleapis.com/auth/cloud-platform",
29
+ ...fields?.authOptions,
30
+ });
31
+ this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller, client);
32
+ }
33
+ }
34
+ exports.ChatGoogleVertexAI = ChatGoogleVertexAI;
35
+ var common_js_2 = require("./common.cjs");
36
+ Object.defineProperty(exports, "GoogleVertexAIChatMessage", { enumerable: true, get: function () { return common_js_2.GoogleVertexAIChatMessage; } });
@@ -0,0 +1,21 @@
1
+ import { GoogleAuthOptions } from "google-auth-library";
2
+ import { BaseChatGoogleVertexAI, GoogleVertexAIChatInput } from "./common.js";
3
+ /**
4
+ * Enables calls to the Google Cloud's Vertex AI API to access
5
+ * Large Language Models in a chat-like fashion.
6
+ *
7
+ * To use, you will need to have one of the following authentication
8
+ * methods in place:
9
+ * - You are logged into an account permitted to the Google Cloud project
10
+ * using Vertex AI.
11
+ * - You are running this on a machine using a service account permitted to
12
+ * the Google Cloud project using Vertex AI.
13
+ * - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
14
+ * path of a credentials file for a service account permitted to the
15
+ * Google Cloud project using Vertex AI.
16
+ */
17
+ export declare class ChatGoogleVertexAI extends BaseChatGoogleVertexAI<GoogleAuthOptions> {
18
+ static lc_name(): string;
19
+ constructor(fields?: GoogleVertexAIChatInput<GoogleAuthOptions>);
20
+ }
21
+ export { ChatExample, GoogleVertexAIChatAuthor, GoogleVertexAIChatInput, GoogleVertexAIChatInstance, GoogleVertexAIChatMessage, GoogleVertexAIChatMessageFields, GoogleVertexAIChatPrediction, } from "./common.js";
@@ -0,0 +1,31 @@
1
+ import { GoogleAuth } from "google-auth-library";
2
+ import { BaseChatGoogleVertexAI } from "./common.js";
3
+ import { GoogleVertexAILLMConnection } from "../../util/googlevertexai-connection.js";
4
+ /**
5
+ * Enables calls to the Google Cloud's Vertex AI API to access
6
+ * Large Language Models in a chat-like fashion.
7
+ *
8
+ * To use, you will need to have one of the following authentication
9
+ * methods in place:
10
+ * - You are logged into an account permitted to the Google Cloud project
11
+ * using Vertex AI.
12
+ * - You are running this on a machine using a service account permitted to
13
+ * the Google Cloud project using Vertex AI.
14
+ * - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
15
+ * path of a credentials file for a service account permitted to the
16
+ * Google Cloud project using Vertex AI.
17
+ */
18
+ export class ChatGoogleVertexAI extends BaseChatGoogleVertexAI {
19
+ static lc_name() {
20
+ return "ChatVertexAI";
21
+ }
22
+ constructor(fields) {
23
+ super(fields);
24
+ const client = new GoogleAuth({
25
+ scopes: "https://www.googleapis.com/auth/cloud-platform",
26
+ ...fields?.authOptions,
27
+ });
28
+ this.connection = new GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller, client);
29
+ }
30
+ }
31
+ export { GoogleVertexAIChatMessage, } from "./common.js";
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GoogleVertexAIChatMessage = exports.ChatGoogleVertexAI = void 0;
4
+ const googlevertexai_connection_js_1 = require("../../util/googlevertexai-connection.cjs");
5
+ const googlevertexai_webauth_js_1 = require("../../util/googlevertexai-webauth.cjs");
6
+ const common_js_1 = require("./common.cjs");
7
+ /**
8
+ * Enables calls to the Google Cloud's Vertex AI API to access
9
+ * Large Language Models in a chat-like fashion.
10
+ *
11
+ * This entrypoint and class are intended to be used in web environments like Edge
12
+ * functions where you do not have access to the file system. It supports passing
13
+ * service account credentials directly as a "GOOGLE_VERTEX_AI_WEB_CREDENTIALS"
14
+ * environment variable or directly as "authOptions.credentials".
15
+ */
16
+ class ChatGoogleVertexAI extends common_js_1.BaseChatGoogleVertexAI {
17
+ static lc_name() {
18
+ return "ChatVertexAI";
19
+ }
20
+ get lc_secrets() {
21
+ return {
22
+ "authOptions.credentials": "GOOGLE_VERTEX_AI_WEB_CREDENTIALS",
23
+ };
24
+ }
25
+ constructor(fields) {
26
+ super(fields);
27
+ const client = new googlevertexai_webauth_js_1.WebGoogleAuth(fields?.authOptions);
28
+ this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller, client);
29
+ }
30
+ }
31
+ exports.ChatGoogleVertexAI = ChatGoogleVertexAI;
32
+ var common_js_2 = require("./common.cjs");
33
+ Object.defineProperty(exports, "GoogleVertexAIChatMessage", { enumerable: true, get: function () { return common_js_2.GoogleVertexAIChatMessage; } });
@@ -0,0 +1,19 @@
1
+ import { WebGoogleAuthOptions } from "../../util/googlevertexai-webauth.js";
2
+ import { BaseChatGoogleVertexAI, GoogleVertexAIChatInput } from "./common.js";
3
+ /**
4
+ * Enables calls to the Google Cloud's Vertex AI API to access
5
+ * Large Language Models in a chat-like fashion.
6
+ *
7
+ * This entrypoint and class are intended to be used in web environments like Edge
8
+ * functions where you do not have access to the file system. It supports passing
9
+ * service account credentials directly as a "GOOGLE_VERTEX_AI_WEB_CREDENTIALS"
10
+ * environment variable or directly as "authOptions.credentials".
11
+ */
12
+ export declare class ChatGoogleVertexAI extends BaseChatGoogleVertexAI<WebGoogleAuthOptions> {
13
+ static lc_name(): string;
14
+ get lc_secrets(): {
15
+ [key: string]: string;
16
+ };
17
+ constructor(fields?: GoogleVertexAIChatInput<WebGoogleAuthOptions>);
18
+ }
19
+ export { ChatExample, GoogleVertexAIChatAuthor, GoogleVertexAIChatInput, GoogleVertexAIChatInstance, GoogleVertexAIChatMessage, GoogleVertexAIChatMessageFields, GoogleVertexAIChatPrediction, } from "./common.js";
@@ -0,0 +1,28 @@
1
+ import { GoogleVertexAILLMConnection } from "../../util/googlevertexai-connection.js";
2
+ import { WebGoogleAuth, } from "../../util/googlevertexai-webauth.js";
3
+ import { BaseChatGoogleVertexAI } from "./common.js";
4
+ /**
5
+ * Enables calls to the Google Cloud's Vertex AI API to access
6
+ * Large Language Models in a chat-like fashion.
7
+ *
8
+ * This entrypoint and class are intended to be used in web environments like Edge
9
+ * functions where you do not have access to the file system. It supports passing
10
+ * service account credentials directly as a "GOOGLE_VERTEX_AI_WEB_CREDENTIALS"
11
+ * environment variable or directly as "authOptions.credentials".
12
+ */
13
+ export class ChatGoogleVertexAI extends BaseChatGoogleVertexAI {
14
+ static lc_name() {
15
+ return "ChatVertexAI";
16
+ }
17
+ get lc_secrets() {
18
+ return {
19
+ "authOptions.credentials": "GOOGLE_VERTEX_AI_WEB_CREDENTIALS",
20
+ };
21
+ }
22
+ constructor(fields) {
23
+ super(fields);
24
+ const client = new WebGoogleAuth(fields?.authOptions);
25
+ this.connection = new GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller, client);
26
+ }
27
+ }
28
+ export { GoogleVertexAIChatMessage, } from "./common.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotionAPILoader = void 0;
3
+ exports.NotionAPILoader = exports.isDatabase = exports.isPage = exports.isErrorResponse = exports.isDatabaseResponse = exports.isPageResponse = void 0;
4
4
  const client_1 = require("@notionhq/client");
5
5
  const notion_to_md_1 = require("notion-to-md");
6
6
  const notion_js_1 = require("notion-to-md/build/utils/notion.js");
@@ -8,18 +8,15 @@ const document_js_1 = require("../../document.cjs");
8
8
  const base_js_1 = require("../base.cjs");
9
9
  const async_caller_js_1 = require("../../util/async_caller.cjs");
10
10
  const isPageResponse = (res) => !(0, client_1.isNotionClientError)(res) && res.object === "page";
11
+ exports.isPageResponse = isPageResponse;
11
12
  const isDatabaseResponse = (res) => !(0, client_1.isNotionClientError)(res) && res.object === "database";
13
+ exports.isDatabaseResponse = isDatabaseResponse;
12
14
  const isErrorResponse = (res) => (0, client_1.isNotionClientError)(res);
13
- const isPage = (res) => isPageResponse(res) && (0, client_1.isFullPage)(res);
14
- const isDatabase = (res) => isDatabaseResponse(res) && (0, client_1.isFullDatabase)(res);
15
- const getTitle = (obj) => {
16
- if (isPage(obj) && obj.properties.title.type === "title") {
17
- return obj.properties.title.title[0]?.plain_text;
18
- }
19
- if (isDatabase(obj))
20
- return obj.title[0]?.plain_text;
21
- return null;
22
- };
15
+ exports.isErrorResponse = isErrorResponse;
16
+ const isPage = (res) => (0, exports.isPageResponse)(res) && (0, client_1.isFullPage)(res);
17
+ exports.isPage = isPage;
18
+ const isDatabase = (res) => (0, exports.isDatabaseResponse)(res) && (0, client_1.isFullDatabase)(res);
19
+ exports.isDatabase = isDatabase;
23
20
  /**
24
21
  * A class that extends the BaseDocumentLoader class. It represents a
25
22
  * document loader for loading documents from Notion using the Notion API.
@@ -107,11 +104,85 @@ class NotionAPILoader extends base_js_1.BaseDocumentLoader {
107
104
  this.rootTitle = "";
108
105
  this.onDocumentLoaded = options.onDocumentLoaded ?? ((_ti, _cu) => { });
109
106
  }
107
+ /**
108
+ * Adds a selection of page ids to the pageQueue and removes duplicates.
109
+ * @param items An array of string ids
110
+ */
110
111
  addToQueue(...items) {
111
112
  const deDuped = items.filter((item) => !this.pageCompleted.concat(this.pageQueue).includes(item));
112
113
  this.pageQueue.push(...deDuped);
113
114
  this.pageQueueTotal += deDuped.length;
114
115
  }
116
+ /**
117
+ * Parses a Notion GetResponse object (page or database) and returns a string of the title.
118
+ * @param obj The Notion GetResponse object to parse.
119
+ * @returns The string of the title.
120
+ */
121
+ getTitle(obj) {
122
+ if ((0, exports.isPage)(obj) && obj.properties.title.type === "title") {
123
+ return obj.properties.title.title[0]?.plain_text;
124
+ }
125
+ if ((0, exports.isDatabase)(obj))
126
+ return obj.title[0]?.plain_text;
127
+ return null;
128
+ }
129
+ /**
130
+ * Parses the property type and returns a string
131
+ * @param page The Notion page property to parse.
132
+ * @returns A string of parsed property.
133
+ */
134
+ getPropValue(prop) {
135
+ switch (prop.type) {
136
+ case "number": {
137
+ const propNumber = prop[prop.type];
138
+ return propNumber !== null ? propNumber.toString() : "";
139
+ }
140
+ case "url":
141
+ return prop[prop.type] || "";
142
+ case "select":
143
+ return prop[prop.type]?.name ?? "";
144
+ case "multi_select":
145
+ return `[${prop[prop.type].map((v) => `"${v.name}"`).join(", ")}]`;
146
+ case "status":
147
+ return prop[prop.type]?.name ?? "";
148
+ case "date":
149
+ return `${prop[prop.type]?.start ?? ""}${prop[prop.type]?.end ? ` - ${prop[prop.type]?.end}` : ""}`;
150
+ case "email":
151
+ return prop[prop.type] || "";
152
+ case "phone_number":
153
+ return prop[prop.type] || "";
154
+ case "checkbox":
155
+ return prop[prop.type].toString();
156
+ case "files":
157
+ return `[${prop[prop.type].map((v) => `"${v.name}"`).join(", ")}]`;
158
+ case "created_by":
159
+ return `["${prop[prop.type].object}", "${prop[prop.type].id}"]`;
160
+ case "created_time":
161
+ return prop[prop.type];
162
+ case "last_edited_by":
163
+ return `["${prop[prop.type].object}", "${prop[prop.type].id}"]`;
164
+ case "last_edited_time":
165
+ return prop[prop.type];
166
+ case "title":
167
+ return prop[prop.type]
168
+ .map((v) => this.n2mClient.annotatePlainText(v.plain_text, v.annotations))
169
+ .join("");
170
+ case "rich_text":
171
+ return prop[prop.type]
172
+ .map((v) => this.n2mClient.annotatePlainText(v.plain_text, v.annotations))
173
+ .join("");
174
+ case "people":
175
+ return `[${prop[prop.type]
176
+ .map((v) => `["${v.object}", "${v.id}"]`)
177
+ .join(", ")}]`;
178
+ case "unique_id":
179
+ return `${prop[prop.type].prefix || ""}${prop[prop.type].number}`;
180
+ case "relation":
181
+ return `[${prop[prop.type].map((v) => `"${v.id}"`).join(", ")}]`;
182
+ default:
183
+ return `Unsupported type: ${prop.type}`;
184
+ }
185
+ }
115
186
  /**
116
187
  * Parses the properties of a Notion page and returns them as key-value
117
188
  * pairs.
@@ -119,60 +190,11 @@ class NotionAPILoader extends base_js_1.BaseDocumentLoader {
119
190
  * @returns An object containing the parsed properties as key-value pairs.
120
191
  */
121
192
  parsePageProperties(page) {
122
- return Object.fromEntries(Object.entries(page.properties).map(([_, prop]) => {
123
- switch (prop.type) {
124
- case "number":
125
- return [prop.type, prop[prop.type]];
126
- case "url":
127
- return [prop.type, prop[prop.type]];
128
- case "select":
129
- return [prop.type, prop[prop.type]?.name ?? ""];
130
- case "multi_select":
131
- return [
132
- prop.type,
133
- prop[prop.type].map((select) => select.name).join(", "),
134
- ];
135
- case "status":
136
- return [prop.type, prop[prop.type]?.name ?? ""];
137
- case "date":
138
- return [
139
- prop.type,
140
- `${prop[prop.type]?.start ?? ""}${prop[prop.type]?.end ? `- ${prop[prop.type]?.end}` : ""}`,
141
- ];
142
- case "email":
143
- return [prop.type, prop[prop.type]];
144
- case "phone_number":
145
- return [prop.type, prop[prop.type]];
146
- case "checkbox":
147
- return [prop.type, prop[prop.type].toString()];
148
- // case "files":
149
- case "created_by":
150
- return [prop.type, prop[prop.type]];
151
- case "created_time":
152
- return [prop.type, prop[prop.type]];
153
- case "last_edited_by":
154
- return [prop.type, prop[prop.type]];
155
- case "last_edited_time":
156
- return [prop.type, prop[prop.type]];
157
- // case "formula":
158
- case "title":
159
- return [
160
- prop.type,
161
- prop[prop.type].map((v) => v.plain_text).join(""),
162
- ];
163
- case "rich_text":
164
- return [
165
- prop.type,
166
- prop[prop.type].map((v) => v.plain_text).join(""),
167
- ];
168
- case "people":
169
- return [prop.type, prop[prop.type]];
170
- // case "relation":
171
- // case "rollup":
172
- default:
173
- return [prop.type, "Unsupported type"];
174
- }
175
- }));
193
+ return Object.entries(page.properties).reduce((accum, [propName, prop]) => {
194
+ const value = this.getPropValue(prop);
195
+ const props = { ...accum, [propName]: value };
196
+ return prop.type === "title" ? { ...props, _title: value } : props;
197
+ }, {});
176
198
  }
177
199
  /**
178
200
  * Parses the details of a Notion page and returns them as an object.
@@ -180,10 +202,10 @@ class NotionAPILoader extends base_js_1.BaseDocumentLoader {
180
202
  * @returns An object containing the parsed details of the page.
181
203
  */
182
204
  parsePageDetails(page) {
183
- const metadata = Object.fromEntries(Object.entries(page).filter(([key, _]) => key !== "id"));
205
+ const { id, ...rest } = page;
184
206
  return {
185
- ...metadata,
186
- notionId: page.id,
207
+ ...rest,
208
+ notionId: id,
187
209
  properties: this.parsePageProperties(page),
188
210
  };
189
211
  }
@@ -306,7 +328,7 @@ class NotionAPILoader extends base_js_1.BaseDocumentLoader {
306
328
  resDatabasePromise,
307
329
  ]);
308
330
  // Check if both resPage and resDatabase resulted in error responses
309
- const errors = [resPage, resDatabase].filter(isErrorResponse);
331
+ const errors = [resPage, resDatabase].filter(exports.isErrorResponse);
310
332
  if (errors.length === 2) {
311
333
  if (errors.every((e) => e.code === client_1.APIErrorCode.ObjectNotFound)) {
312
334
  throw new AggregateError([
@@ -316,7 +338,8 @@ class NotionAPILoader extends base_js_1.BaseDocumentLoader {
316
338
  }
317
339
  throw new AggregateError(errors);
318
340
  }
319
- this.rootTitle = getTitle(resPage) || getTitle(resDatabase) || this.id;
341
+ this.rootTitle =
342
+ this.getTitle(resPage) || this.getTitle(resDatabase) || this.id;
320
343
  let pageId = this.pageQueue.shift();
321
344
  while (pageId) {
322
345
  await this.loadPage(pageId);
@@ -1,7 +1,22 @@
1
- import { Client } from "@notionhq/client";
1
+ import { APIResponseError, Client, isFullBlock, isFullPage, isFullDatabase } from "@notionhq/client";
2
2
  import { Document } from "../../document.js";
3
3
  import { BaseDocumentLoader } from "../base.js";
4
4
  import { AsyncCaller } from "../../util/async_caller.js";
5
+ type GuardType<T> = T extends (x: any, ...rest: any) => x is infer U ? U : never;
6
+ export type GetBlockResponse = Parameters<typeof isFullBlock>[0];
7
+ export type GetPageResponse = Parameters<typeof isFullPage>[0];
8
+ export type GetDatabaseResponse = Parameters<typeof isFullDatabase>[0];
9
+ export type BlockObjectResponse = GuardType<typeof isFullBlock>;
10
+ export type PageObjectResponse = GuardType<typeof isFullPage>;
11
+ export type DatabaseObjectResponse = GuardType<typeof isFullDatabase>;
12
+ export type GetResponse = GetBlockResponse | GetPageResponse | GetDatabaseResponse | APIResponseError;
13
+ export type PagePropertiesType = PageObjectResponse["properties"];
14
+ export type PagePropertiesValue = PagePropertiesType[keyof PagePropertiesType];
15
+ export declare const isPageResponse: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").PageObjectResponse | import("@notionhq/client/build/src/api-endpoints.js").PartialPageObjectResponse;
16
+ export declare const isDatabaseResponse: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").DatabaseObjectResponse | import("@notionhq/client/build/src/api-endpoints.js").PartialDatabaseObjectResponse;
17
+ export declare const isErrorResponse: (res: GetResponse) => res is APIResponseError;
18
+ export declare const isPage: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").PageObjectResponse;
19
+ export declare const isDatabase: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").DatabaseObjectResponse;
5
20
  /**
6
21
  * Represents the type of Notion API to load documents from. The options
7
22
  * are "database" or "page".
@@ -31,7 +46,23 @@ export declare class NotionAPILoader extends BaseDocumentLoader {
31
46
  private rootTitle;
32
47
  private onDocumentLoaded;
33
48
  constructor(options: NotionAPILoaderOptions);
49
+ /**
50
+ * Adds a selection of page ids to the pageQueue and removes duplicates.
51
+ * @param items An array of string ids
52
+ */
34
53
  private addToQueue;
54
+ /**
55
+ * Parses a Notion GetResponse object (page or database) and returns a string of the title.
56
+ * @param obj The Notion GetResponse object to parse.
57
+ * @returns The string of the title.
58
+ */
59
+ private getTitle;
60
+ /**
61
+ * Parses the property type and returns a string
62
+ * @param page The Notion page property to parse.
63
+ * @returns A string of parsed property.
64
+ */
65
+ private getPropValue;
35
66
  /**
36
67
  * Parses the properties of a Notion page and returns them as key-value
37
68
  * pairs.
@@ -73,3 +104,4 @@ export declare class NotionAPILoader extends BaseDocumentLoader {
73
104
  */
74
105
  load(): Promise<Document[]>;
75
106
  }
107
+ export {};