@langchain/google-genai 0.2.11 → 0.2.13
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/README.md
CHANGED
|
@@ -53,7 +53,7 @@ import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
|
|
|
53
53
|
import { HumanMessage } from "@langchain/core/messages";
|
|
54
54
|
|
|
55
55
|
const model = new ChatGoogleGenerativeAI({
|
|
56
|
-
|
|
56
|
+
model: "gemini-pro",
|
|
57
57
|
maxOutputTokens: 2048,
|
|
58
58
|
});
|
|
59
59
|
const response = await model.invoke(new HumanMessage("Hello world!"));
|
|
@@ -73,7 +73,7 @@ import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
|
|
|
73
73
|
import { HumanMessage } from "@langchain/core/messages";
|
|
74
74
|
|
|
75
75
|
const vision = new ChatGoogleGenerativeAI({
|
|
76
|
-
|
|
76
|
+
model: "gemini-pro-vision",
|
|
77
77
|
maxOutputTokens: 2048,
|
|
78
78
|
});
|
|
79
79
|
const image = fs.readFileSync("./hotdog.jpg").toString("base64");
|
package/dist/embeddings.cjs
CHANGED
|
@@ -96,6 +96,8 @@ class GoogleGenerativeAIEmbeddings extends embeddings_1.Embeddings {
|
|
|
96
96
|
}
|
|
97
97
|
this.client = new generative_ai_1.GoogleGenerativeAI(this.apiKey).getGenerativeModel({
|
|
98
98
|
model: this.model,
|
|
99
|
+
}, {
|
|
100
|
+
baseUrl: fields?.baseUrl,
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
103
|
_convertToContent(text) {
|
package/dist/embeddings.d.ts
CHANGED
|
@@ -40,6 +40,10 @@ export interface GoogleGenerativeAIEmbeddingsParams extends EmbeddingsParams {
|
|
|
40
40
|
* Google API key to use
|
|
41
41
|
*/
|
|
42
42
|
apiKey?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Google API base URL to use
|
|
45
|
+
*/
|
|
46
|
+
baseUrl?: string;
|
|
43
47
|
}
|
|
44
48
|
/**
|
|
45
49
|
* Class that extends the Embeddings class and provides methods for
|
package/dist/embeddings.js
CHANGED
package/dist/utils/common.cjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getMessageAuthor = getMessageAuthor;
|
|
4
|
+
exports.convertAuthorToRole = convertAuthorToRole;
|
|
5
|
+
exports.convertMessageContentToParts = convertMessageContentToParts;
|
|
6
|
+
exports.convertBaseMessagesToContent = convertBaseMessagesToContent;
|
|
7
|
+
exports.mapGenerateContentResultToChatResult = mapGenerateContentResultToChatResult;
|
|
8
|
+
exports.convertResponseContentToChatGenerationChunk = convertResponseContentToChatGenerationChunk;
|
|
9
|
+
exports.convertToGenerativeAITools = convertToGenerativeAITools;
|
|
4
10
|
const messages_1 = require("@langchain/core/messages");
|
|
5
11
|
const outputs_1 = require("@langchain/core/outputs");
|
|
6
12
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
@@ -17,7 +23,6 @@ function getMessageAuthor(message) {
|
|
|
17
23
|
}
|
|
18
24
|
return message.name ?? type;
|
|
19
25
|
}
|
|
20
|
-
exports.getMessageAuthor = getMessageAuthor;
|
|
21
26
|
/**
|
|
22
27
|
* Maps a message type to a Google Generative AI chat author.
|
|
23
28
|
* @param message The message to map.
|
|
@@ -45,7 +50,6 @@ function convertAuthorToRole(author) {
|
|
|
45
50
|
throw new Error(`Unknown / unsupported author: ${author}`);
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
|
-
exports.convertAuthorToRole = convertAuthorToRole;
|
|
49
53
|
function messageContentMedia(content) {
|
|
50
54
|
if ("mimeType" in content && "data" in content) {
|
|
51
55
|
return {
|
|
@@ -328,7 +332,6 @@ function convertMessageContentToParts(message, isMultimodalModel, previousMessag
|
|
|
328
332
|
}
|
|
329
333
|
return [...messageParts, ...functionCalls];
|
|
330
334
|
}
|
|
331
|
-
exports.convertMessageContentToParts = convertMessageContentToParts;
|
|
332
335
|
function convertBaseMessagesToContent(messages, isMultimodalModel, convertSystemMessageToHumanContent = false) {
|
|
333
336
|
return messages.reduce((acc, message, index) => {
|
|
334
337
|
if (!(0, messages_1.isBaseMessage)(message)) {
|
|
@@ -373,7 +376,6 @@ function convertBaseMessagesToContent(messages, isMultimodalModel, convertSystem
|
|
|
373
376
|
};
|
|
374
377
|
}, { content: [], mergeWithPreviousContent: false }).content;
|
|
375
378
|
}
|
|
376
|
-
exports.convertBaseMessagesToContent = convertBaseMessagesToContent;
|
|
377
379
|
function mapGenerateContentResultToChatResult(response, extra) {
|
|
378
380
|
// if rejected or error, return empty generations with reason in filters
|
|
379
381
|
if (!response.candidates ||
|
|
@@ -460,7 +462,6 @@ function mapGenerateContentResultToChatResult(response, extra) {
|
|
|
460
462
|
},
|
|
461
463
|
};
|
|
462
464
|
}
|
|
463
|
-
exports.mapGenerateContentResultToChatResult = mapGenerateContentResultToChatResult;
|
|
464
465
|
function convertResponseContentToChatGenerationChunk(response, extra) {
|
|
465
466
|
if (!response.candidates || response.candidates.length === 0) {
|
|
466
467
|
return null;
|
|
@@ -533,7 +534,6 @@ function convertResponseContentToChatGenerationChunk(response, extra) {
|
|
|
533
534
|
generationInfo,
|
|
534
535
|
});
|
|
535
536
|
}
|
|
536
|
-
exports.convertResponseContentToChatGenerationChunk = convertResponseContentToChatGenerationChunk;
|
|
537
537
|
function convertToGenerativeAITools(tools) {
|
|
538
538
|
if (tools.every((tool) => "functionDeclarations" in tool &&
|
|
539
539
|
Array.isArray(tool.functionDeclarations))) {
|
|
@@ -570,4 +570,3 @@ function convertToGenerativeAITools(tools) {
|
|
|
570
570
|
},
|
|
571
571
|
];
|
|
572
572
|
}
|
|
573
|
-
exports.convertToGenerativeAITools = convertToGenerativeAITools;
|
package/dist/utils/tools.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertToolsToGenAI =
|
|
3
|
+
exports.convertToolsToGenAI = convertToolsToGenAI;
|
|
4
4
|
const generative_ai_1 = require("@google/generative-ai");
|
|
5
5
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
6
6
|
const base_1 = require("@langchain/core/language_models/base");
|
|
@@ -13,7 +13,6 @@ function convertToolsToGenAI(tools, extra) {
|
|
|
13
13
|
const toolConfig = createToolConfig(genAITools, extra);
|
|
14
14
|
return { tools: genAITools, toolConfig };
|
|
15
15
|
}
|
|
16
|
-
exports.convertToolsToGenAI = convertToolsToGenAI;
|
|
17
16
|
function processTools(tools) {
|
|
18
17
|
let functionDeclarationTools = [];
|
|
19
18
|
const genAITools = [];
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.removeAdditionalProperties = removeAdditionalProperties;
|
|
5
|
+
exports.schemaToGenerativeAIParameters = schemaToGenerativeAIParameters;
|
|
6
|
+
exports.jsonSchemaToGeminiParameters = jsonSchemaToGeminiParameters;
|
|
5
7
|
const types_1 = require("@langchain/core/utils/types");
|
|
6
8
|
const json_schema_1 = require("@langchain/core/utils/json_schema");
|
|
7
9
|
function removeAdditionalProperties(
|
|
@@ -32,7 +34,6 @@ obj) {
|
|
|
32
34
|
}
|
|
33
35
|
return obj;
|
|
34
36
|
}
|
|
35
|
-
exports.removeAdditionalProperties = removeAdditionalProperties;
|
|
36
37
|
function schemaToGenerativeAIParameters(schema) {
|
|
37
38
|
// GenerativeAI doesn't accept either the $schema or additionalProperties
|
|
38
39
|
// attributes, so we need to explicitly remove them.
|
|
@@ -40,7 +41,6 @@ function schemaToGenerativeAIParameters(schema) {
|
|
|
40
41
|
const { $schema, ...rest } = jsonSchema;
|
|
41
42
|
return rest;
|
|
42
43
|
}
|
|
43
|
-
exports.schemaToGenerativeAIParameters = schemaToGenerativeAIParameters;
|
|
44
44
|
function jsonSchemaToGeminiParameters(
|
|
45
45
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
46
|
schema) {
|
|
@@ -51,4 +51,3 @@ schema) {
|
|
|
51
51
|
const { $schema, ...rest } = jsonSchema;
|
|
52
52
|
return rest;
|
|
53
53
|
}
|
|
54
|
-
exports.jsonSchemaToGeminiParameters = jsonSchemaToGeminiParameters;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google-genai",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "Google Generative AI integration for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"build": "yarn turbo:command build:internal --filter=@langchain/google-genai",
|
|
18
18
|
"build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking",
|
|
19
19
|
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
|
|
20
|
-
"lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
|
|
20
|
+
"lint:dpdm": "dpdm --skip-dynamic-imports circular --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
|
|
21
21
|
"lint": "yarn lint:eslint && yarn lint:dpdm",
|
|
22
22
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
|
|
23
23
|
"clean": "rm -rf .turbo dist/",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
53
53
|
"@typescript-eslint/parser": "^6.12.0",
|
|
54
54
|
"dotenv": "^16.3.1",
|
|
55
|
-
"dpdm": "^3.
|
|
55
|
+
"dpdm": "^3.14.0",
|
|
56
56
|
"eslint": "^8.33.0",
|
|
57
57
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
58
58
|
"eslint-config-prettier": "^8.6.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"release-it": "^18.1.2",
|
|
67
67
|
"rollup": "^4.5.2",
|
|
68
68
|
"ts-jest": "^29.1.0",
|
|
69
|
-
"typescript": "
|
|
69
|
+
"typescript": "~5.8.3",
|
|
70
70
|
"zod": "^3.25.32"
|
|
71
71
|
},
|
|
72
72
|
"publishConfig": {
|