langchain-google-genai 2.0.9__py3-none-any.whl → 2.0.10__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.

@@ -235,13 +235,16 @@ def _format_base_tool_to_function_declaration(
235
235
  ),
236
236
  )
237
237
 
238
- if issubclass(tool.args_schema, BaseModel):
238
+ if isinstance(tool.args_schema, dict):
239
+ schema = tool.args_schema
240
+ elif issubclass(tool.args_schema, BaseModel):
239
241
  schema = tool.args_schema.model_json_schema()
240
242
  elif issubclass(tool.args_schema, BaseModelV1):
241
243
  schema = tool.args_schema.schema()
242
244
  else:
243
245
  raise NotImplementedError(
244
- f"args_schema must be a Pydantic BaseModel, got {tool.args_schema}."
246
+ "args_schema must be a Pydantic BaseModel or JSON schema, "
247
+ f"got {tool.args_schema}."
245
248
  )
246
249
  parameters = _dict_to_gapic_schema(schema)
247
250
 
@@ -301,10 +304,18 @@ def _get_properties_from_schema(schema: Dict) -> Dict[str, Any]:
301
304
  continue
302
305
  properties_item: Dict[str, Union[str, int, Dict, List]] = {}
303
306
  if v.get("type") or v.get("anyOf") or v.get("type_"):
304
- properties_item["type_"] = _get_type_from_schema(v)
307
+ item_type_ = _get_type_from_schema(v)
308
+ properties_item["type_"] = item_type_
305
309
  if _is_nullable_schema(v):
306
310
  properties_item["nullable"] = True
307
311
 
312
+ # Replace `v` with chosen definition for array / object json types
313
+ any_of_types = v.get("anyOf")
314
+ if any_of_types and item_type_ in [glm.Type.ARRAY, glm.Type.OBJECT]:
315
+ json_type_ = "array" if item_type_ == glm.Type.ARRAY else "object"
316
+ # Use Index -1 for consistency with `_get_nullable_type_from_schema`
317
+ v = [val for val in any_of_types if val.get("type") == json_type_][-1]
318
+
308
319
  if v.get("enum"):
309
320
  properties_item["enum"] = v["enum"]
310
321
 
