langchain-google-genai 2.0.4__tar.gz → 2.0.5__tar.gz

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.

Files changed (16) hide show
  1. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/PKG-INFO +1 -10
  2. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/README.md +0 -7
  3. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/chat_models.py +11 -54
  4. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/llms.py +12 -1
  5. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/pyproject.toml +3 -23
  6. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/LICENSE +0 -0
  7. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/__init__.py +0 -0
  8. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/_common.py +0 -0
  9. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/_enums.py +0 -0
  10. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/_function_utils.py +0 -0
  11. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/_genai_extension.py +0 -0
  12. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/_image_utils.py +0 -0
  13. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/embeddings.py +0 -0
  14. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/genai_aqa.py +0 -0
  15. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/google_vector_store.py +0 -0
  16. {langchain_google_genai-2.0.4 → langchain_google_genai-2.0.5}/langchain_google_genai/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langchain-google-genai
3
- Version: 2.0.4
3
+ Version: 2.0.5
4
4
  Summary: An integration package connecting Google's genai package and LangChain
5
5
  Home-page: https://github.com/langchain-ai/langchain-google
6
6
  License: MIT
@@ -11,10 +11,8 @@ Classifier: Programming Language :: Python :: 3.9
11
11
  Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
- Provides-Extra: images
15
14
  Requires-Dist: google-generativeai (>=0.8.0,<0.9.0)
16
15
  Requires-Dist: langchain-core (>=0.3.15,<0.4)
17
- Requires-Dist: pillow (>=10.1.0,<11.0.0) ; extra == "images"
18
16
  Requires-Dist: pydantic (>=2,<3)
19
17
  Project-URL: Repository, https://github.com/langchain-ai/langchain-google
20
18
  Project-URL: Source Code, https://github.com/langchain-ai/langchain-google/tree/main/libs/genai
@@ -30,12 +28,6 @@ This package contains the LangChain integrations for Gemini through their genera
30
28
  pip install -U langchain-google-genai
31
29
  ```
32
30
 
33
- ### Image utilities
34
- To use image utility methods, like loading images from GCS urls, install with extras group 'images':
35
-
36
- ```bash
37
- pip install -e "langchain-google-genai[images]"
38
- ```
39
31
 
40
32
  ## Chat Models
41
33
 
@@ -83,7 +75,6 @@ The value of `image_url` can be any of the following:
83
75
  - A public image URL
84
76
  - An accessible gcs file (e.g., "gcs://path/to/file.png")
85
77
  - A base64 encoded image (e.g., `data:image/png;base64,abcd124`)
86
- - A PIL image
87
78
 
88
79
 
89
80
 
@@ -8,12 +8,6 @@ This package contains the LangChain integrations for Gemini through their genera
8
8
  pip install -U langchain-google-genai
9
9
  ```
10
10
 
11
- ### Image utilities
12
- To use image utility methods, like loading images from GCS urls, install with extras group 'images':
13
-
14
- ```bash
15
- pip install -e "langchain-google-genai[images]"
16
- ```
17
11
 
18
12
  ## Chat Models
19
13
 
@@ -61,7 +55,6 @@ The value of `image_url` can be any of the following:
61
55
  - A public image URL
62
56
  - An accessible gcs file (e.g., "gcs://path/to/file.png")
63
57
  - A base64 encoded image (e.g., `data:image/png;base64,abcd124`)
64
- - A PIL image
65
58
 
66
59
 
67
60
 
@@ -5,7 +5,6 @@ import json
5
5
  import logging
6
6
  import uuid
7
7
  import warnings
8
- from io import BytesIO
9
8
  from operator import itemgetter
