@langchain/google-genai 0.1.5 → 0.1.7

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.
@@ -344,6 +344,47 @@ const tools_js_1 = require("./utils/tools.cjs");
344
344
  * </details>
345
345
  *
346
346
  * <br />
347
+ *
348
+ * <details>
349
+ * <summary><strong>Document Messages</strong></summary>
350
+ *
351
+ * This example will show you how to pass documents such as PDFs to Google
352
+ * Generative AI through messages.
353
+ *
354
+ * ```typescript
355
+ * const pdfPath = "/Users/my_user/Downloads/invoice.pdf";
356
+ * const pdfBase64 = await fs.readFile(pdfPath, "base64");
357
+ *
358
+ * const response = await llm.invoke([
359
+ * ["system", "Use the provided documents to answer the question"],
360
+ * [
361
+ * "user",
362
+ * [
363
+ * {
364
+ * type: "application/pdf", // If the `type` field includes a single slash (`/`), it will be treated as inline data.
365
+ * data: pdfBase64,
366
+ * },
367
+ * {
368
+ * type: "text",
369
+ * text: "Summarize the contents of this PDF",
370
+ * },
371
+ * ],
372
+ * ],
373
+ * ]);
374
+ *
375
+ * console.log(response.content);
376
+ * ```
377
+ *
378
+ * ```txt
379
+ * This is a billing invoice from Twitter Developers for X API Basic Access. The transaction date is January 7, 2025,
380
+ * and the amount is $194.34, which has been paid. The subscription period is from January 7, 2025 21:02 to February 7, 2025 00:00 (UTC).
381
+ * The tax is $0.00, with a tax rate of 0%. The total amount is $194.34. The payment was made using a Visa card ending in 7022,
382
+ * expiring in 12/2026. The billing address is Brace Sproul, 1234 Main Street, San Francisco, CA, US 94103. The company being billed is
383
+ * X Corp, located at 865 FM 1209 Building 2, Bastrop, TX, US 78602. Terms and conditions apply.
384
+ * ```
385
+ * </details>
386
+ *
387
+ * <br />
347
388
  */
348
389
  class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
349
390
  static lc_name() {
@@ -360,7 +401,9 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
360
401
  };
361
402
  }
362
403
  get _isMultimodalModel() {
363
- return this.model.includes("vision") || this.model.startsWith("gemini-1.5");
404
+ return (this.model.includes("vision") ||
405
+ this.model.startsWith("gemini-1.5") ||
406
+ this.model.startsWith("gemini-2"));
364
407
  }
