@langchain/google-vertexai 0.0.25 → 0.0.27

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.
@@ -3,8 +3,286 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChatVertexAI = void 0;
4
4
  const google_gauth_1 = require("@langchain/google-gauth");
5
5
  /**
6
- * Integration with a Google Vertex AI chat model using
7
- * the "@langchain/google-gauth" package for auth.
6
+ * Integration with Google Vertex AI chat models.
7
+ *
8
+ * Setup:
9
+ * Install `@langchain/google-vertexai` and set your stringified
10
+ * Vertex AI credentials as an environment variable named `GOOGLE_APPLICATION_CREDENTIALS`.
11
+ *
12
+ * ```bash
13
+ * npm install @langchain/google-vertexai
14
+ * export GOOGLE_APPLICATION_CREDENTIALS="path/to/credentials"
15
+ * ```
16
+ *
17
+ * ## [Constructor args](https://api.js.langchain.com/classes/langchain_community_chat_models_googlevertexai_web.ChatGoogleVertexAI.html#constructor)
18
+ *
19
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_google_common_types.GoogleAIBaseLanguageModelCallOptions.html)
20
+ *
21
+ * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
22
+ * They can also be passed via `.bind`, or the second arg in `.bindTools`, like shown in the examples below:
23
+ *
24
+ * ```typescript
25
+ * // When calling `.bind`, call options should be passed via the first argument
26
+ * const llmWithArgsBound = llm.bind({
27
+ * stop: ["\n"],
28
+ * tools: [...],
29
+ * });
30
+ *
31
+ * // When calling `.bindTools`, call options should be passed via the second argument
32
+ * const llmWithTools = llm.bindTools(
33
+ * [...],
34
+ * {
35
+ * tool_choice: "auto",
36
+ * }
37
+ * );
38
+ * ```
39
+ *
40
+ * ## Examples
41
+ *
42
+ * <details open>
43
+ * <summary><strong>Instantiate</strong></summary>
44
+ *
45
+ * ```typescript
46
+ * import { ChatVertexAI } from '@langchain/google-vertexai';
47
+ *
48
+ * const llm = new ChatVertexAI({
49
+ * model: "gemini-1.5-pro",
50
+ * temperature: 0,
51
+ * // other params...
52
+ * });
53
+ * ```
54
+ * </details>
55
+ *
56
+ * <br />
57
+ *
58
+ * <details>
59
+ * <summary><strong>Invoking</strong></summary>
60
+ *
61
+ * ```typescript
62
+ * const input = `Translate "I love programming" into French.`;
63
+ *
64
+ * // Models also accept a list of chat messages or a formatted prompt
65
+ * const result = await llm.invoke(input);
66
+ * console.log(result);
67
+ * ```
68
+ *
69
+ * ```txt
70
+ * AIMessageChunk {
71
+ * "content": "\"J'adore programmer\" \n\nHere's why this is the best translation:\n\n* **J'adore** means \"I love\" and conveys a strong passion.\n* **Programmer** is the French verb for \"to program.\"\n\nThis translation is natural and idiomatic in French. \n",
72
+ * "additional_kwargs": {},
73
+ * "response_metadata": {},
74
+ * "tool_calls": [],
75
+ * "tool_call_chunks": [],
76
+ * "invalid_tool_calls": [],
77
+ * "usage_metadata": {
78
+ * "input_tokens": 9,
79
+ * "output_tokens": 63,
80
+ * "total_tokens": 72
81
+ * }
82
+ * }
83
+ * ```
84
+ * </details>
85
+ *
86
+ * <br />
87
+ *
88
+ * <details>
89
+ * <summary><strong>Streaming Chunks</strong></summary>
90
+ *
91
+ * ```typescript
92
+ * for await (const chunk of await llm.stream(input)) {
93
+ * console.log(chunk);
94
+ * }
95
+ * ```
96
+ *
97
+ * ```txt
98
+ * AIMessageChunk {
99
+ * "content": "\"",
100
+ * "additional_kwargs": {},
101
+ * "response_metadata": {},
102
+ * "tool_calls": [],
103
+ * "tool_call_chunks": [],
104
+ * "invalid_tool_calls": []
105
+ * }
106
+ * AIMessageChunk {
107
+ * "content": "J'adore programmer\" \n",
108
+ * "additional_kwargs": {},
109
+ * "response_metadata": {},
110
+ * "tool_calls": [],
111
+ * "tool_call_chunks": [],
112
+ * "invalid_tool_calls": []
113
+ * }
114
+ * AIMessageChunk {
115
+ * "content": "",
116
+ * "additional_kwargs": {},
117
+ * "response_metadata": {},
118
+ * "tool_calls": [],
119
+ * "tool_call_chunks": [],
120
+ * "invalid_tool_calls": []
121
+ * }
122
+ * AIMessageChunk {
123
+ * "content": "",
124
+ * "additional_kwargs": {},
125
+ * "response_metadata": {
126
+ * "finishReason": "stop"
127
+ * },
128
+ * "tool_calls": [],
129
+ * "tool_call_chunks": [],
130
+ * "invalid_tool_calls": [],
131
+ * "usage_metadata": {
132
+ * "input_tokens": 9,
133
+ * "output_tokens": 8,
134
+ * "total_tokens": 17
135
+ * }
136
+ * }
137
+ * ```
138
+ * </details>
139
+ *
140
+ * <br />
141
+ *
142
+ * <details>
143
+ * <summary><strong>Aggregate Streamed Chunks</strong></summary>
144
+ *
145
+ * ```typescript
146
+ * import { AIMessageChunk } from '@langchain/core/messages';
147
+ * import { concat } from '@langchain/core/utils/stream';
148
+ *
149
+ * const stream = await llm.stream(input);
150
+ * let full: AIMessageChunk | undefined;
151
+ * for await (const chunk of stream) {
152
+ * full = !full ? chunk : concat(full, chunk);
153
+ * }
154
+ * console.log(full);
155
+ * ```
156
+ *
157
+ * ```txt
158
+ * AIMessageChunk {
159
+ * "content": "\"J'adore programmer\" \n",
160
+ * "additional_kwargs": {},
161
+ * "response_metadata": {
162
+ * "finishReason": "stop"
163
+ * },
164
+ * "tool_calls": [],
165
+ * "tool_call_chunks": [],
166
+ * "invalid_tool_calls": [],
167
+ * "usage_metadata": {
168
+ * "input_tokens": 9,
169
+ * "output_tokens": 8,
170
+ * "total_tokens": 17
171
+ * }
172
+ * }
173
+ * ```
174
+ * </details>
175
+ *
176
+ * <br />
177
+ *
178
+ * <details>
179
+ * <summary><strong>Bind tools</strong></summary>
180
+ *
181
+ * ```typescript
182
+ * import { z } from 'zod';
183
+ *
184
+ * const GetWeather = {
185
+ * name: "GetWeather",
186
+ * description: "Get the current weather in a given location",
187
+ * schema: z.object({
188
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
189
+ * }),
190
+ * }
191
+ *
192
+ * const GetPopulation = {
193
+ * name: "GetPopulation",
194
+ * description: "Get the current population in a given location",
195
+ * schema: z.object({
196
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
197
+ * }),
198
+ * }
199
+ *
200
+ * const llmWithTools = llm.bindTools([GetWeather, GetPopulation]);
201
+ * const aiMsg = await llmWithTools.invoke(
202
+ * "Which city is hotter today and which is bigger: LA or NY?"
203
+ * );
204
+ * console.log(aiMsg.tool_calls);
205
+ * ```
206
+ *
207
+ * ```txt
208
+ * [
209
+ * {
210
+ * name: 'GetPopulation',
211
+ * args: { location: 'New York City, NY' },
212
+ * id: '33c1c1f47e2f492799c77d2800a43912',
213
+ * type: 'tool_call'
214
+ * }
215
+ * ]
216
+ * ```
217
+ * </details>
218
+ *
219
+ * <br />
220
+ *
221
+ * <details>
222
+ * <summary><strong>Structured Output</strong></summary>
223
+ *
224
+ * ```typescript
225
+ * import { z } from 'zod';
226
+ *
227
+ * const Joke = z.object({
228
+ * setup: z.string().describe("The setup of the joke"),
229
+ * punchline: z.string().describe("The punchline to the joke"),
230
+ * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
231
+ * }).describe('Joke to tell user.');
232
+ *
233
+ * const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
234
+ * const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
235
+ * console.log(jokeResult);
236
+ * ```
237
+ *
238
+ * ```txt
239
+ * {
240
+ * setup: 'What do you call a cat that loves to bowl?',
241
+ * punchline: 'An alley cat!'
242
+ * }
243
+ * ```
244
+ * </details>
245
+ *
246
+ * <br />
247
+ *
248
+ * <details>
249
+ * <summary><strong>Usage Metadata</strong></summary>
250
+ *
251
+ * ```typescript
252
+ * const aiMsgForMetadata = await llm.invoke(input);
253
+ * console.log(aiMsgForMetadata.usage_metadata);
254
+ * ```
255
+ *
256
+ * ```txt
257
+ * { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
258
+ * ```
259
+ * </details>
260
+ *
261
+ * <br />
262
+ *
263
+ * <details>
264
+ * <summary><strong>Stream Usage Metadata</strong></summary>
265
+ *
266
+ * ```typescript
267
+ * const streamForMetadata = await llm.stream(
268
+ * input,
269
+ * {
270
+ * streamUsage: true
271
+ * }
272
+ * );
273
+ * let fullForMetadata: AIMessageChunk | undefined;
274
+ * for await (const chunk of streamForMetadata) {
275
+ * fullForMetadata = !fullForMetadata ? chunk : concat(fullForMetadata, chunk);
276
+ * }
277
+ * console.log(fullForMetadata?.usage_metadata);
278
+ * ```
279
+ *
280
+ * ```txt
281
+ * { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
282
+ * ```
283
+ * </details>
284
+ *
285
+ * <br />
8
286
  */