10
9
  from typing import (
11
10
  Any,
@@ -22,7 +21,6 @@ from typing import (
22
21
  Union,
23
22
  cast,
24
23
  )
25
- from urllib.parse import urlparse
26
24
 
27
25
  import google.api_core
28
26
 
@@ -114,16 +112,6 @@ from langchain_google_genai.llms import _BaseGoogleGenerativeAI
114
112
 
115
113
  from . import _genai_extension as genaix
116
114
 
117
- IMAGE_TYPES: Tuple = ()
118
- try:
119
- import PIL
120
- from PIL.Image import Image
121
-
122
- IMAGE_TYPES = IMAGE_TYPES + (Image,)
123
- except ImportError:
124
- PIL = None # type: ignore
125
- Image = None # type: ignore
126
-
127
115
  logger = logging.getLogger(__name__)
128
116
 
129
117
 
@@ -245,46 +233,6 @@ def _is_openai_parts_format(part: dict) -> bool:
245
233
  return "type" in part
246
234
 
247
235
 
248
- def _is_vision_model(model: str) -> bool:
249
- return "vision" in model
250
-
251
-
252
- def _is_url(s: str) -> bool:
253
- try:
254
- result = urlparse(s)
255
- return all([result.scheme, result.netloc])
256
- except Exception as e:
257
- logger.debug(f"Unable to parse URL: {e}")
258
- return False
259
-
260
-
261
- def _is_b64(s: str) -> bool:
262
- return s.startswith("data:image")
263
-
264
-
265
- def _load_image_from_gcs(path: str, project: Optional[str] = None) -> Image:
266
- try:
267
- from google.cloud import storage # type: ignore[attr-defined]
268
- except ImportError:
269
- raise ImportError(
270
- "google-cloud-storage is required to load images from GCS."
271
- " Install it with `pip install google-cloud-storage`"
272
- )
273
- if PIL is None:
274
- raise ImportError(
275
- "PIL is required to load images. Please install it "
276
- "with `pip install pillow`"
277
- )
278
-
279
- gcs_client = storage.Client(project=project)
280
- pieces = path.split("/")
281
- blobs = list(gcs_client.list_blobs(pieces[2], prefix="/".join(pieces[3:])))
282
- if len(blobs) > 1:
283
- raise ValueError(f"Found more than one candidate for {path}!")
284
- img_bytes = blobs[0].download_as_bytes()
285
- return PIL.Image.open(BytesIO(img_bytes))
286
-
287
-
288
236
  def _convert_to_parts(
289
237
  raw_content: Union[str, Sequence[Union[str, dict]]],
290
238
  ) -> List[Part]:
@@ -368,8 +316,17 @@ def _parse_chat_history(
368
316
  continue
369
317
  elif isinstance(message, AIMessage):
370
318
  role = "model"
371
- raw_function_call = message.additional_kwargs.get("function_call")
372
- if raw_function_call:
319
+ if message.tool_calls:
320
+ parts = []
321
+ for tool_call in message.tool_calls:
322
+ function_call = FunctionCall(
323
+ {
324
+ "name": tool_call["name"],
325
+ "args": tool_call["args"],
326
+ }
327
+ )
328
+ parts.append(Part(function_call=function_call))
329
+ elif raw_function_call := message.additional_kwargs.get("function_call"):
373
330
  function_call = FunctionCall(
374
331
  {
375
332
  "name": raw_function_call["name"],
@@ -310,10 +310,21 @@ class GoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseLLM):
310
310
  generation_config=generation_config,
311
311
  safety_settings=kwargs.pop("safety_settings", None),
312
312
  )
313
+ generation_info = None
314
+ if res.usage_metadata is not None:
315
+ generation_info = {
316
+ "usage_metadata": res.to_dict().get("usage_metadata")
317
+ }
318
+
313
319
  candidates = [
314
320
  "".join([p.text for p in c.content.parts]) for c in res.candidates
315
321
  ]
316
- generations.append([Generation(text=c) for c in candidates])
322
+ generations.append(
323
+ [
324
+ Generation(text=c, generation_info=generation_info)
325
+ for c in candidates
326
+ ]
327
+ )
317
328
  else:
318
329
  res = _completion_with_retry(
319
330
  self,
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langchain-google-genai"
3
- version = "2.0.4"
3
+ version = "2.0.5"
4
4
  description = "An integration package connecting Google's genai package and LangChain"
5
5
  authors = []
6
6
  readme = "README.md"
@@ -14,12 +14,8 @@ license = "MIT"
14
14
  python = ">=3.9,<4.0"
15
15
  langchain-core = ">=0.3.15,<0.4"
16
16
  google-generativeai = "^0.8.0"
17
- pillow = { version = "^10.1.0", optional = true }
18
17
  pydantic = ">=2,<3"
19
18
 
20
- [tool.poetry.extras]
21
- images = ["pillow"]
22
-
23
19
  [tool.poetry.group.test]
24
20
  optional = true
25
21
 
@@ -31,15 +27,12 @@ syrupy = "^4.0.2"
31
27
  pytest-watcher = "^0.3.4"
32
28
  pytest-asyncio = "^0.21.1"
33
29
  numpy = "^1.26.2"
34
- langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" }
35
- langchain-standard-tests = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/standard-tests" }
30
+ langchain-tests = "0.3.1"
36
31
 
37
32
  [tool.codespell]
38
33
  ignore-words-list = "rouge"
39
34
 
40
35
 
41
-
42
-
43
36
  [tool.poetry.group.codespell]
44
37
  optional = true
45
38
 
@@ -47,15 +40,11 @@ optional = true
47
40
  codespell = "^2.2.0"
48
41
 
49
42
 
50
-
51
-
52
43
  [tool.poetry.group.test_integration]
53
44
  optional = true
54
45
 
55
46
  [tool.poetry.group.test_integration.dependencies]
56
- pillow = "^10.1.0"
57
-
58
-
47
+ pytest = "^7.3.0"
59
48
 
60
49
 
61
50
  [tool.poetry.group.lint]
@@ -65,29 +54,20 @@ optional = true
65
54
  ruff = "^0.1.5"
66
55
 
67
56
 
68
-
69
-
70
57
  [tool.poetry.group.typing.dependencies]
71
58
  mypy = "^1.10"
72
59
  types-requests = "^2.28.11.5"
73
60
  types-google-cloud-ndb = "^2.2.0.1"
74
- types-pillow = "^10.1.0.2"
75
61
  types-protobuf = "^4.24.0.20240302"
76
- langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" }
77
62
  numpy = "^1.26.2"
78
63
 
79
64
 
80
-
81
-
82
65
  [tool.poetry.group.dev]
83
66
  optional = true
84
67
 
85
68
  [tool.poetry.group.dev.dependencies]
86
- pillow = "^10.1.0"
87
69
  types-requests = "^2.31.0.10"
88
- types-pillow = "^10.1.0.2"
89
70
  types-google-cloud-ndb = "^2.2.0.1"
90
- langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" }
91
71
 
92
72
  [tool.ruff.lint]
93
73
  select = [