langchain-google-genai 2.1.10__py3-none-any.whl → 2.1.12__py3-none-any.whl
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.
Potentially problematic release.
This version of langchain-google-genai might be problematic. Click here for more details.
- langchain_google_genai/__init__.py +3 -3
- langchain_google_genai/_common.py +28 -17
- langchain_google_genai/_function_utils.py +59 -59
- langchain_google_genai/_genai_extension.py +35 -21
- langchain_google_genai/_image_utils.py +10 -9
- langchain_google_genai/chat_models.py +459 -254
- langchain_google_genai/embeddings.py +62 -15
- langchain_google_genai/genai_aqa.py +15 -15
- langchain_google_genai/google_vector_store.py +26 -16
- langchain_google_genai/llms.py +9 -8
- {langchain_google_genai-2.1.10.dist-info → langchain_google_genai-2.1.12.dist-info}/METADATA +43 -39
- langchain_google_genai-2.1.12.dist-info/RECORD +17 -0
- {langchain_google_genai-2.1.10.dist-info → langchain_google_genai-2.1.12.dist-info}/WHEEL +1 -1
- langchain_google_genai-2.1.12.dist-info/entry_points.txt +4 -0
- langchain_google_genai-2.1.10.dist-info/RECORD +0 -16
- {langchain_google_genai-2.1.10.dist-info → langchain_google_genai-2.1.12.dist-info/licenses}/LICENSE +0 -0
|
@@ -8,13 +8,13 @@ from enum import Enum
|
|
|
8
8
|
from typing import Any, Dict
|
|
9
9
|
from urllib.parse import urlparse
|
|
10
10
|
|
|
11
|
-
import filetype # type: ignore[import]
|
|
11
|
+
import filetype # type: ignore[import-untyped]
|
|
12
12
|
import requests
|
|
13
13
|
from google.ai.generativelanguage_v1beta.types import Part
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class Route(Enum):
|
|
17
|
-
"""Image Loading Route"""
|
|
17
|
+
"""Image Loading Route."""
|
|
18
18
|
|
|
19
19
|
BASE64 = 1
|
|
20
20
|
LOCAL_FILE = 2
|
|
@@ -40,7 +40,6 @@ class ImageBytesLoader:
|
|
|
40
40
|
Returns:
|
|
41
41
|
Image bytes.
|
|
42
42
|
"""
|
|
43
|
-
|
|
44
43
|
route = self._route(image_string)
|
|
45
44
|
|
|
46
45
|
if route == Route.BASE64:
|
|
@@ -50,18 +49,20 @@ class ImageBytesLoader:
|
|
|
50
49
|
return self._bytes_from_url(image_string)
|
|
51
50
|
|
|
52
51
|
if route == Route.LOCAL_FILE:
|
|
53
|
-
|
|
52
|
+
msg = (
|
|
54
53
|
"Loading from local files is no longer supported for security reasons. "
|
|
55
54
|
"Please pass in images as Google Cloud Storage URI, "
|
|
56
55
|
"b64 encoded image string (data:image/...), or valid image url."
|
|
57
56
|
)
|
|
57
|
+
raise ValueError(msg)
|
|
58
58
|
return self._bytes_from_file(image_string)
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
msg = (
|
|
61
61
|
"Image string must be one of: Google Cloud Storage URI, "
|
|
62
62
|
"b64 encoded image string (data:image/...), or valid image url."
|
|
63
63
|
f"Instead got '{image_string}'."
|
|
64
64
|
)
|
|
65
|
+
raise ValueError(msg)
|
|
65
66
|
|
|
66
67
|
def load_part(self, image_string: str) -> Part:
|
|
67
68
|
"""Gets Part for loading from Gemini.
|
|
@@ -110,11 +111,12 @@ class ImageBytesLoader:
|
|
|
110
111
|
if os.path.exists(image_string):
|
|
111
112
|
return Route.LOCAL_FILE
|
|
112
113
|
|
|
113
|
-
|
|
114
|
+
msg = (
|
|
114
115
|
"Image string must be one of: "
|
|
115
116
|
"b64 encoded image string (data:image/...) or valid image url."
|
|
116
117
|
f" Instead got '{image_string}'."
|
|
117
118
|
)
|
|
119
|
+
raise ValueError(msg)
|
|
118
120
|
|
|
119
121
|
def _bytes_from_b64(self, base64_image: str) -> bytes:
|
|
120
122
|
"""Gets image bytes from a base64 encoded string.
|
|
@@ -125,7 +127,6 @@ class ImageBytesLoader:
|
|
|
125
127
|
Returns:
|
|
126
128
|
Image bytes
|
|
127
129
|
"""
|
|
128
|
-
|
|
129
130
|
pattern = r"data:image/\w{2,4};base64,(.*)"
|
|
130
131
|
match = re.search(pattern, base64_image)
|
|
131
132
|
|
|
@@ -133,7 +134,8 @@ class ImageBytesLoader:
|
|
|
133
134
|
encoded_string = match.group(1)
|
|
134
135
|
return base64.b64decode(encoded_string)
|
|
135
136
|
|
|
136
|
-
|
|
137
|
+
msg = f"Error in b64 encoded image. Must follow pattern: {pattern}"
|
|
138
|
+
raise ValueError(msg)
|
|
137
139
|
|
|
138
140
|
def _bytes_from_url(self, url: str) -> bytes:
|
|
139
141
|
"""Gets image bytes from a public url.
|
|
@@ -147,7 +149,6 @@ class ImageBytesLoader:
|
|
|
147
149
|
Returns:
|
|
148
150
|
Image bytes
|
|
149
151
|
"""
|
|
150
|
-
|
|
151
152
|
response = requests.get(url)
|
|
152
153
|
|
|
153
154
|
if not response.ok:
|