langchain 0.0.147 → 0.0.149

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 (141) 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/chains/question_answering/load.cjs +12 -4
  10. package/dist/chains/question_answering/load.d.ts +2 -0
  11. package/dist/chains/question_answering/load.js +12 -4
  12. package/dist/chains/summarization/load.cjs +8 -4
  13. package/dist/chains/summarization/load.d.ts +2 -0
  14. package/dist/chains/summarization/load.js +8 -4
  15. package/dist/chat_models/{googlevertexai.cjs → googlevertexai/common.cjs} +14 -26
  16. package/dist/chat_models/{googlevertexai.d.ts → googlevertexai/common.d.ts} +13 -22
  17. package/dist/chat_models/{googlevertexai.js → googlevertexai/common.js} +12 -24
  18. package/dist/chat_models/googlevertexai/index.cjs +36 -0
  19. package/dist/chat_models/googlevertexai/index.d.ts +21 -0
  20. package/dist/chat_models/googlevertexai/index.js +31 -0
  21. package/dist/chat_models/googlevertexai/web.cjs +33 -0
  22. package/dist/chat_models/googlevertexai/web.d.ts +19 -0
  23. package/dist/chat_models/googlevertexai/web.js +28 -0
  24. package/dist/document_loaders/web/notionapi.cjs +93 -70
  25. package/dist/document_loaders/web/notionapi.d.ts +33 -1
  26. package/dist/document_loaders/web/notionapi.js +89 -71
  27. package/dist/embeddings/googlevertexai.cjs +5 -1
  28. package/dist/embeddings/googlevertexai.d.ts +2 -1
  29. package/dist/embeddings/googlevertexai.js +5 -1
  30. package/dist/evaluation/agents/index.cjs +17 -0
  31. package/dist/evaluation/agents/index.d.ts +1 -0
  32. package/dist/evaluation/agents/index.js +1 -0
  33. package/dist/evaluation/agents/prompt.cjs +132 -0
  34. package/dist/evaluation/agents/prompt.d.ts +6 -0
  35. package/dist/evaluation/agents/prompt.js +129 -0
  36. package/dist/evaluation/agents/trajectory.cjs +189 -0
  37. package/dist/evaluation/agents/trajectory.d.ts +54 -0
  38. package/dist/evaluation/agents/trajectory.js +184 -0
  39. package/dist/evaluation/base.cjs +274 -0
  40. package/dist/evaluation/base.d.ts +232 -0
  41. package/dist/evaluation/base.js +263 -0
  42. package/dist/evaluation/comparison/index.cjs +17 -0
  43. package/dist/evaluation/comparison/index.d.ts +1 -0
  44. package/dist/evaluation/comparison/index.js +1 -0
  45. package/dist/evaluation/comparison/pairwise.cjs +244 -0
  46. package/dist/evaluation/comparison/pairwise.d.ts +50 -0
  47. package/dist/evaluation/comparison/pairwise.js +238 -0
  48. package/dist/evaluation/comparison/prompt.cjs +74 -0
  49. package/dist/evaluation/comparison/prompt.d.ts +21 -0
  50. package/dist/evaluation/comparison/prompt.js +71 -0
  51. package/dist/evaluation/criteria/criteria.cjs +259 -0
  52. package/dist/evaluation/criteria/criteria.d.ts +73 -0
  53. package/dist/evaluation/criteria/criteria.js +253 -0
  54. package/dist/evaluation/criteria/index.cjs +17 -0
  55. package/dist/evaluation/criteria/index.d.ts +1 -0
  56. package/dist/evaluation/criteria/index.js +1 -0
  57. package/dist/evaluation/criteria/prompt.cjs +36 -0
  58. package/dist/evaluation/criteria/prompt.d.ts +12 -0
  59. package/dist/evaluation/criteria/prompt.js +33 -0
  60. package/dist/evaluation/embedding_distance/base.cjs +163 -0
  61. package/dist/evaluation/embedding_distance/base.d.ts +78 -0
  62. package/dist/evaluation/embedding_distance/base.js +156 -0
  63. package/dist/evaluation/embedding_distance/index.cjs +17 -0
  64. package/dist/evaluation/embedding_distance/index.d.ts +1 -0
  65. package/dist/evaluation/embedding_distance/index.js +1 -0
  66. package/dist/evaluation/index.cjs +6 -0
  67. package/dist/evaluation/index.d.ts +6 -0
  68. package/dist/evaluation/index.js +6 -0
  69. package/dist/evaluation/loader.cjs +60 -0
  70. package/dist/evaluation/loader.d.ts +27 -0
  71. package/dist/evaluation/loader.js +56 -0
  72. package/dist/evaluation/types.cjs +2 -0
  73. package/dist/evaluation/types.d.ts +35 -0
  74. package/dist/evaluation/types.js +1 -0
  75. package/dist/experimental/multimodal_embeddings/googlevertexai.cjs +5 -1
  76. package/dist/experimental/multimodal_embeddings/googlevertexai.d.ts +2 -1
  77. package/dist/experimental/multimodal_embeddings/googlevertexai.js +5 -1
  78. package/dist/llms/bedrock.cjs +9 -1
  79. package/dist/llms/bedrock.d.ts +3 -0
  80. package/dist/llms/bedrock.js +9 -1
  81. package/dist/llms/{googlevertexai.js → googlevertexai/common.cjs} +21 -17
  82. package/dist/llms/{googlevertexai.d.ts → googlevertexai/common.d.ts} +13 -23
  83. package/dist/llms/{googlevertexai.cjs → googlevertexai/common.js} +17 -21
  84. package/dist/llms/googlevertexai/index.cjs +34 -0
  85. package/dist/llms/googlevertexai/index.d.ts +26 -0
  86. package/dist/llms/googlevertexai/index.js +30 -0
  87. package/dist/llms/googlevertexai/web.cjs +31 -0
  88. package/dist/llms/googlevertexai/web.d.ts +24 -0
  89. package/dist/llms/googlevertexai/web.js +27 -0
  90. package/dist/load/import_constants.cjs +2 -0
  91. package/dist/load/import_constants.js +2 -0
  92. package/dist/load/import_map.cjs +2 -1
  93. package/dist/load/import_map.d.ts +1 -0
  94. package/dist/load/import_map.js +1 -0
  95. package/dist/load/serializable.cjs +23 -4
  96. package/dist/load/serializable.js +23 -4
  97. package/dist/retrievers/multi_query.cjs +140 -0
  98. package/dist/retrievers/multi_query.d.ts +33 -0
  99. package/dist/retrievers/multi_query.js +136 -0
  100. package/dist/retrievers/self_query/base.cjs +1 -1
  101. package/dist/retrievers/self_query/base.js +2 -2
  102. package/dist/retrievers/self_query/functional.cjs +1 -1
  103. package/dist/retrievers/self_query/functional.js +2 -2
  104. package/dist/retrievers/self_query/utils.cjs +46 -6
  105. package/dist/retrievers/self_query/utils.d.ts +7 -0
  106. package/dist/retrievers/self_query/utils.js +44 -5
  107. package/dist/schema/runnable/base.cjs +910 -0
  108. package/dist/schema/runnable/base.d.ts +300 -0
  109. package/dist/schema/runnable/base.js +896 -0
  110. package/dist/schema/runnable/index.cjs +19 -926
  111. package/dist/schema/runnable/index.d.ts +4 -298
  112. package/dist/schema/runnable/index.js +3 -914
  113. package/dist/schema/runnable/passthrough.cjs +31 -0
  114. package/dist/schema/runnable/passthrough.d.ts +11 -0
  115. package/dist/schema/runnable/passthrough.js +27 -0
  116. package/dist/schema/runnable/router.cjs +74 -0
  117. package/dist/schema/runnable/router.d.ts +29 -0
  118. package/dist/schema/runnable/router.js +70 -0
  119. package/dist/types/googlevertexai-types.d.ts +11 -4
  120. package/dist/util/googlevertexai-connection.cjs +14 -15
  121. package/dist/util/googlevertexai-connection.d.ts +7 -7
  122. package/dist/util/googlevertexai-connection.js +14 -15
  123. package/dist/util/googlevertexai-webauth.cjs +56 -0
  124. package/dist/util/googlevertexai-webauth.d.ts +25 -0
  125. package/dist/util/googlevertexai-webauth.js +52 -0
  126. package/dist/vectorstores/googlevertexai.cjs +9 -8
  127. package/dist/vectorstores/googlevertexai.d.ts +8 -7
  128. package/dist/vectorstores/googlevertexai.js +9 -8
  129. package/dist/vectorstores/opensearch.cjs +4 -2
  130. package/dist/vectorstores/opensearch.d.ts +4 -1
  131. package/dist/vectorstores/opensearch.js +4 -2
  132. package/llms/googlevertexai/web.cjs +1 -0
  133. package/llms/googlevertexai/web.d.ts +1 -0
  134. package/llms/googlevertexai/web.js +1 -0
  135. package/llms/googlevertexai.cjs +1 -1
  136. package/llms/googlevertexai.d.ts +1 -1
  137. package/llms/googlevertexai.js +1 -1
  138. package/package.json +32 -3
  139. package/retrievers/multi_query.cjs +1 -0
  140. package/retrievers/multi_query.d.ts +1 -0
  141. package/retrievers/multi_query.js +1 -0
