@langchain/google-common 0.0.3 → 0.0.4
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/utils/gemini.cjs +25 -3
- package/dist/utils/gemini.js +25 -3
- package/package.json +1 -1
package/dist/utils/gemini.cjs
CHANGED
|
@@ -54,12 +54,20 @@ function messageContentToParts(content) {
|
|
|
54
54
|
.map((content) => {
|
|
55
55
|
switch (content.type) {
|
|
56
56
|
case "text":
|
|
57
|
-
|
|
57
|
+
if ("text" in content) {
|
|
58
|
+
return messageContentText(content);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
58
61
|
case "image_url":
|
|
59
|
-
|
|
62
|
+
if ("image_url" in content) {
|
|
63
|
+
// Type guard for MessageContentImageUrl
|
|
64
|
+
return messageContentImageUrl(content);
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
60
67
|
default:
|
|
61
68
|
throw new Error(`Unsupported type received while converting message to message parts`);
|
|
62
69
|
}
|
|
70
|
+
throw new Error(`Cannot coerce "${content.type}" message part into a string.`);
|
|
63
71
|
})
|
|
64
72
|
.reduce((acc, val) => {
|
|
65
73
|
if (val) {
|
|
@@ -393,7 +401,21 @@ function partToChatGeneration(part) {
|
|
|
393
401
|
exports.partToChatGeneration = partToChatGeneration;
|
|
394
402
|
function responseToChatGenerations(response) {
|
|
395
403
|
const parts = responseToParts(response);
|
|
396
|
-
|
|
404
|
+
let ret = parts.map((part) => partToChatGeneration(part));
|
|
405
|
+
if (ret.every((item) => typeof item.message.content === "string")) {
|
|
406
|
+
const combinedContent = ret.map((item) => item.message.content).join("");
|
|
407
|
+
const combinedText = ret.map((item) => item.text).join("");
|
|
408
|
+
ret = [
|
|
409
|
+
new outputs_1.ChatGenerationChunk({
|
|
410
|
+
message: new messages_1.AIMessageChunk({
|
|
411
|
+
content: combinedContent,
|
|
412
|
+
additional_kwargs: ret[ret.length - 1].message.additional_kwargs,
|
|
413
|
+
}),
|
|
414
|
+
text: combinedText,
|
|
415
|
+
generationInfo: ret[ret.length - 1].generationInfo,
|
|
416
|
+
}),
|
|
417
|
+
];
|
|
418
|
+
}
|
|
397
419
|
return ret;
|
|
398
420
|
}
|
|
399
421
|
exports.responseToChatGenerations = responseToChatGenerations;
|
package/dist/utils/gemini.js
CHANGED
|
@@ -51,12 +51,20 @@ export function messageContentToParts(content) {
|
|
|
51
51
|
.map((content) => {
|
|
52
52
|
switch (content.type) {
|
|
53
53
|
case "text":
|
|
54
|
-
|
|
54
|
+
if ("text" in content) {
|
|
55
|
+
return messageContentText(content);
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
55
58
|
case "image_url":
|
|
56
|
-
|
|
59
|
+
if ("image_url" in content) {
|
|
60
|
+
// Type guard for MessageContentImageUrl
|
|
61
|
+
return messageContentImageUrl(content);
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
57
64
|
default:
|
|
58
65
|
throw new Error(`Unsupported type received while converting message to message parts`);
|
|
59
66
|
}
|
|
67
|
+
throw new Error(`Cannot coerce "${content.type}" message part into a string.`);
|
|
60
68
|
})
|
|
61
69
|
.reduce((acc, val) => {
|
|
62
70
|
if (val) {
|
|
@@ -373,7 +381,21 @@ export function partToChatGeneration(part) {
|
|
|
373
381
|
}
|
|
374
382
|
export function responseToChatGenerations(response) {
|
|
375
383
|
const parts = responseToParts(response);
|
|
376
|
-
|
|
384
|
+
let ret = parts.map((part) => partToChatGeneration(part));
|
|
385
|
+
if (ret.every((item) => typeof item.message.content === "string")) {
|
|
386
|
+
const combinedContent = ret.map((item) => item.message.content).join("");
|
|
387
|
+
const combinedText = ret.map((item) => item.text).join("");
|
|
388
|
+
ret = [
|
|
389
|
+
new ChatGenerationChunk({
|
|
390
|
+
message: new AIMessageChunk({
|
|
391
|
+
content: combinedContent,
|
|
392
|
+
additional_kwargs: ret[ret.length - 1].message.additional_kwargs,
|
|
393
|
+
}),
|
|
394
|
+
text: combinedText,
|
|
395
|
+
generationInfo: ret[ret.length - 1].generationInfo,
|
|
396
|
+
}),
|
|
397
|
+
];
|
|
398
|
+
}
|
|
377
399
|
return ret;
|
|
378
400
|
}
|
|
379
401
|
export function responseToBaseMessageFields(response) {
|