9
287
  class ChatVertexAI extends google_gauth_1.ChatGoogle {
10
288
  static lc_name() {
@@ -5,8 +5,286 @@ import { type ChatGoogleInput, ChatGoogle } from "@langchain/google-gauth";
5
5
  export interface ChatVertexAIInput extends ChatGoogleInput {
6
6
  }
7
7
  /**
8
- * Integration with a Google Vertex AI chat model using
9
- * the "@langchain/google-gauth" package for auth.
8
+ * Integration with Google Vertex AI chat models.
9
+ *
10
+ * Setup:
11
+ * Install `@langchain/google-vertexai` and set your stringified
12
+ * Vertex AI credentials as an environment variable named `GOOGLE_APPLICATION_CREDENTIALS`.
13
+ *
14
+ * ```bash
15
+ * npm install @langchain/google-vertexai
16
+ * export GOOGLE_APPLICATION_CREDENTIALS="path/to/credentials"
17
+ * ```
18
+ *
19
+ * ## [Constructor args](https://api.js.langchain.com/classes/langchain_community_chat_models_googlevertexai_web.ChatGoogleVertexAI.html#constructor)
20
+ *
21
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_google_common_types.GoogleAIBaseLanguageModelCallOptions.html)
22
+ *
23
+ * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
24
+ * They can also be passed via `.bind`, or the second arg in `.bindTools`, like shown in the examples below:
25
+ *
26
+ * ```typescript
27
+ * // When calling `.bind`, call options should be passed via the first argument
28
+ * const llmWithArgsBound = llm.bind({
29
+ * stop: ["\n"],
30
+ * tools: [...],
31
+ * });
32
+ *
33
+ * // When calling `.bindTools`, call options should be passed via the second argument
34
+ * const llmWithTools = llm.bindTools(
35
+ * [...],
36
+ * {
37
+ * tool_choice: "auto",
38
+ * }
39
+ * );
40
+ * ```
41
+ *
42
+ * ## Examples
43
+ *
44
+ * <details open>
45
+ * <summary><strong>Instantiate</strong></summary>
46
+ *
47
+ * ```typescript
48
+ * import { ChatVertexAI } from '@langchain/google-vertexai';
49
+ *
50
+ * const llm = new ChatVertexAI({
51
+ * model: "gemini-1.5-pro",
52
+ * temperature: 0,
53
+ * // other params...
54
+ * });
55
+ * ```
56
+ * </details>
57
+ *
58
+ * <br />
59
+ *
60
+ * <details>
61
+ * <summary><strong>Invoking</strong></summary>
62
+ *
63
+ * ```typescript
64
+ * const input = `Translate "I love programming" into French.`;
65
+ *
66
+ * // Models also accept a list of chat messages or a formatted prompt
67
+ * const result = await llm.invoke(input);
68
+ * console.log(result);
69
+ * ```
70
+ *
71
+ * ```txt
72
+ * AIMessageChunk {
73
+ * "content": "\"J'adore programmer\" \n\nHere's why this is the best translation:\n\n* **J'adore** means \"I love\" and conveys a strong passion.\n* **Programmer** is the French verb for \"to program.\"\n\nThis translation is natural and idiomatic in French. \n",
74
+ * "additional_kwargs": {},
75
+ * "response_metadata": {},
76
+ * "tool_calls": [],
77
+ * "tool_call_chunks": [],
78
+ * "invalid_tool_calls": [],
79
+ * "usage_metadata": {
80
+ * "input_tokens": 9,
81
+ * "output_tokens": 63,
82
+ * "total_tokens": 72
83
+ * }
84
+ * }
85
+ * ```
86
+ * </details>
87
+ *
88
+ * <br />
89
+ *
90
+ * <details>
91
+ * <summary><strong>Streaming Chunks</strong></summary>
92
+ *
93
+ * ```typescript
94
+ * for await (const chunk of await llm.stream(input)) {
95
+ * console.log(chunk);
96
+ * }
97
+ * ```
98
+ *
99
+ * ```txt
100
+ * AIMessageChunk {
101
+ * "content": "\"",
102
+ * "additional_kwargs": {},
103
+ * "response_metadata": {},
104
+ * "tool_calls": [],
105
+ * "tool_call_chunks": [],
106
+ * "invalid_tool_calls": []
107
+ * }
108
+ * AIMessageChunk {
109
+ * "content": "J'adore programmer\" \n",
110
+ * "additional_kwargs": {},
111
+ * "response_metadata": {},
112
+ * "tool_calls": [],
113
+ * "tool_call_chunks": [],
114
+ * "invalid_tool_calls": []
115
+ * }
116
+ * AIMessageChunk {
117
+ * "content": "",
118
+ * "additional_kwargs": {},
119
+ * "response_metadata": {},
120
+ * "tool_calls": [],
121
+ * "tool_call_chunks": [],
122
+ * "invalid_tool_calls": []
123
+ * }
124
+ * AIMessageChunk {
125
+ * "content": "",
126
+ * "additional_kwargs": {},
127
+ * "response_metadata": {
128
+ * "finishReason": "stop"
129
+ * },
130
+ * "tool_calls": [],
131
+ * "tool_call_chunks": [],
132
+ * "invalid_tool_calls": [],
133
+ * "usage_metadata": {
134
+ * "input_tokens": 9,
135
+ * "output_tokens": 8,
136
+ * "total_tokens": 17
137
+ * }
138
+ * }
139
+ * ```
140
+ * </details>
141
+ *
142
+ * <br />
143
+ *
144
+ * <details>
145
+ * <summary><strong>Aggregate Streamed Chunks</strong></summary>
146
+ *
147
+ * ```typescript
148
+ * import { AIMessageChunk } from '@langchain/core/messages';
149
+ * import { concat } from '@langchain/core/utils/stream';
150
+ *
151
+ * const stream = await llm.stream(input);
152
+ * let full: AIMessageChunk | undefined;
153
+ * for await (const chunk of stream) {
154
+ * full = !full ? chunk : concat(full, chunk);
155
+ * }
156
+ * console.log(full);
157
+ * ```
158
+ *
159
+ * ```txt
160
+ * AIMessageChunk {
161
+ * "content": "\"J'adore programmer\" \n",
162
+ * "additional_kwargs": {},
163
+ * "response_metadata": {
164
+ * "finishReason": "stop"
165
+ * },
166
+ * "tool_calls": [],
167
+ * "tool_call_chunks": [],
168
+ * "invalid_tool_calls": [],
169
+ * "usage_metadata": {
170
+ * "input_tokens": 9,
171
+ * "output_tokens": 8,
172
+ * "total_tokens": 17
173
+ * }
174
+ * }
175
+ * ```
176
+ * </details>
177
+ *
178
+ * <br />
179
+ *
180
+ * <details>
181
+ * <summary><strong>Bind tools</strong></summary>
182
+ *
183
+ * ```typescript
184
+ * import { z } from 'zod';
185
+ *
186
+ * const GetWeather = {
187
+ * name: "GetWeather",
188
+ * description: "Get the current weather in a given location",
189
+ * schema: z.object({
190
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
191
+ * }),
192
+ * }
193
+ *
194
+ * const GetPopulation = {
195
+ * name: "GetPopulation",
196
+ * description: "Get the current population in a given location",
197
+ * schema: z.object({
198
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
199
+ * }),
200
+ * }
201
+ *
202
+ * const llmWithTools = llm.bindTools([GetWeather, GetPopulation]);
203
+ * const aiMsg = await llmWithTools.invoke(
204
+ * "Which city is hotter today and which is bigger: LA or NY?"
205
+ * );
206
+ * console.log(aiMsg.tool_calls);
207
+ * ```
208
+ *
209
+ * ```txt
210
+ * [
211
+ * {
212
+ * name: 'GetPopulation',
213
+ * args: { location: 'New York City, NY' },
214
+ * id: '33c1c1f47e2f492799c77d2800a43912',
215
+ * type: 'tool_call'
216
+ * }
217
+ * ]
218
+ * ```
219
+ * </details>
220
+ *
221
+ * <br />
222
+ *
223
+ * <details>
224
+ * <summary><strong>Structured Output</strong></summary>
225
+ *
226
+ * ```typescript
227
+ * import { z } from 'zod';
228
+ *
229
+ * const Joke = z.object({
230
+ * setup: z.string().describe("The setup of the joke"),
231
+ * punchline: z.string().describe("The punchline to the joke"),
232
+ * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
233
+ * }).describe('Joke to tell user.');
234
+ *
235
+ * const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
236
+ * const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
237
+ * console.log(jokeResult);
238
+ * ```
239
+ *
240
+ * ```txt
241
+ * {
242
+ * setup: 'What do you call a cat that loves to bowl?',
243
+ * punchline: 'An alley cat!'
244
+ * }
245
+ * ```
246
+ * </details>
247
+ *
248
+ * <br />
249
+ *
250
+ * <details>
251
+ * <summary><strong>Usage Metadata</strong></summary>
252
+ *
253
+ * ```typescript
254
+ * const aiMsgForMetadata = await llm.invoke(input);
255
+ * console.log(aiMsgForMetadata.usage_metadata);
256
+ * ```
257
+ *
258
+ * ```txt
259
+ * { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
260
+ * ```
261
+ * </details>
262
+ *
263
+ * <br />
264
+ *
265
+ * <details>
266
+ * <summary><strong>Stream Usage Metadata</strong></summary>
267
+ *
268
+ * ```typescript
269
+ * const streamForMetadata = await llm.stream(
270
+ * input,
271
+ * {
272
+ * streamUsage: true
273
+ * }
274
+ * );
275
+ * let fullForMetadata: AIMessageChunk | undefined;
276
+ * for await (const chunk of streamForMetadata) {
277
+ * fullForMetadata = !fullForMetadata ? chunk : concat(fullForMetadata, chunk);
278
+ * }
279
+ * console.log(fullForMetadata?.usage_metadata);
280
+ * ```
281
+ *
282
+ * ```txt
283
+ * { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
284
+ * ```
285
+ * </details>
286
+ *
287
+ * <br />
10
288
  */
11
289
  export declare class ChatVertexAI extends ChatGoogle {
12
290
  static lc_name(): string;
@@ -1,7 +1,285 @@
1
1
  import { ChatGoogle } from "@langchain/google-gauth";
2
2
  /**
3
- * Integration with a Google Vertex AI chat model using
4
- * the "@langchain/google-gauth" package for auth.
3
+ * Integration with Google Vertex AI chat models.
4
+ *
5
+ * Setup:
6
+ * Install `@langchain/google-vertexai` and set your stringified
7
+ * Vertex AI credentials as an environment variable named `GOOGLE_APPLICATION_CREDENTIALS`.
8
+ *
9
+ * ```bash
10
+ * npm install @langchain/google-vertexai
11
+ * export GOOGLE_APPLICATION_CREDENTIALS="path/to/credentials"
12
+ * ```
13
+ *
14
+ * ## [Constructor args](https://api.js.langchain.com/classes/langchain_community_chat_models_googlevertexai_web.ChatGoogleVertexAI.html#constructor)
15
+ *
16
+ * ## [Runtime args](https://api.js.langchain.com/interfaces/langchain_google_common_types.GoogleAIBaseLanguageModelCallOptions.html)
17
+ *
18
+ * Runtime args can be passed as the second argument to any of the base runnable methods `.invoke`. `.stream`, `.batch`, etc.
19
+ * They can also be passed via `.bind`, or the second arg in `.bindTools`, like shown in the examples below:
20
+ *
21
+ * ```typescript
22
+ * // When calling `.bind`, call options should be passed via the first argument
23
+ * const llmWithArgsBound = llm.bind({
24
+ * stop: ["\n"],
25
+ * tools: [...],
26
+ * });
27
+ *
28
+ * // When calling `.bindTools`, call options should be passed via the second argument
29
+ * const llmWithTools = llm.bindTools(
30
+ * [...],
31
+ * {
32
+ * tool_choice: "auto",
33
+ * }
34
+ * );
35
+ * ```
36
+ *
37
+ * ## Examples
38
+ *
39
+ * <details open>
40
+ * <summary><strong>Instantiate</strong></summary>
41
+ *
42
+ * ```typescript
43
+ * import { ChatVertexAI } from '@langchain/google-vertexai';
44
+ *
45
+ * const llm = new ChatVertexAI({
46
+ * model: "gemini-1.5-pro",
47
+ * temperature: 0,
48
+ * // other params...
49
+ * });
50
+ * ```
51
+ * </details>
52
+ *
53
+ * <br />
54
+ *
55
+ * <details>
56
+ * <summary><strong>Invoking</strong></summary>
57
+ *
58
+ * ```typescript
59
+ * const input = `Translate "I love programming" into French.`;
60
+ *
61
+ * // Models also accept a list of chat messages or a formatted prompt
62
+ * const result = await llm.invoke(input);
63
+ * console.log(result);
64
+ * ```
65
+ *
66
+ * ```txt
67
+ * AIMessageChunk {
68
+ * "content": "\"J'adore programmer\" \n\nHere's why this is the best translation:\n\n* **J'adore** means \"I love\" and conveys a strong passion.\n* **Programmer** is the French verb for \"to program.\"\n\nThis translation is natural and idiomatic in French. \n",
69
+ * "additional_kwargs": {},
70
+ * "response_metadata": {},
71
+ * "tool_calls": [],
72
+ * "tool_call_chunks": [],
73
+ * "invalid_tool_calls": [],
74
+ * "usage_metadata": {
75
+ * "input_tokens": 9,
76
+ * "output_tokens": 63,
77
+ * "total_tokens": 72
78
+ * }
79
+ * }
80
+ * ```
81
+ * </details>
82
+ *
83
+ * <br />
84
+ *
85
+ * <details>
86
+ * <summary><strong>Streaming Chunks</strong></summary>
87
+ *
88
+ * ```typescript
89
+ * for await (const chunk of await llm.stream(input)) {
90
+ * console.log(chunk);
91
+ * }
92
+ * ```
93
+ *
94
+ * ```txt
95
+ * AIMessageChunk {
96
+ * "content": "\"",
97
+ * "additional_kwargs": {},
98
+ * "response_metadata": {},
99
+ * "tool_calls": [],
100
+ * "tool_call_chunks": [],
101
+ * "invalid_tool_calls": []
102
+ * }
103
+ * AIMessageChunk {
104
+ * "content": "J'adore programmer\" \n",
105
+ * "additional_kwargs": {},
106
+ * "response_metadata": {},
107
+ * "tool_calls": [],
108
+ * "tool_call_chunks": [],
109
+ * "invalid_tool_calls": []
110
+ * }
111
+ * AIMessageChunk {
112
+ * "content": "",
113
+ * "additional_kwargs": {},
114
+ * "response_metadata": {},
115
+ * "tool_calls": [],
116
+ * "tool_call_chunks": [],
117
+ * "invalid_tool_calls": []
118
+ * }
119
+ * AIMessageChunk {
120
+ * "content": "",
121
+ * "additional_kwargs": {},
122
+ * "response_metadata": {
123
+ * "finishReason": "stop"
124
+ * },
125
+ * "tool_calls": [],
126
+ * "tool_call_chunks": [],
127
+ * "invalid_tool_calls": [],
128
+ * "usage_metadata": {
129
+ * "input_tokens": 9,
130
+ * "output_tokens": 8,
131
+ * "total_tokens": 17
132
+ * }
133
+ * }
134
+ * ```
135
+ * </details>
136
+ *
137
+ * <br />
138
+ *
139
+ * <details>
140
+ * <summary><strong>Aggregate Streamed Chunks</strong></summary>
141
+ *
142
+ * ```typescript
143
+ * import { AIMessageChunk } from '@langchain/core/messages';
144
+ * import { concat } from '@langchain/core/utils/stream';
145
+ *
146
+ * const stream = await llm.stream(input);
147
+ * let full: AIMessageChunk | undefined;
148
+ * for await (const chunk of stream) {
149
+ * full = !full ? chunk : concat(full, chunk);
150
+ * }
151
+ * console.log(full);
152
+ * ```
153
+ *
154
+ * ```txt
155
+ * AIMessageChunk {
156
+ * "content": "\"J'adore programmer\" \n",
157
+ * "additional_kwargs": {},
158
+ * "response_metadata": {
159
+ * "finishReason": "stop"
160
+ * },
161
+ * "tool_calls": [],
162
+ * "tool_call_chunks": [],
163
+ * "invalid_tool_calls": [],
164
+ * "usage_metadata": {
165
+ * "input_tokens": 9,
166
+ * "output_tokens": 8,
167
+ * "total_tokens": 17
168
+ * }
169
+ * }
170
+ * ```
171
+ * </details>
172
+ *
173
+ * <br />
174
+ *
175
+ * <details>
176
+ * <summary><strong>Bind tools</strong></summary>
177
+ *
178
+ * ```typescript
179
+ * import { z } from 'zod';
180
+ *
181
+ * const GetWeather = {
182
+ * name: "GetWeather",
183
+ * description: "Get the current weather in a given location",
184
+ * schema: z.object({
185
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
186
+ * }),
187
+ * }
188
+ *
189
+ * const GetPopulation = {
190
+ * name: "GetPopulation",
191
+ * description: "Get the current population in a given location",
192
+ * schema: z.object({
193
+ * location: z.string().describe("The city and state, e.g. San Francisco, CA")
194
+ * }),
195
+ * }
196
+ *
197
+ * const llmWithTools = llm.bindTools([GetWeather, GetPopulation]);
198
+ * const aiMsg = await llmWithTools.invoke(
199
+ * "Which city is hotter today and which is bigger: LA or NY?"
200
+ * );
201
+ * console.log(aiMsg.tool_calls);
202
+ * ```
203
+ *
204
+ * ```txt
205
+ * [
206
+ * {
207
+ * name: 'GetPopulation',
208
+ * args: { location: 'New York City, NY' },
209
+ * id: '33c1c1f47e2f492799c77d2800a43912',
210
+ * type: 'tool_call'
211
+ * }
212
+ * ]
213
+ * ```
214
+ * </details>
215
+ *
216
+ * <br />
217
+ *
218
+ * <details>
219
+ * <summary><strong>Structured Output</strong></summary>
220
+ *
221
+ * ```typescript
222
+ * import { z } from 'zod';
223
+ *
224
+ * const Joke = z.object({
225
+ * setup: z.string().describe("The setup of the joke"),
226
+ * punchline: z.string().describe("The punchline to the joke"),
227
+ * rating: z.number().optional().describe("How funny the joke is, from 1 to 10")
228
+ * }).describe('Joke to tell user.');
229
+ *
230
+ * const structuredLlm = llm.withStructuredOutput(Joke, { name: "Joke" });
231
+ * const jokeResult = await structuredLlm.invoke("Tell me a joke about cats");
232
+ * console.log(jokeResult);
233
+ * ```
234
+ *
235
+ * ```txt
236
+ * {
237
+ * setup: 'What do you call a cat that loves to bowl?',
238
+ * punchline: 'An alley cat!'
239
+ * }
240
+ * ```
241
+ * </details>
242
+ *
243
+ * <br />
244
+ *
245
+ * <details>
246
+ * <summary><strong>Usage Metadata</strong></summary>
247
+ *
248
+ * ```typescript
249
+ * const aiMsgForMetadata = await llm.invoke(input);
250
+ * console.log(aiMsgForMetadata.usage_metadata);
251
+ * ```
252
+ *
253
+ * ```txt
254
+ * { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
255
+ * ```
256
+ * </details>
257
+ *
258
+ * <br />
259
+ *
260
+ * <details>
261
+ * <summary><strong>Stream Usage Metadata</strong></summary>
262
+ *
263
+ * ```typescript
264
+ * const streamForMetadata = await llm.stream(
265
+ * input,
266
+ * {
267
+ * streamUsage: true
268
+ * }
269
+ * );
270
+ * let fullForMetadata: AIMessageChunk | undefined;
271
+ * for await (const chunk of streamForMetadata) {
272
+ * fullForMetadata = !fullForMetadata ? chunk : concat(fullForMetadata, chunk);
273
+ * }
274
+ * console.log(fullForMetadata?.usage_metadata);
275
+ * ```
276
+ *
277
+ * ```txt
278
+ * { input_tokens: 9, output_tokens: 8, total_tokens: 17 }
279
+ * ```
280
+ * </details>
281
+ *
282
+ * <br />
5
283
  */
6
284
  export class ChatVertexAI extends ChatGoogle {
7
285
  static lc_name() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/google-vertexai",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "LangChain.js support for Google Vertex AI",
5
5
  "type": "module",
6
6
  "engines": {
@@ -15,12 +15,7 @@
15
15
  "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-google-vertexai/",
16
16
  "scripts": {
17
17
  "build": "yarn turbo:command build:internal --filter=@langchain/google-vertexai",
18
- "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking",
19
- "build:deps": "yarn run turbo:command build --filter=@langchain/google-gauth",
20
- "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests",
21
- "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs",
22
- "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
23
- "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking",
18
+ "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking",
24
19
  "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
25
20
  "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
26
21
  "lint": "yarn lint:eslint && yarn lint:dpdm",
@@ -31,25 +26,19 @@
31
26
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
32
27
  "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
33
28
  "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
34
- "test:standard:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.test.ts --testTimeout 100000 --maxWorkers=50%",
35
- "test:standard:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
36
- "test:standard": "yarn test:standard:unit && yarn test:standard:int",
37
29
  "format": "prettier --config .prettierrc --write \"src\"",
38
- "format:check": "prettier --config .prettierrc --check \"src\"",
39
- "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
40
- "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints",
41
- "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking"
30
+ "format:check": "prettier --config .prettierrc --check \"src\""
42
31
  },
43
32
  "author": "LangChain",
44
33
  "license": "MIT",
45
34
  "dependencies": {
46
35
  "@langchain/core": ">=0.2.21 <0.3.0",
47
- "@langchain/google-gauth": "~0.0.25"
36
+ "@langchain/google-gauth": "~0.0.27"
48
37
  },
49
38
  "devDependencies": {
50
39
  "@jest/globals": "^29.5.0",
51
- "@langchain/google-common": "~0.0",
52
- "@langchain/scripts": "~0.0.20",
40
+ "@langchain/google-common": "^0.0.27",
41
+ "@langchain/scripts": ">=0.1.0 <0.2.0",
53
42
  "@langchain/standard-tests": "0.0.0",
54
43
  "@swc/core": "^1.3.90",
55
44
  "@swc/jest": "^0.2.29",