365
408
  constructor(fields) {
366
409
  super(fields ?? {});
@@ -463,6 +463,47 @@ export interface GoogleGenerativeAIChatInput extends BaseChatModelParams, Pick<G
463
463
  * </details>
464
464
  *
465
465
  * <br />
466
+ *
467
+ * <details>
468
+ * <summary><strong>Document Messages</strong></summary>
469
+ *
470
+ * This example will show you how to pass documents such as PDFs to Google
471
+ * Generative AI through messages.
472
+ *
473
+ * ```typescript
474
+ * const pdfPath = "/Users/my_user/Downloads/invoice.pdf";
475
+ * const pdfBase64 = await fs.readFile(pdfPath, "base64");
476
+ *
477
+ * const response = await llm.invoke([
478
+ * ["system", "Use the provided documents to answer the question"],
479
+ * [
480
+ * "user",
481
+ * [
482
+ * {
483
+ * type: "application/pdf", // If the `type` field includes a single slash (`/`), it will be treated as inline data.
484
+ * data: pdfBase64,
485
+ * },
486
+ * {
487
+ * type: "text",
488
+ * text: "Summarize the contents of this PDF",
489
+ * },
490
+ * ],
491
+ * ],
492
+ * ]);
493
+ *
494
+ * console.log(response.content);
495
+ * ```
496
+ *
497
+ * ```txt
498
+ * This is a billing invoice from Twitter Developers for X API Basic Access. The transaction date is January 7, 2025,
499
+ * and the amount is $194.34, which has been paid. The subscription period is from January 7, 2025 21:02 to February 7, 2025 00:00 (UTC).
500
+ * The tax is $0.00, with a tax rate of 0%. The total amount is $194.34. The payment was made using a Visa card ending in 7022,
501
+ * expiring in 12/2026. The billing address is Brace Sproul, 1234 Main Street, San Francisco, CA, US 94103. The company being billed is
502
+ * X Corp, located at 865 FM 1209 Building 2, Bastrop, TX, US 78602. Terms and conditions apply.
503
+ * ```
504
+ * </details>
505
+ *
506
+ * <br />
466
507
  */
467
508
  export declare class ChatGoogleGenerativeAI extends BaseChatModel<GoogleGenerativeAIChatCallOptions, AIMessageChunk> implements GoogleGenerativeAIChatInput {
468
509
  static lc_name(): string;
@@ -341,6 +341,47 @@ import { convertToolsToGenAI } from "./utils/tools.js";
341
341
  * </details>
342
342
  *
343
343
  * <br />
344
+ *
345
+ * <details>
346
+ * <summary><strong>Document Messages</strong></summary>
347
+ *
348
+ * This example will show you how to pass documents such as PDFs to Google
349
+ * Generative AI through messages.
350
+ *
351
+ * ```typescript
352
+ * const pdfPath = "/Users/my_user/Downloads/invoice.pdf";
353
+ * const pdfBase64 = await fs.readFile(pdfPath, "base64");
354
+ *
355
+ * const response = await llm.invoke([
356
+ * ["system", "Use the provided documents to answer the question"],
357
+ * [
358
+ * "user",
359
+ * [
360
+ * {
361
+ * type: "application/pdf", // If the `type` field includes a single slash (`/`), it will be treated as inline data.
362
+ * data: pdfBase64,
363
+ * },
364
+ * {
365
+ * type: "text",
366
+ * text: "Summarize the contents of this PDF",
367
+ * },
368
+ * ],
369
+ * ],
370
+ * ]);
371
+ *
372
+ * console.log(response.content);
373
+ * ```
374
+ *
375
+ * ```txt
376
+ * This is a billing invoice from Twitter Developers for X API Basic Access. The transaction date is January 7, 2025,
377
+ * and the amount is $194.34, which has been paid. The subscription period is from January 7, 2025 21:02 to February 7, 2025 00:00 (UTC).
378
+ * The tax is $0.00, with a tax rate of 0%. The total amount is $194.34. The payment was made using a Visa card ending in 7022,
379
+ * expiring in 12/2026. The billing address is Brace Sproul, 1234 Main Street, San Francisco, CA, US 94103. The company being billed is
380
+ * X Corp, located at 865 FM 1209 Building 2, Bastrop, TX, US 78602. Terms and conditions apply.
381
+ * ```
382
+ * </details>
383
+ *
384
+ * <br />
344
385
  */
345
386
  export class ChatGoogleGenerativeAI extends BaseChatModel {
346
387
  static lc_name() {
@@ -357,7 +398,9 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
357
398
  };
358
399
  }
359
400
  get _isMultimodalModel() {
360
- return this.model.includes("vision") || this.model.startsWith("gemini-1.5");
401
+ return (this.model.includes("vision") ||
402
+ this.model.startsWith("gemini-1.5") ||
403
+ this.model.startsWith("gemini-2"));
361
404
  }
362
405
  constructor(fields) {
363
406
  super(fields ?? {});
@@ -139,6 +139,18 @@ function convertMessageContentToParts(message, isMultimodalModel) {
139
139
  },
140
140
  };
141
141
  }
142
+ else if (c.type?.includes("/") &&
143
+ // Ensure it's a single slash.
144
+ c.type.split("/").length === 2 &&
145
+ "data" in c &&
146
+ typeof c.data === "string") {
147
+ return {
148
+ inlineData: {
149
+ mimeType: c.type,
150
+ data: c.data,
151
+ },
152
+ };
153
+ }
142
154
  throw new Error(`Unknown content type ${c.type}`);
143
155
  });
144
156
  }
@@ -134,6 +134,18 @@ export function convertMessageContentToParts(message, isMultimodalModel) {
134
134
  },
135
135
  };
136
136
  }
137
+ else if (c.type?.includes("/") &&
138
+ // Ensure it's a single slash.
139
+ c.type.split("/").length === 2 &&
140
+ "data" in c &&
141
+ typeof c.data === "string") {
142
+ return {
143
+ inlineData: {
144
+ mimeType: c.type,
145
+ data: c.data,
146
+ },
147
+ };
148
+ }
137
149
  throw new Error(`Unknown content type ${c.type}`);
138
150
  });
139
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/google-genai",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Google Generative AI integration for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {