@langchain/google-genai 0.0.10 → 0.0.12
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 +1 -1
- package/dist/chat_models.cjs +13 -4
- package/dist/chat_models.d.ts +10 -1
- package/dist/chat_models.js +13 -4
- package/dist/embeddings.cjs +11 -2
- package/dist/embeddings.d.ts +9 -0
- package/dist/embeddings.js +11 -2
- package/dist/utils.cjs +9 -2
- package/dist/utils.js +9 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ const model = new ChatGoogleGenerativeAI({
|
|
|
55
55
|
modelName: "gemini-pro",
|
|
56
56
|
maxOutputTokens: 2048,
|
|
57
57
|
});
|
|
58
|
-
const response = await
|
|
58
|
+
const response = await model.invoke(new HumanMessage("Hello world!"));
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
#### Multimodal inputs
|
package/dist/chat_models.cjs
CHANGED
|
@@ -30,7 +30,7 @@ const utils_js_1 = require("./utils.cjs");
|
|
|
30
30
|
* ]
|
|
31
31
|
* })
|
|
32
32
|
* ];
|
|
33
|
-
* const res = await model.
|
|
33
|
+
* const res = await model.invoke(questions);
|
|
34
34
|
* console.log({ res });
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
@@ -44,7 +44,7 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
get _isMultimodalModel() {
|
|
47
|
-
return this.
|
|
47
|
+
return this.model.includes("vision") || this.model.startsWith("gemini-1.5");
|
|
48
48
|
}
|
|
49
49
|
constructor(fields) {
|
|
50
50
|
super(fields ?? {});
|
|
@@ -60,6 +60,12 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
|
|
|
60
60
|
writable: true,
|
|
61
61
|
value: "gemini-pro"
|
|
62
62
|
});
|
|
63
|
+
Object.defineProperty(this, "model", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: "gemini-pro"
|
|
68
|
+
});
|
|
63
69
|
Object.defineProperty(this, "temperature", {
|
|
64
70
|
enumerable: true,
|
|
65
71
|
configurable: true,
|
|
@@ -115,7 +121,10 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
|
|
|
115
121
|
value: void 0
|
|
116
122
|
});
|
|
117
123
|
this.modelName =
|
|
118
|
-
fields?.
|
|
124
|
+
fields?.model?.replace(/^models\//, "") ??
|
|
125
|
+
fields?.modelName?.replace(/^models\//, "") ??
|
|
126
|
+
this.model;
|
|
127
|
+
this.model = this.modelName;
|
|
119
128
|
this.maxOutputTokens = fields?.maxOutputTokens ?? this.maxOutputTokens;
|
|
120
129
|
if (this.maxOutputTokens && this.maxOutputTokens < 0) {
|
|
121
130
|
throw new Error("`maxOutputTokens` must be a positive integer");
|
|
@@ -152,7 +161,7 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
|
|
|
152
161
|
}
|
|
153
162
|
this.streaming = fields?.streaming ?? this.streaming;
|
|
154
163
|
this.client = new generative_ai_1.GoogleGenerativeAI(this.apiKey).getGenerativeModel({
|
|
155
|
-
model: this.
|
|
164
|
+
model: this.model,
|
|
156
165
|
safetySettings: this.safetySettings,
|
|
157
166
|
generationConfig: {
|
|
158
167
|
candidateCount: 1,
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -14,9 +14,17 @@ export interface GoogleGenerativeAIChatInput extends BaseChatModelParams {
|
|
|
14
14
|
/**
|
|
15
15
|
* Model Name to use
|
|
16
16
|
*
|
|
17
|
+
* Alias for `model`
|
|
18
|
+
*
|
|
17
19
|
* Note: The format must follow the pattern - `{model}`
|
|
18
20
|
*/
|
|
19
21
|
modelName?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Model Name to use
|
|
24
|
+
*
|
|
25
|
+
* Note: The format must follow the pattern - `{model}`
|
|
26
|
+
*/
|
|
27
|
+
model?: string;
|
|
20
28
|
/**
|
|
21
29
|
* Controls the randomness of the output.
|
|
22
30
|
*
|
|
@@ -104,7 +112,7 @@ export interface GoogleGenerativeAIChatInput extends BaseChatModelParams {
|
|
|
104
112
|
* ]
|
|
105
113
|
* })
|
|
106
114
|
* ];
|
|
107
|
-
* const res = await model.
|
|
115
|
+
* const res = await model.invoke(questions);
|
|
108
116
|
* console.log({ res });
|
|
109
117
|
* ```
|
|
110
118
|
*/
|
|
@@ -115,6 +123,7 @@ export declare class ChatGoogleGenerativeAI extends BaseChatModel implements Goo
|
|
|
115
123
|
[key: string]: string;
|
|
116
124
|
} | undefined;
|
|
117
125
|
modelName: string;
|
|
126
|
+
model: string;
|
|
118
127
|
temperature?: number;
|
|
119
128
|
maxOutputTokens?: number;
|
|
120
129
|
topP?: number;
|
package/dist/chat_models.js
CHANGED
|
@@ -27,7 +27,7 @@ import { convertBaseMessagesToContent, convertResponseContentToChatGenerationChu
|
|
|
27
27
|
* ]
|
|
28
28
|
* })
|
|
29
29
|
* ];
|
|
30
|
-
* const res = await model.
|
|
30
|
+
* const res = await model.invoke(questions);
|
|
31
31
|
* console.log({ res });
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
@@ -41,7 +41,7 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
get _isMultimodalModel() {
|
|
44
|
-
return this.
|
|
44
|
+
return this.model.includes("vision") || this.model.startsWith("gemini-1.5");
|
|
45
45
|
}
|
|
46
46
|
constructor(fields) {
|
|
47
47
|
super(fields ?? {});
|
|
@@ -57,6 +57,12 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
|
|
|
57
57
|
writable: true,
|
|
58
58
|
value: "gemini-pro"
|
|
59
59
|
});
|
|
60
|
+
Object.defineProperty(this, "model", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: "gemini-pro"
|
|
65
|
+
});
|
|
60
66
|
Object.defineProperty(this, "temperature", {
|
|
61
67
|
enumerable: true,
|
|
62
68
|
configurable: true,
|
|
@@ -112,7 +118,10 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
|
|
|
112
118
|
value: void 0
|
|
113
119
|
});
|
|
114
120
|
this.modelName =
|
|
115
|
-
fields?.
|
|
121
|
+
fields?.model?.replace(/^models\//, "") ??
|
|
122
|
+
fields?.modelName?.replace(/^models\//, "") ??
|
|
123
|
+
this.model;
|
|
124
|
+
this.model = this.modelName;
|
|
116
125
|
this.maxOutputTokens = fields?.maxOutputTokens ?? this.maxOutputTokens;
|
|
117
126
|
if (this.maxOutputTokens && this.maxOutputTokens < 0) {
|
|
118
127
|
throw new Error("`maxOutputTokens` must be a positive integer");
|
|
@@ -149,7 +158,7 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
|
|
|
149
158
|
}
|
|
150
159
|
this.streaming = fields?.streaming ?? this.streaming;
|
|
151
160
|
this.client = new GenerativeAI(this.apiKey).getGenerativeModel({
|
|
152
|
-
model: this.
|
|
161
|
+
model: this.model,
|
|
153
162
|
safetySettings: this.safetySettings,
|
|
154
163
|
generationConfig: {
|
|
155
164
|
candidateCount: 1,
|
package/dist/embeddings.cjs
CHANGED
|
@@ -41,6 +41,12 @@ class GoogleGenerativeAIEmbeddings extends embeddings_1.Embeddings {
|
|
|
41
41
|
writable: true,
|
|
42
42
|
value: "embedding-001"
|
|
43
43
|
});
|
|
44
|
+
Object.defineProperty(this, "model", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true,
|
|
48
|
+
value: "embedding-001"
|
|
49
|
+
});
|
|
44
50
|
Object.defineProperty(this, "taskType", {
|
|
45
51
|
enumerable: true,
|
|
46
52
|
configurable: true,
|
|
@@ -72,7 +78,10 @@ class GoogleGenerativeAIEmbeddings extends embeddings_1.Embeddings {
|
|
|
72
78
|
value: void 0
|
|
73
79
|
});
|
|
74
80
|
this.modelName =
|
|
75
|
-
fields?.
|
|
81
|
+
fields?.model?.replace(/^models\//, "") ??
|
|
82
|
+
fields?.modelName?.replace(/^models\//, "") ??
|
|
83
|
+
this.modelName;
|
|
84
|
+
this.model = this.modelName;
|
|
76
85
|
this.taskType = fields?.taskType ?? this.taskType;
|
|
77
86
|
this.title = fields?.title ?? this.title;
|
|
78
87
|
if (this.title && this.taskType !== "RETRIEVAL_DOCUMENT") {
|
|
@@ -86,7 +95,7 @@ class GoogleGenerativeAIEmbeddings extends embeddings_1.Embeddings {
|
|
|
86
95
|
"GoogleGenerativeAIEmbeddings constructor");
|
|
87
96
|
}
|
|
88
97
|
this.client = new generative_ai_1.GoogleGenerativeAI(this.apiKey).getGenerativeModel({
|
|
89
|
-
model: this.
|
|
98
|
+
model: this.model,
|
|
90
99
|
});
|
|
91
100
|
}
|
|
92
101
|
_convertToContent(text) {
|
package/dist/embeddings.d.ts
CHANGED
|
@@ -8,9 +8,17 @@ export interface GoogleGenerativeAIEmbeddingsParams extends EmbeddingsParams {
|
|
|
8
8
|
/**
|
|
9
9
|
* Model Name to use
|
|
10
10
|
*
|
|
11
|
+
* Alias for `model`
|
|
12
|
+
*
|
|
11
13
|
* Note: The format must follow the pattern - `{model}`
|
|
12
14
|
*/
|
|
13
15
|
modelName?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Model Name to use
|
|
18
|
+
*
|
|
19
|
+
* Note: The format must follow the pattern - `{model}`
|
|
20
|
+
*/
|
|
21
|
+
model?: string;
|
|
14
22
|
/**
|
|
15
23
|
* Type of task for which the embedding will be used
|
|
16
24
|
*
|
|
@@ -57,6 +65,7 @@ export interface GoogleGenerativeAIEmbeddingsParams extends EmbeddingsParams {
|
|
|
57
65
|
export declare class GoogleGenerativeAIEmbeddings extends Embeddings implements GoogleGenerativeAIEmbeddingsParams {
|
|
58
66
|
apiKey?: string;
|
|
59
67
|
modelName: string;
|
|
68
|
+
model: string;
|
|
60
69
|
taskType?: TaskType;
|
|
61
70
|
title?: string;
|
|
62
71
|
stripNewLines: boolean;
|
package/dist/embeddings.js
CHANGED
|
@@ -38,6 +38,12 @@ export class GoogleGenerativeAIEmbeddings extends Embeddings {
|
|
|
38
38
|
writable: true,
|
|
39
39
|
value: "embedding-001"
|
|
40
40
|
});
|
|
41
|
+
Object.defineProperty(this, "model", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: "embedding-001"
|
|
46
|
+
});
|
|
41
47
|
Object.defineProperty(this, "taskType", {
|
|
42
48
|
enumerable: true,
|
|
43
49
|
configurable: true,
|
|
@@ -69,7 +75,10 @@ export class GoogleGenerativeAIEmbeddings extends Embeddings {
|
|
|
69
75
|
value: void 0
|
|
70
76
|
});
|
|
71
77
|
this.modelName =
|
|
72
|
-
fields?.
|
|
78
|
+
fields?.model?.replace(/^models\//, "") ??
|
|
79
|
+
fields?.modelName?.replace(/^models\//, "") ??
|
|
80
|
+
this.modelName;
|
|
81
|
+
this.model = this.modelName;
|
|
73
82
|
this.taskType = fields?.taskType ?? this.taskType;
|
|
74
83
|
this.title = fields?.title ?? this.title;
|
|
75
84
|
if (this.title && this.taskType !== "RETRIEVAL_DOCUMENT") {
|
|
@@ -83,7 +92,7 @@ export class GoogleGenerativeAIEmbeddings extends Embeddings {
|
|
|
83
92
|
"GoogleGenerativeAIEmbeddings constructor");
|
|
84
93
|
}
|
|
85
94
|
this.client = new GoogleGenerativeAI(this.apiKey).getGenerativeModel({
|
|
86
|
-
model: this.
|
|
95
|
+
model: this.model,
|
|
87
96
|
});
|
|
88
97
|
}
|
|
89
98
|
_convertToContent(text) {
|
package/dist/utils.cjs
CHANGED
|
@@ -48,10 +48,17 @@ function convertMessageContentToParts(content, isMultimodalModel) {
|
|
|
48
48
|
if (!isMultimodalModel) {
|
|
49
49
|
throw new Error(`This model does not support images`);
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
let source;
|
|
52
|
+
if (typeof c.image_url === "string") {
|
|
53
|
+
source = c.image_url;
|
|
54
|
+
}
|
|
55
|
+
else if (typeof c.image_url === "object" && "url" in c.image_url) {
|
|
56
|
+
source = c.image_url.url;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
52
59
|
throw new Error("Please provide image as base64 encoded data URL");
|
|
53
60
|
}
|
|
54
|
-
const [dm, data] =
|
|
61
|
+
const [dm, data] = source.split(",");
|
|
55
62
|
if (!dm.startsWith("data:")) {
|
|
56
63
|
throw new Error("Please provide image as base64 encoded data URL");
|
|
57
64
|
}
|
package/dist/utils.js
CHANGED
|
@@ -43,10 +43,17 @@ export function convertMessageContentToParts(content, isMultimodalModel) {
|
|
|
43
43
|
if (!isMultimodalModel) {
|
|
44
44
|
throw new Error(`This model does not support images`);
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
let source;
|
|
47
|
+
if (typeof c.image_url === "string") {
|
|
48
|
+
source = c.image_url;
|
|
49
|
+
}
|
|
50
|
+
else if (typeof c.image_url === "object" && "url" in c.image_url) {
|
|
51
|
+
source = c.image_url.url;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
47
54
|
throw new Error("Please provide image as base64 encoded data URL");
|
|
48
55
|
}
|
|
49
|
-
const [dm, data] =
|
|
56
|
+
const [dm, data] = source.split(",");
|
|
50
57
|
if (!dm.startsWith("data:")) {
|
|
51
58
|
throw new Error("Please provide image as base64 encoded data URL");
|
|
52
59
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google-genai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Sample integration for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"author": "LangChain",
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@google/generative-ai": "^0.
|
|
42
|
+
"@google/generative-ai": "^0.7.0",
|
|
43
43
|
"@langchain/core": "~0.1.5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"eslint-plugin-import": "^2.27.5",
|
|
59
59
|
"eslint-plugin-no-instanceof": "^1.0.1",
|
|
60
60
|
"eslint-plugin-prettier": "^4.2.1",
|
|
61
|
-
"hnswlib-node": "^
|
|
61
|
+
"hnswlib-node": "^3.0.0",
|
|
62
62
|
"jest": "^29.5.0",
|
|
63
63
|
"jest-environment-node": "^29.6.4",
|
|
64
64
|
"prettier": "^2.8.3",
|