@@ -35,6 +35,7 @@ export interface MapReduceQAChainParams {
35
35
  returnIntermediateSteps?: MapReduceDocumentsChainInput["returnIntermediateSteps"];
36
36
  combineMapPrompt?: BasePromptTemplate;
37
37
  combinePrompt?: BasePromptTemplate;
38
+ combineLLM?: BaseLanguageModel;
38
39
  verbose?: boolean;
39
40
  }
40
41
  /**
@@ -51,6 +52,7 @@ export declare function loadQAMapReduceChain(llm: BaseLanguageModel, params?: Ma
51
52
  export interface RefineQAChainParams {
52
53
  questionPrompt?: BasePromptTemplate;
53
54
  refinePrompt?: BasePromptTemplate;
55
+ refineLLM?: BaseLanguageModel;
54
56
  verbose?: boolean;
55
57
  }
56
58
  /**
@@ -37,9 +37,13 @@ export function loadQAStuffChain(llm, params = {}) {
37
37
  * @returns A MapReduceQAChain instance.
38
38
  */
39
39
  export function loadQAMapReduceChain(llm, params = {}) {
40
- const { combineMapPrompt = COMBINE_QA_PROMPT_SELECTOR.getPrompt(llm), combinePrompt = COMBINE_PROMPT_SELECTOR.getPrompt(llm), verbose, returnIntermediateSteps, } = params;
40
+ const { combineMapPrompt = COMBINE_QA_PROMPT_SELECTOR.getPrompt(llm), combinePrompt = COMBINE_PROMPT_SELECTOR.getPrompt(llm), verbose, combineLLM, returnIntermediateSteps, } = params;
41
41
  const llmChain = new LLMChain({ prompt: combineMapPrompt, llm, verbose });
42
- const combineLLMChain = new LLMChain({ prompt: combinePrompt, llm, verbose });
42
+ const combineLLMChain = new LLMChain({
43
+ prompt: combinePrompt,
44
+ llm: combineLLM ?? llm,
45
+ verbose,
46
+ });
43
47
  const combineDocumentChain = new StuffDocumentsChain({
44
48
  llmChain: combineLLMChain,
45
49
  documentVariableName: "summaries",
@@ -61,9 +65,13 @@ export function loadQAMapReduceChain(llm, params = {}) {
61
65
  * @returns A RefineQAChain instance.
62
66
  */
63
67
  export function loadQARefineChain(llm, params = {}) {
64
- const { questionPrompt = QUESTION_PROMPT_SELECTOR.getPrompt(llm), refinePrompt = REFINE_PROMPT_SELECTOR.getPrompt(llm), verbose, } = params;
68
+ const { questionPrompt = QUESTION_PROMPT_SELECTOR.getPrompt(llm), refinePrompt = REFINE_PROMPT_SELECTOR.getPrompt(llm), refineLLM, verbose, } = params;
65
69
  const llmChain = new LLMChain({ prompt: questionPrompt, llm, verbose });
66
- const refineLLMChain = new LLMChain({ prompt: refinePrompt, llm, verbose });
70
+ const refineLLMChain = new LLMChain({
71
+ prompt: refinePrompt,
72
+ llm: refineLLM ?? llm,
73
+ verbose,
74
+ });
67
75
  const chain = new RefineDocumentsChain({
68
76
  llmChain,
69
77
  refineLLMChain,
@@ -18,11 +18,11 @@ const loadSummarizationChain = (llm, params = { type: "map_reduce" }) => {
18
18
  return chain;
19
19
  }
20
20
  if (params.type === "map_reduce") {
21
- const { combineMapPrompt = stuff_prompts_js_1.DEFAULT_PROMPT, combinePrompt = stuff_prompts_js_1.DEFAULT_PROMPT, returnIntermediateSteps, } = params;
21
+ const { combineMapPrompt = stuff_prompts_js_1.DEFAULT_PROMPT, combinePrompt = stuff_prompts_js_1.DEFAULT_PROMPT, combineLLM, returnIntermediateSteps, } = params;
22
22
  const llmChain = new llm_chain_js_1.LLMChain({ prompt: combineMapPrompt, llm, verbose });
23
23
  const combineLLMChain = new llm_chain_js_1.LLMChain({
24
24
  prompt: combinePrompt,
25
- llm,
25
+ llm: combineLLM ?? llm,
26
26
  verbose,
27
27
  });
28
28
  const combineDocumentChain = new combine_docs_chain_js_1.StuffDocumentsChain({
@@ -40,9 +40,13 @@ const loadSummarizationChain = (llm, params = { type: "map_reduce" }) => {
40
40
  return chain;
41
41
  }
42
42
  if (params.type === "refine") {
43
- const { refinePrompt = refine_prompts_js_1.REFINE_PROMPT, questionPrompt = stuff_prompts_js_1.DEFAULT_PROMPT } = params;
43
+ const { refinePrompt = refine_prompts_js_1.REFINE_PROMPT, refineLLM, questionPrompt = stuff_prompts_js_1.DEFAULT_PROMPT, } = params;
44
44
  const llmChain = new llm_chain_js_1.LLMChain({ prompt: questionPrompt, llm, verbose });
45
- const refineLLMChain = new llm_chain_js_1.LLMChain({ prompt: refinePrompt, llm, verbose });
45
+ const refineLLMChain = new llm_chain_js_1.LLMChain({
46
+ prompt: refinePrompt,
47
+ llm: refineLLM ?? llm,
48
+ verbose,
49
+ });
46
50
  const chain = new combine_docs_chain_js_1.RefineDocumentsChain({
47
51
  llmChain,
48
52
  refineLLMChain,
@@ -16,9 +16,11 @@ export type SummarizationChainParams = BaseParams & ({
16
16
  type?: "map_reduce";
17
17
  combineMapPrompt?: BasePromptTemplate;
18
18
  combinePrompt?: BasePromptTemplate;
19
+ combineLLM?: BaseLanguageModel;
19
20
  } & Pick<MapReduceDocumentsChainInput, "returnIntermediateSteps">) | {
20
21
  type?: "refine";
21
22
  refinePrompt?: BasePromptTemplate;
23
+ refineLLM?: BaseLanguageModel;
22
24
  questionPrompt?: BasePromptTemplate;
23
25
  });
24
26
  export declare const loadSummarizationChain: (llm: BaseLanguageModel, params?: SummarizationChainParams) => StuffDocumentsChain | MapReduceDocumentsChain | RefineDocumentsChain;
@@ -15,11 +15,11 @@ export const loadSummarizationChain = (llm, params = { type: "map_reduce" }) =>
15
15
  return chain;
16
16
  }
17
17
  if (params.type === "map_reduce") {
18
- const { combineMapPrompt = DEFAULT_PROMPT, combinePrompt = DEFAULT_PROMPT, returnIntermediateSteps, } = params;
18
+ const { combineMapPrompt = DEFAULT_PROMPT, combinePrompt = DEFAULT_PROMPT, combineLLM, returnIntermediateSteps, } = params;
19
19
  const llmChain = new LLMChain({ prompt: combineMapPrompt, llm, verbose });
20
20
  const combineLLMChain = new LLMChain({
21
21
  prompt: combinePrompt,
22
- llm,
22
+ llm: combineLLM ?? llm,
23
23
  verbose,
24
24
  });
25
25
  const combineDocumentChain = new StuffDocumentsChain({
@@ -37,9 +37,13 @@ export const loadSummarizationChain = (llm, params = { type: "map_reduce" }) =>
37
37
  return chain;
38
38
  }
39
39
  if (params.type === "refine") {
40
- const { refinePrompt = REFINE_PROMPT, questionPrompt = DEFAULT_PROMPT } = params;
40
+ const { refinePrompt = REFINE_PROMPT, refineLLM, questionPrompt = DEFAULT_PROMPT, } = params;
41
41
  const llmChain = new LLMChain({ prompt: questionPrompt, llm, verbose });
42
- const refineLLMChain = new LLMChain({ prompt: refinePrompt, llm, verbose });
42
+ const refineLLMChain = new LLMChain({
43
+ prompt: refinePrompt,
44
+ llm: refineLLM ?? llm,
45
+ verbose,
46
+ });
43
47
  const chain = new RefineDocumentsChain({
44
48
  llmChain,
45
49
  refineLLMChain,
@@ -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";