langchain-google-genai 1.0.1__tar.gz → 1.0.2__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 (15) hide show
  1. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/PKG-INFO +3 -3
  2. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/langchain_google_genai/chat_models.py +19 -28
  3. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/langchain_google_genai/llms.py +6 -0
  4. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/pyproject.toml +6 -3
  5. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/LICENSE +0 -0
  6. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/README.md +0 -0
  7. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/langchain_google_genai/__init__.py +0 -0
  8. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/langchain_google_genai/_common.py +0 -0
  9. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/langchain_google_genai/_enums.py +0 -0
  10. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/langchain_google_genai/_function_utils.py +0 -0
  11. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/langchain_google_genai/_genai_extension.py +0 -0
  12. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/langchain_google_genai/embeddings.py +0 -0
  13. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/langchain_google_genai/genai_aqa.py +0 -0
  14. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/langchain_google_genai/google_vector_store.py +0 -0
  15. {langchain_google_genai-1.0.1 → langchain_google_genai-1.0.2}/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: 1.0.1
3
+ Version: 1.0.2
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
@@ -12,8 +12,8 @@ Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Provides-Extra: images
15
- Requires-Dist: google-generativeai (>=0.4.1,<0.5.0)
16
- Requires-Dist: langchain-core (>=0.1,<0.2)
15
+ Requires-Dist: google-generativeai (>=0.5.0,<0.6.0)
16
+ Requires-Dist: langchain-core (>=0.1.27,<0.2)
17
17
  Requires-Dist: pillow (>=10.1.0,<11.0.0) ; extra == "images"
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
@@ -4,6 +4,7 @@ import base64
4
4
  import json
5
5
  import logging
6
6
  import os
7
+ import warnings
7
8
  from io import BytesIO
