@langchain/google-common 0.0.0 → 0.0.2
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 +7 -2
- package/dist/chat_models.cjs +115 -7
- package/dist/chat_models.d.ts +16 -6
- package/dist/chat_models.js +116 -8
- package/dist/connection.cjs +48 -4
- package/dist/connection.d.ts +14 -7
- package/dist/connection.js +48 -4
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/llms.cjs +91 -24
- package/dist/llms.d.ts +21 -12
- package/dist/llms.js +93 -26
- package/dist/types.d.ts +66 -11
- package/dist/utils/common.cjs +19 -12
- package/dist/utils/common.d.ts +3 -3
- package/dist/utils/common.js +19 -12
- package/dist/utils/failed_handler.cjs +37 -0
- package/dist/utils/failed_handler.d.ts +3 -0
- package/dist/utils/failed_handler.js +32 -0
- package/dist/utils/gemini.cjs +321 -25
- package/dist/utils/gemini.d.ts +53 -3
- package/dist/utils/gemini.js +308 -23
- package/dist/utils/index.cjs +23 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/safety.cjs +23 -0
- package/dist/utils/safety.d.ts +6 -0
- package/dist/utils/safety.js +19 -0
- package/dist/utils/zod_to_gemini_parameters.cjs +15 -0
- package/dist/utils/zod_to_gemini_parameters.d.ts +3 -0
- package/dist/utils/zod_to_gemini_parameters.js +11 -0
- package/index.d.cts +1 -0
- package/package.json +42 -7
- package/types.cjs +1 -0
- package/types.d.cts +1 -0
- package/types.d.ts +1 -0
- package/types.js +1 -0
- package/utils.cjs +1 -0
- package/utils.d.cts +1 -0
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
package/dist/utils/gemini.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { AIMessage, AIMessageChunk, } from "@langchain/core/messages";
|
|
2
2
|
import { ChatGenerationChunk, } from "@langchain/core/outputs";
|
|
3
|
+
import { GoogleAISafetyError } from "./safety.js";
|
|
3
4
|
function messageContentText(content) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
if (content?.text && content?.text.length > 0) {
|
|
6
|
+
return {
|
|
7
|
+
text: content.text,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
7
13
|
}
|
|
8
14
|
function messageContentImageUrl(content) {
|
|
9
15
|
const url = typeof content.image_url === "string"
|
|
@@ -14,15 +20,19 @@ function messageContentImageUrl(content) {
|
|
|
14
20
|
}
|
|
15
21
|
if (url.startsWith("data:")) {
|
|
16
22
|
return {
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
inlineData: {
|
|
24
|
+
mimeType: url.split(":")[1].split(";")[0],
|
|
25
|
+
data: url.split(",")[1],
|
|
26
|
+
},
|
|
19
27
|
};
|
|
20
28
|
}
|
|
21
29
|
else {
|
|
22
30
|
// FIXME - need some way to get mime type
|
|
23
31
|
return {
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
fileData: {
|
|
33
|
+
mimeType: "image/png",
|
|
34
|
+
fileUri: url,
|
|
35
|
+
},
|
|
26
36
|
};
|
|
27
37
|
}
|
|
28
38
|
}
|
|
@@ -37,22 +47,60 @@ export function messageContentToParts(content) {
|
|
|
37
47
|
]
|
|
38
48
|
: content;
|
|
39
49
|
// eslint-disable-next-line array-callback-return
|
|
40
|
-
const parts = messageContent
|
|
41
|
-
|
|
50
|
+
const parts = messageContent
|
|
51
|
+
.map((content) => {
|
|
42
52
|
switch (content.type) {
|
|
43
53
|
case "text":
|
|
44
54
|
return messageContentText(content);
|
|
45
55
|
case "image_url":
|
|
46
56
|
return messageContentImageUrl(content);
|
|
57
|
+
default:
|
|
58
|
+
throw new Error(`Unsupported type received while converting message to message parts`);
|
|
47
59
|
}
|
|
48
|
-
})
|
|
60
|
+
})
|
|
61
|
+
.reduce((acc, val) => {
|
|
62
|
+
if (val) {
|
|
63
|
+
return [...acc, val];
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return acc;
|
|
67
|
+
}
|
|
68
|
+
}, []);
|
|
49
69
|
return parts;
|
|
50
70
|
}
|
|
71
|
+
function messageToolCallsToParts(toolCalls) {
|
|
72
|
+
if (!toolCalls || toolCalls.length === 0) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
return toolCalls.map((tool) => {
|
|
76
|
+
let args = {};
|
|
77
|
+
if (tool?.function?.arguments) {
|
|
78
|
+
const argStr = tool.function.arguments;
|
|
79
|
+
args = JSON.parse(argStr);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
functionCall: {
|
|
83
|
+
name: tool.function.name,
|
|
84
|
+
args,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function messageKwargsToParts(kwargs) {
|
|
90
|
+
const ret = [];
|
|
91
|
+
if (kwargs?.tool_calls) {
|
|
92
|
+
ret.push(...messageToolCallsToParts(kwargs.tool_calls));
|
|
93
|
+
}
|
|
94
|
+
return ret;
|
|
95
|
+
}
|
|
51
96
|
function roleMessageToContent(role, message) {
|
|
97
|
+
const contentParts = messageContentToParts(message.content);
|
|
98
|
+
const toolParts = messageKwargsToParts(message.additional_kwargs);
|
|
99
|
+
const parts = [...contentParts, ...toolParts];
|
|
52
100
|
return [
|
|
53
101
|
{
|
|
54
102
|
role,
|
|
55
|
-
parts
|
|
103
|
+
parts,
|
|
56
104
|
},
|
|
57
105
|
];
|
|
58
106
|
}
|
|
@@ -62,6 +110,32 @@ function systemMessageToContent(message) {
|
|
|
62
110
|
...roleMessageToContent("model", new AIMessage("Ok")),
|
|
63
111
|
];
|
|
64
112
|
}
|
|
113
|
+
function toolMessageToContent(message) {
|
|
114
|
+
const contentStr = typeof message.content === "string"
|
|
115
|
+
? message.content
|
|
116
|
+
: message.content.reduce((acc, content) => {
|
|
117
|
+
if (content.type === "text") {
|
|
118
|
+
return acc + content.text;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
return acc;
|
|
122
|
+
}
|
|
123
|
+
}, "");
|
|
124
|
+
const content = JSON.parse(contentStr);
|
|
125
|
+
return [
|
|
126
|
+
{
|
|
127
|
+
role: "function",
|
|
128
|
+
parts: [
|
|
129
|
+
{
|
|
130
|
+
functionResponse: {
|
|
131
|
+
name: message.tool_call_id,
|
|
132
|
+
response: content,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
}
|
|
65
139
|
export function baseMessageToContent(message) {
|
|
66
140
|
const type = message._getType();
|
|
67
141
|
switch (type) {
|
|
@@ -71,6 +145,8 @@ export function baseMessageToContent(message) {
|
|
|
71
145
|
return roleMessageToContent("user", message);
|
|
72
146
|
case "ai":
|
|
73
147
|
return roleMessageToContent("model", message);
|
|
148
|
+
case "tool":
|
|
149
|
+
return toolMessageToContent(message);
|
|
74
150
|
default:
|
|
75
151
|
console.log(`Unsupported message type: ${type}`);
|
|
76
152
|
return [];
|
|
@@ -85,25 +161,28 @@ function textPartToMessageContent(part) {
|
|
|
85
161
|
function inlineDataPartToMessageContent(part) {
|
|
86
162
|
return {
|
|
87
163
|
type: "image_url",
|
|
88
|
-
image_url: `data:${part.mimeType};base64,${part.data}`,
|
|
164
|
+
image_url: `data:${part.inlineData.mimeType};base64,${part.inlineData.data}`,
|
|
89
165
|
};
|
|
90
166
|
}
|
|
91
167
|
function fileDataPartToMessageContent(part) {
|
|
92
168
|
return {
|
|
93
169
|
type: "image_url",
|
|
94
|
-
image_url: part.fileUri,
|
|
170
|
+
image_url: part.fileData.fileUri,
|
|
95
171
|
};
|
|
96
172
|
}
|
|
97
173
|
export function partsToMessageContent(parts) {
|
|
98
174
|
return parts
|
|
99
175
|
.map((part) => {
|
|
100
|
-
if (
|
|
176
|
+
if (part === undefined || part === null) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
else if ("text" in part) {
|
|
101
180
|
return textPartToMessageContent(part);
|
|
102
181
|
}
|
|
103
|
-
else if ("
|
|
182
|
+
else if ("inlineData" in part) {
|
|
104
183
|
return inlineDataPartToMessageContent(part);
|
|
105
184
|
}
|
|
106
|
-
else if ("
|
|
185
|
+
else if ("fileData" in part) {
|
|
107
186
|
return fileDataPartToMessageContent(part);
|
|
108
187
|
}
|
|
109
188
|
else {
|
|
@@ -117,6 +196,49 @@ export function partsToMessageContent(parts) {
|
|
|
117
196
|
return acc;
|
|
118
197
|
}, []);
|
|
119
198
|
}
|
|
199
|
+
function toolRawToTool(raw) {
|
|
200
|
+
return {
|
|
201
|
+
id: raw.id,
|
|
202
|
+
type: raw.type,
|
|
203
|
+
function: {
|
|
204
|
+
name: raw.function.name,
|
|
205
|
+
arguments: JSON.stringify(raw.function.arguments),
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function functionCallPartToToolRaw(part) {
|
|
210
|
+
return {
|
|
211
|
+
id: part?.functionCall?.name ?? "",
|
|
212
|
+
type: "function",
|
|
213
|
+
function: {
|
|
214
|
+
name: part.functionCall.name,
|
|
215
|
+
arguments: part.functionCall.args ?? {},
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
export function partsToToolsRaw(parts) {
|
|
220
|
+
return parts
|
|
221
|
+
.map((part) => {
|
|
222
|
+
if (part === undefined || part === null) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
else if ("functionCall" in part) {
|
|
226
|
+
return functionCallPartToToolRaw(part);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
.reduce((acc, content) => {
|
|
233
|
+
if (content) {
|
|
234
|
+
acc.push(content);
|
|
235
|
+
}
|
|
236
|
+
return acc;
|
|
237
|
+
}, []);
|
|
238
|
+
}
|
|
239
|
+
export function toolsRawToTools(raws) {
|
|
240
|
+
return raws.map((raw) => toolRawToTool(raw));
|
|
241
|
+
}
|
|
120
242
|
export function responseToGenerateContentResponseData(response) {
|
|
121
243
|
if ("nextChunk" in response.data) {
|
|
122
244
|
throw new Error("Cannot convert Stream to GenerateContentResponseData");
|
|
@@ -153,12 +275,32 @@ export function responseToString(response) {
|
|
|
153
275
|
}, "");
|
|
154
276
|
return ret;
|
|
155
277
|
}
|
|
278
|
+
function safeResponseTo(response, safetyHandler, responseTo) {
|
|
279
|
+
try {
|
|
280
|
+
const safeResponse = safetyHandler.handle(response);
|
|
281
|
+
return responseTo(safeResponse);
|
|
282
|
+
}
|
|
283
|
+
catch (xx) {
|
|
284
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
285
|
+
if (xx instanceof GoogleAISafetyError) {
|
|
286
|
+
const ret = responseTo(xx.response);
|
|
287
|
+
xx.reply = ret;
|
|
288
|
+
}
|
|
289
|
+
throw xx;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
export function safeResponseToString(response, safetyHandler) {
|
|
293
|
+
return safeResponseTo(response, safetyHandler, responseToString);
|
|
294
|
+
}
|
|
156
295
|
export function responseToGeneration(response) {
|
|
157
296
|
return {
|
|
158
297
|
text: responseToString(response),
|
|
159
298
|
generationInfo: response,
|
|
160
299
|
};
|
|
161
300
|
}
|
|
301
|
+
export function safeResponseToGeneration(response, safetyHandler) {
|
|
302
|
+
return safeResponseTo(response, safetyHandler, responseToGeneration);
|
|
303
|
+
}
|
|
162
304
|
export function responseToChatGeneration(response) {
|
|
163
305
|
return new ChatGenerationChunk({
|
|
164
306
|
text: responseToString(response),
|
|
@@ -166,9 +308,29 @@ export function responseToChatGeneration(response) {
|
|
|
166
308
|
generationInfo: response,
|
|
167
309
|
});
|
|
168
310
|
}
|
|
311
|
+
export function safeResponseToChatGeneration(response, safetyHandler) {
|
|
312
|
+
return safeResponseTo(response, safetyHandler, responseToChatGeneration);
|
|
313
|
+
}
|
|
314
|
+
export function chunkToString(chunk) {
|
|
315
|
+
if (chunk === null) {
|
|
316
|
+
return "";
|
|
317
|
+
}
|
|
318
|
+
else if (typeof chunk.content === "string") {
|
|
319
|
+
return chunk.content;
|
|
320
|
+
}
|
|
321
|
+
else if (chunk.content.length === 0) {
|
|
322
|
+
return "";
|
|
323
|
+
}
|
|
324
|
+
else if (chunk.content[0].type === "text") {
|
|
325
|
+
return chunk.content[0].text;
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
throw new Error(`Unexpected chunk: ${chunk}`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
169
331
|
export function partToMessage(part) {
|
|
170
|
-
const
|
|
171
|
-
return new AIMessageChunk(
|
|
332
|
+
const fields = partsToBaseMessageFields([part]);
|
|
333
|
+
return new AIMessageChunk(fields);
|
|
172
334
|
}
|
|
173
335
|
export function partToChatGeneration(part) {
|
|
174
336
|
const message = partToMessage(part);
|
|
@@ -183,14 +345,29 @@ export function responseToChatGenerations(response) {
|
|
|
183
345
|
const ret = parts.map((part) => partToChatGeneration(part));
|
|
184
346
|
return ret;
|
|
185
347
|
}
|
|
186
|
-
export function
|
|
348
|
+
export function responseToBaseMessageFields(response) {
|
|
187
349
|
const parts = responseToParts(response);
|
|
188
|
-
return
|
|
350
|
+
return partsToBaseMessageFields(parts);
|
|
351
|
+
}
|
|
352
|
+
export function partsToBaseMessageFields(parts) {
|
|
353
|
+
const fields = {
|
|
354
|
+
content: partsToMessageContent(parts),
|
|
355
|
+
};
|
|
356
|
+
const rawTools = partsToToolsRaw(parts);
|
|
357
|
+
if (rawTools.length > 0) {
|
|
358
|
+
const tools = toolsRawToTools(rawTools);
|
|
359
|
+
fields.additional_kwargs = {
|
|
360
|
+
tool_calls: tools,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
return fields;
|
|
189
364
|
}
|
|
190
365
|
export function responseToBaseMessage(response) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
366
|
+
const fields = responseToBaseMessageFields(response);
|
|
367
|
+
return new AIMessage(fields);
|
|
368
|
+
}
|
|
369
|
+
export function safeResponseToBaseMessage(response, safetyHandler) {
|
|
370
|
+
return safeResponseTo(response, safetyHandler, responseToBaseMessage);
|
|
194
371
|
}
|
|
195
372
|
export function responseToChatResult(response) {
|
|
196
373
|
const generations = responseToChatGenerations(response);
|
|
@@ -199,6 +376,9 @@ export function responseToChatResult(response) {
|
|
|
199
376
|
llmOutput: response,
|
|
200
377
|
};
|
|
201
378
|
}
|
|
379
|
+
export function safeResponseToChatResult(response, safetyHandler) {
|
|
380
|
+
return safeResponseTo(response, safetyHandler, responseToChatResult);
|
|
381
|
+
}
|
|
202
382
|
export function validateGeminiParams(params) {
|
|
203
383
|
if (params.maxOutputTokens && params.maxOutputTokens < 0) {
|
|
204
384
|
throw new Error("`maxOutputTokens` must be a positive integer");
|
|
@@ -217,3 +397,108 @@ export function validateGeminiParams(params) {
|
|
|
217
397
|
export function isModelGemini(modelName) {
|
|
218
398
|
return modelName.toLowerCase().startsWith("gemini");
|
|
219
399
|
}
|
|
400
|
+
export class DefaultGeminiSafetyHandler {
|
|
401
|
+
constructor(settings) {
|
|
402
|
+
Object.defineProperty(this, "errorFinish", {
|
|
403
|
+
enumerable: true,
|
|
404
|
+
configurable: true,
|
|
405
|
+
writable: true,
|
|
406
|
+
value: ["SAFETY", "RECITATION", "OTHER"]
|
|
407
|
+
});
|
|
408
|
+
this.errorFinish = settings?.errorFinish ?? this.errorFinish;
|
|
409
|
+
}
|
|
410
|
+
handleDataPromptFeedback(response, data) {
|
|
411
|
+
// Check to see if our prompt was blocked in the first place
|
|
412
|
+
const promptFeedback = data?.promptFeedback;
|
|
413
|
+
const blockReason = promptFeedback?.blockReason;
|
|
414
|
+
if (blockReason) {
|
|
415
|
+
throw new GoogleAISafetyError(response, `Prompt blocked: ${blockReason}`);
|
|
416
|
+
}
|
|
417
|
+
return data;
|
|
418
|
+
}
|
|
419
|
+
handleDataFinishReason(response, data) {
|
|
420
|
+
const firstCandidate = data?.candidates?.[0];
|
|
421
|
+
const finishReason = firstCandidate?.finishReason;
|
|
422
|
+
if (this.errorFinish.includes(finishReason)) {
|
|
423
|
+
throw new GoogleAISafetyError(response, `Finish reason: ${finishReason}`);
|
|
424
|
+
}
|
|
425
|
+
return data;
|
|
426
|
+
}
|
|
427
|
+
handleData(response, data) {
|
|
428
|
+
let ret = data;
|
|
429
|
+
ret = this.handleDataPromptFeedback(response, ret);
|
|
430
|
+
ret = this.handleDataFinishReason(response, ret);
|
|
431
|
+
return ret;
|
|
432
|
+
}
|
|
433
|
+
handle(response) {
|
|
434
|
+
let newdata;
|
|
435
|
+
if ("nextChunk" in response.data) {
|
|
436
|
+
// TODO: This is a stream. How to handle?
|
|
437
|
+
newdata = response.data;
|
|
438
|
+
}
|
|
439
|
+
else if (Array.isArray(response.data)) {
|
|
440
|
+
// If it is an array, try to handle every item in the array
|
|
441
|
+
try {
|
|
442
|
+
newdata = response.data.map((item) => this.handleData(response, item));
|
|
443
|
+
}
|
|
444
|
+
catch (xx) {
|
|
445
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
446
|
+
if (xx instanceof GoogleAISafetyError) {
|
|
447
|
+
throw new GoogleAISafetyError(response, xx.message);
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
throw xx;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
const data = response.data;
|
|
456
|
+
newdata = this.handleData(response, data);
|
|
457
|
+
}
|
|
458
|
+
return {
|
|
459
|
+
...response,
|
|
460
|
+
data: newdata,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
export class MessageGeminiSafetyHandler extends DefaultGeminiSafetyHandler {
|
|
465
|
+
constructor(settings) {
|
|
466
|
+
super(settings);
|
|
467
|
+
Object.defineProperty(this, "msg", {
|
|
468
|
+
enumerable: true,
|
|
469
|
+
configurable: true,
|
|
470
|
+
writable: true,
|
|
471
|
+
value: ""
|
|
472
|
+
});
|
|
473
|
+
Object.defineProperty(this, "forceNewMessage", {
|
|
474
|
+
enumerable: true,
|
|
475
|
+
configurable: true,
|
|
476
|
+
writable: true,
|
|
477
|
+
value: false
|
|
478
|
+
});
|
|
479
|
+
this.msg = settings?.msg ?? this.msg;
|
|
480
|
+
this.forceNewMessage = settings?.forceNewMessage ?? this.forceNewMessage;
|
|
481
|
+
}
|
|
482
|
+
setMessage(data) {
|
|
483
|
+
const ret = data;
|
|
484
|
+
if (this.forceNewMessage ||
|
|
485
|
+
!data?.candidates?.[0]?.content?.parts?.length) {
|
|
486
|
+
ret.candidates = data.candidates ?? [];
|
|
487
|
+
ret.candidates[0] = data.candidates[0] ?? {};
|
|
488
|
+
ret.candidates[0].content = data.candidates[0].content ?? {};
|
|
489
|
+
ret.candidates[0].content = {
|
|
490
|
+
role: "model",
|
|
491
|
+
parts: [{ text: this.msg }],
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
return ret;
|
|
495
|
+
}
|
|
496
|
+
handleData(response, data) {
|
|
497
|
+
try {
|
|
498
|
+
return super.handleData(response, data);
|
|
499
|
+
}
|
|
500
|
+
catch (xx) {
|
|
501
|
+
return this.setMessage(data);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common.cjs"), exports);
|
|
18
|
+
__exportStar(require("./failed_handler.cjs"), exports);
|
|
19
|
+
__exportStar(require("./gemini.cjs"), exports);
|
|
20
|
+
__exportStar(require("./zod_to_gemini_parameters.cjs"), exports);
|
|
21
|
+
__exportStar(require("./palm.cjs"), exports);
|
|
22
|
+
__exportStar(require("./safety.cjs"), exports);
|
|
23
|
+
__exportStar(require("./stream.cjs"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GoogleAISafetyError = void 0;
|
|
4
|
+
class GoogleAISafetyError extends Error {
|
|
5
|
+
constructor(response, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
Object.defineProperty(this, "response", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: void 0
|
|
12
|
+
});
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
Object.defineProperty(this, "reply", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: ""
|
|
19
|
+
});
|
|
20
|
+
this.response = response;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.GoogleAISafetyError = GoogleAISafetyError;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class GoogleAISafetyError extends Error {
|
|
2
|
+
constructor(response, message) {
|
|
3
|
+
super(message);
|
|
4
|
+
Object.defineProperty(this, "response", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: void 0
|
|
9
|
+
});
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
Object.defineProperty(this, "reply", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: ""
|
|
16
|
+
});
|
|
17
|
+
this.response = response;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zodToGeminiParameters = void 0;
|
|
4
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
|
+
function zodToGeminiParameters(
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
zodObj) {
|
|
8
|
+
// Gemini doesn't accept either the $schema or additionalProperties
|
|
9
|
+
// attributes, so we need to explicitly remove them.
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
const jsonSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(zodObj);
|
|
12
|
+
const { $schema, additionalProperties, ...rest } = jsonSchema;
|
|
13
|
+
return rest;
|
|
14
|
+
}
|
|
15
|
+
exports.zodToGeminiParameters = zodToGeminiParameters;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
+
export function zodToGeminiParameters(
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
+
zodObj) {
|
|
5
|
+
// Gemini doesn't accept either the $schema or additionalProperties
|
|
6
|
+
// attributes, so we need to explicitly remove them.
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
const jsonSchema = zodToJsonSchema(zodObj);
|
|
9
|
+
const { $schema, additionalProperties, ...rest } = jsonSchema;
|
|
10
|
+
return rest;
|
|
11
|
+
}
|
package/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/index.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Core types and classes for Google services.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git@github.com:langchain-ai/langchainjs.git"
|
|
14
14
|
},
|
|
15
|
+
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-google-common/",
|
|
15
16
|
"scripts": {
|
|
16
17
|
"build": "yarn run build:deps && yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts",
|
|
17
18
|
"build:deps": "yarn run turbo:command build --filter=@langchain/core",
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
"lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
|
|
24
25
|
"lint": "yarn lint:eslint && yarn lint:dpdm",
|
|
25
26
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
|
|
26
|
-
"clean": "rm -rf dist/ && NODE_OPTIONS=--max-old-space-size=4096 yarn create-entrypoints --
|
|
27
|
+
"clean": "rm -rf dist/ && NODE_OPTIONS=--max-old-space-size=4096 yarn lc-build --config ./langchain.config.js --create-entrypoints --pre",
|
|
27
28
|
"prepack": "yarn build",
|
|
28
29
|
"test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
|
|
29
30
|
"test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
|
|
@@ -38,11 +39,12 @@
|
|
|
38
39
|
"author": "LangChain",
|
|
39
40
|
"license": "MIT",
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@langchain/core": "~0.1.1"
|
|
42
|
+
"@langchain/core": "~0.1.1",
|
|
43
|
+
"zod-to-json-schema": "^3.22.4"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@jest/globals": "^29.5.0",
|
|
45
|
-
"@langchain/scripts": "
|
|
47
|
+
"@langchain/scripts": "~0.0",
|
|
46
48
|
"@swc/core": "^1.3.90",
|
|
47
49
|
"@swc/jest": "^0.2.29",
|
|
48
50
|
"@tsconfig/recommended": "^1.0.3",
|
|
@@ -59,25 +61,58 @@
|
|
|
59
61
|
"jest": "^29.5.0",
|
|
60
62
|
"jest-environment-node": "^29.6.4",
|
|
61
63
|
"prettier": "^2.8.3",
|
|
64
|
+
"release-it": "^15.10.1",
|
|
62
65
|
"rollup": "^4.5.2",
|
|
63
66
|
"ts-jest": "^29.1.0",
|
|
64
|
-
"typescript": "<5.2.0"
|
|
67
|
+
"typescript": "<5.2.0",
|
|
68
|
+
"zod": "^3.22.4"
|
|
65
69
|
},
|
|
66
70
|
"publishConfig": {
|
|
67
71
|
"access": "public"
|
|
68
72
|
},
|
|
69
73
|
"exports": {
|
|
70
74
|
".": {
|
|
71
|
-
"types":
|
|
75
|
+
"types": {
|
|
76
|
+
"import": "./index.d.ts",
|
|
77
|
+
"require": "./index.d.cts",
|
|
78
|
+
"default": "./index.d.ts"
|
|
79
|
+
},
|
|
72
80
|
"import": "./index.js",
|
|
73
81
|
"require": "./index.cjs"
|
|
74
82
|
},
|
|
83
|
+
"./utils": {
|
|
84
|
+
"types": {
|
|
85
|
+
"import": "./utils.d.ts",
|
|
86
|
+
"require": "./utils.d.cts",
|
|
87
|
+
"default": "./utils.d.ts"
|
|
88
|
+
},
|
|
89
|
+
"import": "./utils.js",
|
|
90
|
+
"require": "./utils.cjs"
|
|
91
|
+
},
|
|
92
|
+
"./types": {
|
|
93
|
+
"types": {
|
|
94
|
+
"import": "./types.d.ts",
|
|
95
|
+
"require": "./types.d.cts",
|
|
96
|
+
"default": "./types.d.ts"
|
|
97
|
+
},
|
|
98
|
+
"import": "./types.js",
|
|
99
|
+
"require": "./types.cjs"
|
|
100
|
+
},
|
|
75
101
|
"./package.json": "./package.json"
|
|
76
102
|
},
|
|
77
103
|
"files": [
|
|
78
104
|
"dist/",
|
|
79
105
|
"index.cjs",
|
|
80
106
|
"index.js",
|
|
81
|
-
"index.d.ts"
|
|
107
|
+
"index.d.ts",
|
|
108
|
+
"index.d.cts",
|
|
109
|
+
"utils.cjs",
|
|
110
|
+
"utils.js",
|
|
111
|
+
"utils.d.ts",
|
|
112
|
+
"utils.d.cts",
|
|
113
|
+
"types.cjs",
|
|
114
|
+
"types.js",
|
|
115
|
+
"types.d.ts",
|
|
116
|
+
"types.d.cts"
|
|
82
117
|
]
|
|
83
118
|
}
|
package/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/types.cjs');
|
package/types.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/types.js'
|