@@ -301,9 +301,12 @@ def _convert_to_parts(
301
301
  return parts
302
302
 
303
303
 
304
- def _convert_tool_message_to_part(message: ToolMessage | FunctionMessage) -> Part:
304
+ def _convert_tool_message_to_part(
305
+ message: ToolMessage | FunctionMessage, name: Optional[str] = None
306
+ ) -> Part:
305
307
  """Converts a tool or function message to a google part."""
306
- name = message.name
308
+ # Legacy agent stores tool name in message.additional_kwargs instead of message.name
309
+ name = message.name or name or message.additional_kwargs.get("name")
307
310
  response: Any
308
311
  if not isinstance(message.content, str):
309
312
  response = message.content
@@ -331,16 +334,17 @@ def _get_ai_message_tool_messages_parts(
331
334
  list of Parts.
332
335
  """
333
336
  # We are interested only in the tool messages that are part of the AI message
334
- tool_calls_ids = [tool_call["id"] for tool_call in ai_message.tool_calls]
337
+ tool_calls_ids = {tool_call["id"]: tool_call for tool_call in ai_message.tool_calls}
335
338
  parts = []
336
339
  for i, message in enumerate(tool_messages):
337
340
  if not tool_calls_ids:
338
341
  break
339
342
  if message.tool_call_id in tool_calls_ids:
340
- # remove the id from the list, so that we do not iterate over it again
341
- tool_calls_ids.remove(message.tool_call_id)
342
- part = _convert_tool_message_to_part(message)
343
+ tool_call = tool_calls_ids[message.tool_call_id]
344
+ part = _convert_tool_message_to_part(message, name=tool_call.get("name"))
343
345
  parts.append(part)
346
+ # remove the id from the dict, so that we do not iterate over it again
347
+ tool_calls_ids.pop(message.tool_call_id)
344
348
  return parts
345
349
 
346
350
 
@@ -360,8 +364,14 @@ def _parse_chat_history(
360
364
  message for message in input_messages if isinstance(message, ToolMessage)
361
365
  ]
362
366
  for i, message in enumerate(messages_without_tool_messages):
363
- if i == 0 and isinstance(message, SystemMessage):
364
- system_instruction = Content(parts=_convert_to_parts(message.content))
367
+ if isinstance(message, SystemMessage):
368
+ system_parts = _convert_to_parts(message.content)
369
+ if i == 0:
370
+ system_instruction = Content(parts=system_parts)
371
+ elif system_instruction is not None:
372
+ system_instruction.parts.extend(system_parts)
373
+ else:
374
+ pass
365
375
  continue
366
376
  elif isinstance(message, AIMessage):
367
377
  role = "model"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langchain-google-genai
3
- Version: 2.0.9
3
+ Version: 2.0.10
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
@@ -13,7 +13,7 @@ Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Requires-Dist: filetype (>=1.2.0,<2.0.0)
15
15
  Requires-Dist: google-generativeai (>=0.8.0,<0.9.0)
16
- Requires-Dist: langchain-core (>=0.3.27,<0.4.0)
16
+ Requires-Dist: langchain-core (>=0.3.37,<0.4.0)
17
17
  Requires-Dist: pydantic (>=2,<3)
18
18
  Project-URL: Repository, https://github.com/langchain-ai/langchain-google
19
19
  Project-URL: Source Code, https://github.com/langchain-ai/langchain-google/tree/main/libs/genai
@@ -1,16 +1,16 @@
1
1
  langchain_google_genai/__init__.py,sha256=Oji-S2KYWrku1wyQEskY84IOfY8MfRhujjJ4d7hbsk4,2758
2
2
  langchain_google_genai/_common.py,sha256=ASlwE8hEbvOm55BVF_D4rf2nl7RYsnpsi5xbM6DW3Cc,1576
3
3
  langchain_google_genai/_enums.py,sha256=KLPmxS1K83K4HjBIXFaXoL_sFEOv8Hq-2B2PDMKyDgo,197
4
- langchain_google_genai/_function_utils.py,sha256=xcUwX2DmGM4UwH7bhBC6W9E5oVAE8k_l9lMYzJUJwA0,17433
4
+ langchain_google_genai/_function_utils.py,sha256=c0bYzUcWyDnaYQi5tPtBxl7KGV4FswzSb3ywu8tD6yI,18036
5
5
  langchain_google_genai/_genai_extension.py,sha256=81a4ly5ZHlqMf37uJfdB8K41qE6J5ujLnbUypIfFf2o,20775
6
6
  langchain_google_genai/_image_utils.py,sha256=tPrQyMvVmO8xkuow1SvA91omxUEv9ZUy1EMHNGjMAKY,5202
7
- langchain_google_genai/chat_models.py,sha256=DpTIfMdO_HvuM7s6T3BMuVLfVH0n_ndAq-eiGHKncug,54547
7
+ langchain_google_genai/chat_models.py,sha256=F36_mMwLgnsQIEDJomKLuF4QdXdjkatXR5Ut-nMEvRA,55022
8
8
  langchain_google_genai/embeddings.py,sha256=jQRWPXD9twXoVBlXJQG7Duz0fb8UC0kgRzzwAmW3Dic,10146
9
9
  langchain_google_genai/genai_aqa.py,sha256=qB6h3-BSXqe0YLR3eeVllYzmNKK6ofI6xJLdBahUVZo,4300
10
10
  langchain_google_genai/google_vector_store.py,sha256=4wvhIiOmc3Fo046FyafPmT9NBCLek-9bgluvuTfrbpQ,16148
11
11
  langchain_google_genai/llms.py,sha256=EPUgkz5aqKOyKbztT7br8w60Uo5D_X_bF5qP-zd6iLs,14593
12
12
  langchain_google_genai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- langchain_google_genai-2.0.9.dist-info/LICENSE,sha256=DppmdYJVSc1jd0aio6ptnMUn5tIHrdAhQ12SclEBfBg,1072
14
- langchain_google_genai-2.0.9.dist-info/METADATA,sha256=lYcZ7V1qdeG84ekvofzoFACmjjMolZ-Hevgigsdw7dQ,3594
15
- langchain_google_genai-2.0.9.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
16
- langchain_google_genai-2.0.9.dist-info/RECORD,,
13
+ langchain_google_genai-2.0.10.dist-info/LICENSE,sha256=DppmdYJVSc1jd0aio6ptnMUn5tIHrdAhQ12SclEBfBg,1072
14
+ langchain_google_genai-2.0.10.dist-info/METADATA,sha256=2VjXxw5v4_8anWbUPouX2Y3yjG8JmBk9mKTJwIpvEkw,3595
15
+ langchain_google_genai-2.0.10.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
16
+ langchain_google_genai-2.0.10.dist-info/RECORD,,