@langchain/google-genai 0.0.11 → 0.0.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.
@@ -44,7 +44,7 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
44
44
  };
45
45
  }
46
46
  get _isMultimodalModel() {
47
- return this.model.includes("vision");
47
+ return this.model.includes("vision") || this.model.startsWith("gemini-1.5");
48
48
  }
49
49
  constructor(fields) {
50
50
  super(fields ?? {});
@@ -41,7 +41,7 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
41
41
  };
42
42
  }
43
43
  get _isMultimodalModel() {
44
- return this.model.includes("vision");
44
+ return this.model.includes("vision") || this.model.startsWith("gemini-1.5");
45
45
  }
46
46
  constructor(fields) {
47
47
  super(fields ?? {});
package/dist/utils.cjs CHANGED
@@ -34,6 +34,17 @@ function convertAuthorToRole(author) {
34
34
  }
35
35
  }
36
36
  exports.convertAuthorToRole = convertAuthorToRole;
37
+ function messageContentMedia(content) {
38
+ if ("mimeType" in content && "data" in content) {
39
+ return {
40
+ inlineData: {
41
+ mimeType: content.mimeType,
42
+ data: content.data,
43
+ },
44
+ };
45
+ }
46
+ throw new Error("Invalid media content");
47
+ }
37
48
  function convertMessageContentToParts(content, isMultimodalModel) {
38
49
  if (typeof content === "string") {
39
50
  return [{ text: content }];
@@ -48,10 +59,17 @@ function convertMessageContentToParts(content, isMultimodalModel) {
48
59
  if (!isMultimodalModel) {
49
60
  throw new Error(`This model does not support images`);
50
61
  }
51
- if (typeof c.image_url !== "string") {
62
+ let source;
63
+ if (typeof c.image_url === "string") {
64
+ source = c.image_url;
65
+ }
66
+ else if (typeof c.image_url === "object" && "url" in c.image_url) {
67
+ source = c.image_url.url;
68
+ }
69
+ else {
52
70
  throw new Error("Please provide image as base64 encoded data URL");
53
71
  }
54
- const [dm, data] = c.image_url.split(",");
72
+ const [dm, data] = source.split(",");
55
73
  if (!dm.startsWith("data:")) {
56
74
  throw new Error("Please provide image as base64 encoded data URL");
57
75
  }
@@ -66,6 +84,9 @@ function convertMessageContentToParts(content, isMultimodalModel) {
66
84
  },
67
85
  };
68
86
  }
87
+ else if (c.type === "media") {
88
+ return messageContentMedia(c);
89
+ }
69
90
  throw new Error(`Unknown content type ${c.type}`);
70
91
  });
71
92
  }
package/dist/utils.js CHANGED
@@ -29,6 +29,17 @@ export function convertAuthorToRole(author) {
29
29
  throw new Error(`Unknown / unsupported author: ${author}`);
30
30
  }
31
31
  }
32
+ function messageContentMedia(content) {
33
+ if ("mimeType" in content && "data" in content) {
34
+ return {
35
+ inlineData: {
36
+ mimeType: content.mimeType,
37
+ data: content.data,
38
+ },
39
+ };
40
+ }
41
+ throw new Error("Invalid media content");
42
+ }
32
43
  export function convertMessageContentToParts(content, isMultimodalModel) {
33
44
  if (typeof content === "string") {
34
45
  return [{ text: content }];
@@ -43,10 +54,17 @@ export function convertMessageContentToParts(content, isMultimodalModel) {
43
54
  if (!isMultimodalModel) {
44
55
  throw new Error(`This model does not support images`);
45
56
  }
46
- if (typeof c.image_url !== "string") {
57
+ let source;
58
+ if (typeof c.image_url === "string") {
59
+ source = c.image_url;
60
+ }
61
+ else if (typeof c.image_url === "object" && "url" in c.image_url) {
62
+ source = c.image_url.url;
63
+ }
64
+ else {
47
65
  throw new Error("Please provide image as base64 encoded data URL");
48
66
  }
49
- const [dm, data] = c.image_url.split(",");
67
+ const [dm, data] = source.split(",");
50
68
  if (!dm.startsWith("data:")) {
51
69
  throw new Error("Please provide image as base64 encoded data URL");
52
70
  }
@@ -61,6 +79,9 @@ export function convertMessageContentToParts(content, isMultimodalModel) {
61
79
  },
62
80
  };
63
81
  }
82
+ else if (c.type === "media") {
83
+ return messageContentMedia(c);
84
+ }
64
85
  throw new Error(`Unknown content type ${c.type}`);
65
86
  });
66
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/google-genai",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Sample integration for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {
@@ -39,8 +39,8 @@
39
39
  "author": "LangChain",
40
40
  "license": "MIT",
41
41
  "dependencies": {
42
- "@google/generative-ai": "^0.1.3",
43
- "@langchain/core": "~0.1.5"
42
+ "@google/generative-ai": "^0.7.0",
43
+ "@langchain/core": "<0.3.0 || >0.1.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@jest/globals": "^29.5.0",
@@ -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": "^1.4.2",
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",