@langchain/google-genai 0.1.6 → 0.1.8
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.
- package/dist/chat_models.cjs +41 -0
- package/dist/chat_models.d.ts +41 -0
- package/dist/chat_models.js +41 -0
- package/dist/utils/common.cjs +20 -0
- package/dist/utils/common.js +20 -0
- package/package.json +1 -1
package/dist/chat_models.cjs
CHANGED
|
@@ -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() {
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -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;
|
package/dist/chat_models.js
CHANGED
|
@@ -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() {
|
package/dist/utils/common.cjs
CHANGED
|
@@ -53,6 +53,14 @@ function messageContentMedia(content) {
|
|
|
53
53
|
},
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
if ("mimeType" in content && "fileUri" in content) {
|
|
57
|
+
return {
|
|
58
|
+
fileData: {
|
|
59
|
+
mimeType: content.mimeType,
|
|
60
|
+
fileUri: content.fileUri,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
56
64
|
throw new Error("Invalid media content");
|
|
57
65
|
}
|
|
58
66
|
function convertMessageContentToParts(message, isMultimodalModel) {
|
|
@@ -139,6 +147,18 @@ function convertMessageContentToParts(message, isMultimodalModel) {
|
|
|
139
147
|
},
|
|
140
148
|
};
|
|
141
149
|
}
|
|
150
|
+
else if (c.type?.includes("/") &&
|
|
151
|
+
// Ensure it's a single slash.
|
|
152
|
+
c.type.split("/").length === 2 &&
|
|
153
|
+
"data" in c &&
|
|
154
|
+
typeof c.data === "string") {
|
|
155
|
+
return {
|
|
156
|
+
inlineData: {
|
|
157
|
+
mimeType: c.type,
|
|
158
|
+
data: c.data,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
142
162
|
throw new Error(`Unknown content type ${c.type}`);
|
|
143
163
|
});
|
|
144
164
|
}
|
package/dist/utils/common.js
CHANGED
|
@@ -48,6 +48,14 @@ function messageContentMedia(content) {
|
|
|
48
48
|
},
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
+
if ("mimeType" in content && "fileUri" in content) {
|
|
52
|
+
return {
|
|
53
|
+
fileData: {
|
|
54
|
+
mimeType: content.mimeType,
|
|
55
|
+
fileUri: content.fileUri,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
51
59
|
throw new Error("Invalid media content");
|
|
52
60
|
}
|
|
53
61
|
export function convertMessageContentToParts(message, isMultimodalModel) {
|
|
@@ -134,6 +142,18 @@ export function convertMessageContentToParts(message, isMultimodalModel) {
|
|
|
134
142
|
},
|
|
135
143
|
};
|
|
136
144
|
}
|
|
145
|
+
else if (c.type?.includes("/") &&
|
|
146
|
+
// Ensure it's a single slash.
|
|
147
|
+
c.type.split("/").length === 2 &&
|
|
148
|
+
"data" in c &&
|
|
149
|
+
typeof c.data === "string") {
|
|
150
|
+
return {
|
|
151
|
+
inlineData: {
|
|
152
|
+
mimeType: c.type,
|
|
153
|
+
data: c.data,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
137
157
|
throw new Error(`Unknown content type ${c.type}`);
|
|
138
158
|
});
|
|
139
159
|
}
|