8
9
  from typing import (
9
10
  Any,
@@ -300,27 +301,16 @@ def _convert_to_parts(
300
301
 
301
302
  def _parse_chat_history(
302
303
  input_messages: Sequence[BaseMessage], convert_system_message_to_human: bool = False
303
- ) -> List[genai.types.ContentDict]:
304
+ ) -> Tuple[Optional[genai.types.ContentDict], List[genai.types.ContentDict]]:
304
305
  messages: List[genai.types.MessageDict] = []
305
306
 
306
- raw_system_message: Optional[SystemMessage] = None
307
- for i, message in enumerate(input_messages):
308
- if (
309
- i == 0
310
- and isinstance(message, SystemMessage)
311
- and not convert_system_message_to_human
312
- ):
313
- raise ValueError(
314
- """SystemMessages are not yet supported!
315
-
316
- To automatically convert the leading SystemMessage to a HumanMessage,
317
- set `convert_system_message_to_human` to True. Example:
307
+ if convert_system_message_to_human:
308
+ warnings.warn("Convert_system_message_to_human will be deprecated!")
318
309
 
319
- llm = ChatGoogleGenerativeAI(model="gemini-pro", convert_system_message_to_human=True)
320
- """
321
- )
322
- elif i == 0 and isinstance(message, SystemMessage):
323
- raw_system_message = message
310
+ system_instruction: Optional[genai.types.ContentDict] = None
311
+ for i, message in enumerate(input_messages):
312
+ if i == 0 and isinstance(message, SystemMessage):
313
+ system_instruction = _convert_to_parts(message.content)
324
314
  continue
325
315
  elif isinstance(message, AIMessage):
326
316
  role = "model"
@@ -365,16 +355,8 @@ llm = ChatGoogleGenerativeAI(model="gemini-pro", convert_system_message_to_human
365
355
  f"Unexpected message with type {type(message)} at the position {i}."
366
356
  )
367
357
 
368
- if raw_system_message:
369
- if role == "model":
370
- raise ValueError(
371
- "SystemMessage should be followed by a HumanMessage and "
372
- "not by AIMessage."
373
- )
374
- parts = _convert_to_parts(raw_system_message.content) + parts
375
- raw_system_message = None
376
358
  messages.append({"role": role, "parts": parts})
377
- return messages
359
+ return system_instruction, messages
378
360
 
379
361
 
380
362
  def _parse_response_candidate(
@@ -483,11 +465,15 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
483
465
  @root_validator()
484
466
  def validate_environment(cls, values: Dict) -> Dict:
485
467
  """Validates params and passes them to google-generativeai package."""
468
+ additional_headers = values.get("additional_headers") or {}
469
+ default_metadata = tuple(additional_headers.items())
470
+
486
471
  if values.get("credentials"):
487
472
  genai.configure(
488
473
  credentials=values.get("credentials"),
489
474
  transport=values.get("transport"),
490
475
  client_options=values.get("client_options"),
476
+ default_metadata=default_metadata,
491
477
  )
492
478
  else:
493
479
  google_api_key = get_from_dict_or_env(
@@ -500,6 +486,7 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
500
486
  api_key=google_api_key,
501
487
  transport=values.get("transport"),
502
488
  client_options=values.get("client_options"),
489
+ default_metadata=default_metadata,
503
490
  )
504
491
  if (
505
492
  values.get("temperature") is not None
@@ -654,11 +641,15 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
654
641
  )
655
642
 
656
643
  params = self._prepare_params(stop, **kwargs)
657
- history = _parse_chat_history(
644
+ system_instruction, history = _parse_chat_history(
658
645
  messages,
659
646
  convert_system_message_to_human=self.convert_system_message_to_human,
660
647
  )
661
648
  message = history.pop()
649
+ if self.client._system_instruction != system_instruction:
650
+ self.client = genai.GenerativeModel(
651
+ model_name=self.model, system_instruction=system_instruction
652
+ )
662
653
  chat = client.start_chat(history=history)
663
654
  return params, chat, message
664
655
 
@@ -154,6 +154,12 @@ Supported examples:
154
154
  None,
155
155
  description="A string, one of: [`rest`, `grpc`, `grpc_asyncio`].",
156
156
  )
157
+ additional_headers: Optional[Dict[str, str]] = Field(
158
+ None,
159
+ description=(
160
+ "A key-value dictionary representing additional headers for the model call"
161
+ ),
162
+ )
157
163
 
158
164
  safety_settings: Optional[Dict[HarmCategory, HarmBlockThreshold]] = None
159
165
  """The default safety settings to use for all generations.
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "langchain-google-genai"
3
- version = "1.0.1"
3
+ version = "1.0.2"
4
4
  description = "An integration package connecting Google's genai package and LangChain"
5
5
  authors = []
6
6
  readme = "README.md"
@@ -12,8 +12,8 @@ license = "MIT"
12
12
 
13
13
  [tool.poetry.dependencies]
14
14
  python = ">=3.9,<4.0"
15
- langchain-core = "^0.1"
16
- google-generativeai = "^0.4.1"
15
+ langchain-core = ">=0.1.27,<0.2"
16
+ google-generativeai = "^0.5.0"
17
17
  pillow = { version = "^10.1.0", optional = true }
18
18
 
19
19
  [tool.poetry.extras]
@@ -30,6 +30,7 @@ syrupy = "^4.0.2"
30
30
  pytest-watcher = "^0.3.4"
31
31
  pytest-asyncio = "^0.21.1"
32
32
  numpy = "^1.26.2"
33
+ langchain-core = {git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core"}
33
34
 
34
35
  [tool.poetry.group.codespell]
35
36
  optional = true
@@ -56,6 +57,7 @@ types-requests = "^2.28.11.5"
56
57
  types-google-cloud-ndb = "^2.2.0.1"
57
58
  types-pillow = "^10.1.0.2"
58
59
  types-protobuf = "^4.24.0.20240302"
60
+ langchain-core = {git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core"}
59
61
 
60
62
  [tool.poetry.group.dev]
61
63
  optional = true
@@ -65,6 +67,7 @@ pillow = "^10.1.0"
65
67
  types-requests = "^2.31.0.10"
66
68
  types-pillow = "^10.1.0.2"
67
69
  types-google-cloud-ndb = "^2.2.0.1"
70
+ langchain-core = {git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core"}
68
71
 
69
72
  [tool.ruff]
70
73
  select = [