langchain-google-genai 1.0.9__tar.gz → 2.0.0.dev1__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.
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/PKG-INFO +3 -2
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/_function_utils.py +27 -4
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/chat_models.py +41 -36
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/embeddings.py +18 -16
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/genai_aqa.py +1 -1
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/google_vector_store.py +2 -2
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/llms.py +39 -27
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/pyproject.toml +8 -7
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/LICENSE +0 -0
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/README.md +0 -0
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/__init__.py +0 -0
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/_common.py +0 -0
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/_enums.py +0 -0
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/_genai_extension.py +0 -0
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/_image_utils.py +0 -0
- {langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/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:
|
|
3
|
+
Version: 2.0.0.dev1
|
|
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,8 +13,9 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
14
|
Provides-Extra: images
|
|
15
15
|
Requires-Dist: google-generativeai (>=0.7.0,<0.8.0)
|
|
16
|
-
Requires-Dist: langchain-core (>=0.
|
|
16
|
+
Requires-Dist: langchain-core (>=0.3.0.dev4,<0.4.0)
|
|
17
17
|
Requires-Dist: pillow (>=10.1.0,<11.0.0) ; extra == "images"
|
|
18
|
+
Requires-Dist: pydantic (>=2,<3)
|
|
18
19
|
Project-URL: Repository, https://github.com/langchain-ai/langchain-google
|
|
19
20
|
Project-URL: Source Code, https://github.com/langchain-ai/langchain-google/tree/main/libs/genai
|
|
20
21
|
Description-Content-Type: text/markdown
|
|
@@ -22,7 +22,6 @@ import google.ai.generativelanguage as glm
|
|
|
22
22
|
import google.ai.generativelanguage_v1beta.types as gapic
|
|
23
23
|
import proto # type: ignore[import]
|
|
24
24
|
from google.generativeai.types.content_types import ToolDict # type: ignore[import]
|
|
25
|
-
from langchain_core.pydantic_v1 import BaseModel
|
|
26
25
|
from langchain_core.tools import BaseTool
|
|
27
26
|
from langchain_core.tools import tool as callable_as_lc_tool
|
|
28
27
|
from langchain_core.utils.function_calling import (
|
|
@@ -30,6 +29,8 @@ from langchain_core.utils.function_calling import (
|
|
|
30
29
|
convert_to_openai_tool,
|
|
31
30
|
)
|
|
32
31
|
from langchain_core.utils.json_schema import dereference_refs
|
|
32
|
+
from pydantic import BaseModel
|
|
33
|
+
from pydantic.v1 import BaseModel as BaseModelV1
|
|
33
34
|
|
|
34
35
|
logger = logging.getLogger(__name__)
|
|
35
36
|
|
|
@@ -107,6 +108,13 @@ def _format_json_schema_to_gapic(schema: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
107
108
|
pvalue
|
|
108
109
|
)
|
|
109
110
|
continue
|
|
111
|
+
elif key == "allOf":
|
|
112
|
+
if len(value) > 1:
|
|
113
|
+
logger.warning(
|
|
114
|
+
"Only first value for 'allOf' key is supported. "
|
|
115
|
+
f"Got {len(value)}, ignoring other than first value!"
|
|
116
|
+
)
|
|
117
|
+
return _format_json_schema_to_gapic(value[0])
|
|
110
118
|
elif key in ["type", "_type"]:
|
|
111
119
|
converted_schema["type"] = str(value).upper()
|
|
112
120
|
elif key not in _ALLOWED_SCHEMA_FIELDS_SET:
|
|
@@ -198,7 +206,7 @@ def _format_to_gapic_function_declaration(
|
|
|
198
206
|
function = cast(dict, tool)
|
|
199
207
|
function["parameters"] = {}
|
|
200
208
|
else:
|
|
201
|
-
if "parameters" in tool and tool["parameters"].get("properties"):
|
|
209
|
+
if "parameters" in tool and tool["parameters"].get("properties"): # type: ignore[index]
|
|
202
210
|
function = convert_to_openai_tool(cast(dict, tool))["function"]
|
|
203
211
|
else:
|
|
204
212
|
function = cast(dict, tool)
|
|
@@ -225,7 +233,14 @@ def _format_base_tool_to_function_declaration(
|
|
|
225
233
|
),
|
|
226
234
|
)
|
|
227
235
|
|
|
228
|
-
|
|
236
|
+
if issubclass(tool.args_schema, BaseModel):
|
|
237
|
+
schema = tool.args_schema.model_json_schema()
|
|
238
|
+
elif issubclass(tool.args_schema, BaseModelV1):
|
|
239
|
+
schema = tool.args_schema.schema()
|
|
240
|
+
else:
|
|
241
|
+
raise NotImplementedError(
|
|
242
|
+
f"args_schema must be a Pydantic BaseModel, got {tool.args_schema}."
|
|
243
|
+
)
|
|
229
244
|
parameters = _dict_to_gapic_schema(schema)
|
|
230
245
|
|
|
231
246
|
return gapic.FunctionDeclaration(
|
|
@@ -240,7 +255,15 @@ def _convert_pydantic_to_genai_function(
|
|
|
240
255
|
tool_name: Optional[str] = None,
|
|
241
256
|
tool_description: Optional[str] = None,
|
|
242
257
|
) -> gapic.FunctionDeclaration:
|
|
243
|
-
|
|
258
|
+
if issubclass(pydantic_model, BaseModel):
|
|
259
|
+
schema = pydantic_model.model_json_schema()
|
|
260
|
+
elif issubclass(pydantic_model, BaseModelV1):
|
|
261
|
+
schema = pydantic_model.schema()
|
|
262
|
+
else:
|
|
263
|
+
raise NotImplementedError(
|
|
264
|
+
f"pydantic_model must be a Pydantic BaseModel, got {pydantic_model}"
|
|
265
|
+
)
|
|
266
|
+
schema = dereference_refs(schema)
|
|
244
267
|
schema.pop("definitions", None)
|
|
245
268
|
function_declaration = gapic.FunctionDeclaration(
|
|
246
269
|
name=tool_name if tool_name else schema.get("title"),
|
|
@@ -75,10 +75,16 @@ from langchain_core.output_parsers.openai_tools import (
|
|
|
75
75
|
parse_tool_calls,
|
|
76
76
|
)
|
|
77
77
|
from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult
|
|
78
|
-
from langchain_core.pydantic_v1 import BaseModel, Field, SecretStr, root_validator
|
|
79
78
|
from langchain_core.runnables import Runnable, RunnablePassthrough
|
|
80
|
-
from langchain_core.utils import
|
|
79
|
+
from langchain_core.utils import secret_from_env
|
|
81
80
|
from langchain_core.utils.pydantic import is_basemodel_subclass
|
|
81
|
+
from pydantic import (
|
|
82
|
+
BaseModel,
|
|
83
|
+
ConfigDict,
|
|
84
|
+
Field,
|
|
85
|
+
SecretStr,
|
|
86
|
+
model_validator,
|
|
87
|
+
)
|
|
82
88
|
from tenacity import (
|
|
83
89
|
before_sleep_log,
|
|
84
90
|
retry,
|
|
@@ -86,6 +92,7 @@ from tenacity import (
|
|
|
86
92
|
stop_after_attempt,
|
|
87
93
|
wait_exponential,
|
|
88
94
|
)
|
|
95
|
+
from typing_extensions import Self
|
|
89
96
|
|
|
90
97
|
from langchain_google_genai._common import (
|
|
91
98
|
GoogleGenerativeAIError,
|
|
@@ -817,9 +824,10 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
|
|
|
817
824
|
|
|
818
825
|
client: Any = Field(default=None, exclude=True) #: :meta private:
|
|
819
826
|
async_client: Any = Field(default=None, exclude=True) #: :meta private:
|
|
820
|
-
google_api_key: Optional[SecretStr] = Field(
|
|
821
|
-
|
|
822
|
-
|
|
827
|
+
google_api_key: Optional[SecretStr] = Field(
|
|
828
|
+
alias="api_key", default_factory=secret_from_env("GOOGLE_API_KEY", default=None)
|
|
829
|
+
)
|
|
830
|
+
"""Google AI API key.
|
|
823
831
|
If not specified will be read from env var ``GOOGLE_API_KEY``."""
|
|
824
832
|
default_metadata: Sequence[Tuple[str, str]] = Field(
|
|
825
833
|
default_factory=list
|
|
@@ -827,12 +835,13 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
|
|
|
827
835
|
|
|
828
836
|
convert_system_message_to_human: bool = False
|
|
829
837
|
"""Whether to merge any leading SystemMessage into the following HumanMessage.
|
|
830
|
-
|
|
831
|
-
Gemini does not support system messages; any unsupported messages will
|
|
838
|
+
|
|
839
|
+
Gemini does not support system messages; any unsupported messages will
|
|
832
840
|
raise an error."""
|
|
833
841
|
|
|
834
|
-
|
|
835
|
-
|
|
842
|
+
model_config = ConfigDict(
|
|
843
|
+
populate_by_name=True,
|
|
844
|
+
)
|
|
836
845
|
|
|
837
846
|
@property
|
|
838
847
|
def lc_secrets(self) -> Dict[str, str]:
|
|
@@ -846,40 +855,36 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
|
|
|
846
855
|
def is_lc_serializable(self) -> bool:
|
|
847
856
|
return True
|
|
848
857
|
|
|
849
|
-
@
|
|
850
|
-
def validate_environment(
|
|
858
|
+
@model_validator(mode="after")
|
|
859
|
+
def validate_environment(self) -> Self:
|
|
851
860
|
"""Validates params and passes them to google-generativeai package."""
|
|
852
|
-
if
|
|
853
|
-
values.get("temperature") is not None
|
|
854
|
-
and not 0 <= values["temperature"] <= 1
|
|
855
|
-
):
|
|
861
|
+
if self.temperature is not None and not 0 <= self.temperature <= 1:
|
|
856
862
|
raise ValueError("temperature must be in the range [0.0, 1.0]")
|
|
857
863
|
|
|
858
|
-
if
|
|
864
|
+
if self.top_p is not None and not 0 <= self.top_p <= 1:
|
|
859
865
|
raise ValueError("top_p must be in the range [0.0, 1.0]")
|
|
860
866
|
|
|
861
|
-
if
|
|
867
|
+
if self.top_k is not None and self.top_k <= 0:
|
|
862
868
|
raise ValueError("top_k must be positive")
|
|
863
869
|
|
|
864
|
-
if not
|
|
865
|
-
|
|
870
|
+
if not self.model.startswith("models/"):
|
|
871
|
+
self.model = f"models/{self.model}"
|
|
866
872
|
|
|
867
|
-
additional_headers =
|
|
868
|
-
|
|
873
|
+
additional_headers = self.additional_headers or {}
|
|
874
|
+
self.default_metadata = tuple(additional_headers.items())
|
|
869
875
|
client_info = get_client_info("ChatGoogleGenerativeAI")
|
|
870
876
|
google_api_key = None
|
|
871
|
-
if not
|
|
872
|
-
google_api_key
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
credentials=values.get("credentials"),
|
|
877
|
+
if not self.credentials:
|
|
878
|
+
if isinstance(self.google_api_key, SecretStr):
|
|
879
|
+
google_api_key = self.google_api_key.get_secret_value()
|
|
880
|
+
else:
|
|
881
|
+
google_api_key = self.google_api_key
|
|
882
|
+
transport: Optional[str] = self.transport
|
|
883
|
+
self.client = genaix.build_generative_service(
|
|
884
|
+
credentials=self.credentials,
|
|
880
885
|
api_key=google_api_key,
|
|
881
886
|
client_info=client_info,
|
|
882
|
-
client_options=
|
|
887
|
+
client_options=self.client_options,
|
|
883
888
|
transport=transport,
|
|
884
889
|
)
|
|
885
890
|
|
|
@@ -889,17 +894,17 @@ class ChatGoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseChatModel):
|
|
|
889
894
|
# this check ensures that async client is only initialized
|
|
890
895
|
# within an asyncio event loop to avoid the error
|
|
891
896
|
if _is_event_loop_running():
|
|
892
|
-
|
|
893
|
-
credentials=
|
|
897
|
+
self.async_client = genaix.build_generative_async_service(
|
|
898
|
+
credentials=self.credentials,
|
|
894
899
|
api_key=google_api_key,
|
|
895
900
|
client_info=client_info,
|
|
896
|
-
client_options=
|
|
901
|
+
client_options=self.client_options,
|
|
897
902
|
transport=transport,
|
|
898
903
|
)
|
|
899
904
|
else:
|
|
900
|
-
|
|
905
|
+
self.async_client = None
|
|
901
906
|
|
|
902
|
-
return
|
|
907
|
+
return self
|
|
903
908
|
|
|
904
909
|
@property
|
|
905
910
|
def _identifying_params(self) -> Dict[str, Any]:
|
|
@@ -8,8 +8,9 @@ from google.ai.generativelanguage_v1beta.types import (
|
|
|
8
8
|
EmbedContentRequest,
|
|
9
9
|
)
|
|
10
10
|
from langchain_core.embeddings import Embeddings
|
|
11
|
-
from langchain_core.
|
|
12
|
-
from
|
|
11
|
+
from langchain_core.utils import secret_from_env
|
|
12
|
+
from pydantic import BaseModel, Field, SecretStr, model_validator
|
|
13
|
+
from typing_extensions import Self
|
|
13
14
|
|
|
14
15
|
from langchain_google_genai._common import (
|
|
15
16
|
GoogleGenerativeAIError,
|
|
@@ -52,9 +53,11 @@ class GoogleGenerativeAIEmbeddings(BaseModel, Embeddings):
|
|
|
52
53
|
"semantic_similarity, classification, and clustering",
|
|
53
54
|
)
|
|
54
55
|
google_api_key: Optional[SecretStr] = Field(
|
|
55
|
-
default=None,
|
|
56
|
-
description=
|
|
57
|
-
|
|
56
|
+
default_factory=secret_from_env("GOOGLE_API_KEY", default=None),
|
|
57
|
+
description=(
|
|
58
|
+
"The Google API key to use. If not provided, "
|
|
59
|
+
"the GOOGLE_API_KEY environment variable will be used."
|
|
60
|
+
),
|
|
58
61
|
)
|
|
59
62
|
credentials: Any = Field(
|
|
60
63
|
default=None,
|
|
@@ -80,23 +83,22 @@ class GoogleGenerativeAIEmbeddings(BaseModel, Embeddings):
|
|
|
80
83
|
"Example: `{'timeout': 10}`",
|
|
81
84
|
)
|
|
82
85
|
|
|
83
|
-
@
|
|
84
|
-
def validate_environment(
|
|
86
|
+
@model_validator(mode="after")
|
|
87
|
+
def validate_environment(self) -> Self:
|
|
85
88
|
"""Validates params and passes them to google-generativeai package."""
|
|
86
|
-
google_api_key
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
google_api_key = google_api_key.get_secret_value()
|
|
89
|
+
if isinstance(self.google_api_key, SecretStr):
|
|
90
|
+
google_api_key: Optional[str] = self.google_api_key.get_secret_value()
|
|
91
|
+
else:
|
|
92
|
+
google_api_key = self.google_api_key
|
|
91
93
|
client_info = get_client_info("GoogleGenerativeAIEmbeddings")
|
|
92
94
|
|
|
93
|
-
|
|
94
|
-
credentials=
|
|
95
|
+
self.client = build_generative_service(
|
|
96
|
+
credentials=self.credentials,
|
|
95
97
|
api_key=google_api_key,
|
|
96
98
|
client_info=client_info,
|
|
97
|
-
client_options=
|
|
99
|
+
client_options=self.client_options,
|
|
98
100
|
)
|
|
99
|
-
return
|
|
101
|
+
return self
|
|
100
102
|
|
|
101
103
|
@staticmethod
|
|
102
104
|
def _split_by_punctuation(text: str) -> List[str]:
|
|
@@ -9,9 +9,9 @@ https://developers.generativeai.google/guide
|
|
|
9
9
|
from typing import Any, List, Optional
|
|
10
10
|
|
|
11
11
|
import google.ai.generativelanguage as genai
|
|
12
|
-
from langchain_core.pydantic_v1 import BaseModel, PrivateAttr
|
|
13
12
|
from langchain_core.runnables import RunnableSerializable
|
|
14
13
|
from langchain_core.runnables.config import RunnableConfig
|
|
14
|
+
from pydantic import BaseModel, PrivateAttr
|
|
15
15
|
|
|
16
16
|
from . import _genai_extension as genaix
|
|
17
17
|
|
|
@@ -21,9 +21,9 @@ from typing import (
|
|
|
21
21
|
import google.ai.generativelanguage as genai
|
|
22
22
|
from langchain_core.documents import Document
|
|
23
23
|
from langchain_core.embeddings import Embeddings
|
|
24
|
-
from langchain_core.pydantic_v1 import BaseModel, PrivateAttr
|
|
25
24
|
from langchain_core.runnables import Runnable, RunnableLambda, RunnablePassthrough
|
|
26
25
|
from langchain_core.vectorstores import VectorStore
|
|
26
|
+
from pydantic import BaseModel, PrivateAttr
|
|
27
27
|
|
|
28
28
|
from . import _genai_extension as genaix
|
|
29
29
|
from .genai_aqa import (
|
|
@@ -467,7 +467,7 @@ class GoogleVectorStore(VectorStore):
|
|
|
467
467
|
return (
|
|
468
468
|
RunnablePassthrough[str]()
|
|
469
469
|
| {
|
|
470
|
-
"prompt": RunnablePassthrough(),
|
|
470
|
+
"prompt": RunnablePassthrough(), # type: ignore[dict-item]
|
|
471
471
|
"passages": self.as_retriever(),
|
|
472
472
|
}
|
|
473
473
|
| RunnableLambda(_toAqaInput)
|
{langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/llms.py
RENAMED
|
@@ -9,11 +9,12 @@ from langchain_core.callbacks import (
|
|
|
9
9
|
AsyncCallbackManagerForLLMRun,
|
|
10
10
|
CallbackManagerForLLMRun,
|
|
11
11
|
)
|
|
12
|
-
from langchain_core.language_models import LanguageModelInput
|
|
12
|
+
from langchain_core.language_models import LangSmithParams, LanguageModelInput
|
|
13
13
|
from langchain_core.language_models.llms import BaseLLM, create_base_retry_decorator
|
|
14
14
|
from langchain_core.outputs import Generation, GenerationChunk, LLMResult
|
|
15
|
-
from langchain_core.
|
|
16
|
-
from
|
|
15
|
+
from langchain_core.utils import secret_from_env
|
|
16
|
+
from pydantic import BaseModel, Field, SecretStr, model_validator
|
|
17
|
+
from typing_extensions import Self
|
|
17
18
|
|
|
18
19
|
from langchain_google_genai._enums import (
|
|
19
20
|
HarmBlockThreshold,
|
|
@@ -122,7 +123,9 @@ Supported examples:
|
|
|
122
123
|
- models/text-bison-001""",
|
|
123
124
|
)
|
|
124
125
|
"""Model name to use."""
|
|
125
|
-
google_api_key: Optional[SecretStr] =
|
|
126
|
+
google_api_key: Optional[SecretStr] = Field(
|
|
127
|
+
alias="api_key", default_factory=secret_from_env("GOOGLE_API_KEY", default=None)
|
|
128
|
+
)
|
|
126
129
|
credentials: Any = None
|
|
127
130
|
"The default custom credentials (google.auth.credentials.Credentials) to use "
|
|
128
131
|
"when making API calls. If not provided, credentials will be ascertained from "
|
|
@@ -214,30 +217,29 @@ class GoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseLLM):
|
|
|
214
217
|
|
|
215
218
|
client: Any = None #: :meta private:
|
|
216
219
|
|
|
217
|
-
@
|
|
218
|
-
def validate_environment(
|
|
220
|
+
@model_validator(mode="after")
|
|
221
|
+
def validate_environment(self) -> Self:
|
|
219
222
|
"""Validates params and passes them to google-generativeai package."""
|
|
220
|
-
if
|
|
223
|
+
if self.credentials:
|
|
221
224
|
genai.configure(
|
|
222
|
-
credentials=
|
|
223
|
-
transport=
|
|
224
|
-
client_options=
|
|
225
|
+
credentials=self.credentials,
|
|
226
|
+
transport=self.transport,
|
|
227
|
+
client_options=self.client_options,
|
|
225
228
|
)
|
|
226
229
|
else:
|
|
227
|
-
google_api_key
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
google_api_key = google_api_key.get_secret_value()
|
|
230
|
+
if isinstance(self.google_api_key, SecretStr):
|
|
231
|
+
google_api_key: Optional[str] = self.google_api_key.get_secret_value()
|
|
232
|
+
else:
|
|
233
|
+
google_api_key = self.google_api_key
|
|
232
234
|
genai.configure(
|
|
233
235
|
api_key=google_api_key,
|
|
234
|
-
transport=
|
|
235
|
-
client_options=
|
|
236
|
+
transport=self.transport,
|
|
237
|
+
client_options=self.client_options,
|
|
236
238
|
)
|
|
237
239
|
|
|
238
|
-
model_name =
|
|
240
|
+
model_name = self.model
|
|
239
241
|
|
|
240
|
-
safety_settings =
|
|
242
|
+
safety_settings = self.safety_settings
|
|
241
243
|
|
|
242
244
|
if safety_settings and (
|
|
243
245
|
not GoogleModelFamily(model_name) == GoogleModelFamily.GEMINI
|
|
@@ -245,28 +247,38 @@ class GoogleGenerativeAI(_BaseGoogleGenerativeAI, BaseLLM):
|
|
|
245
247
|
raise ValueError("Safety settings are only supported for Gemini models")
|
|
246
248
|
|
|
247
249
|
if GoogleModelFamily(model_name) == GoogleModelFamily.GEMINI:
|
|
248
|
-
|
|
250
|
+
self.client = genai.GenerativeModel(
|
|
249
251
|
model_name=model_name, safety_settings=safety_settings
|
|
250
252
|
)
|
|
251
253
|
else:
|
|
252
|
-
|
|
254
|
+
self.client = genai
|
|
253
255
|
|
|
254
|
-
if
|
|
256
|
+
if self.temperature is not None and not 0 <= self.temperature <= 1:
|
|
255
257
|
raise ValueError("temperature must be in the range [0.0, 1.0]")
|
|
256
258
|
|
|
257
|
-
if
|
|
259
|
+
if self.top_p is not None and not 0 <= self.top_p <= 1:
|
|
258
260
|
raise ValueError("top_p must be in the range [0.0, 1.0]")
|
|
259
261
|
|
|
260
|
-
if
|
|
262
|
+
if self.top_k is not None and self.top_k <= 0:
|
|
261
263
|
raise ValueError("top_k must be positive")
|
|
262
264
|
|
|
263
|
-
if
|
|
265
|
+
if self.max_output_tokens is not None and self.max_output_tokens <= 0:
|
|
264
266
|
raise ValueError("max_output_tokens must be greater than zero")
|
|
265
267
|
|
|
266
|
-
if
|
|
268
|
+
if self.timeout is not None and self.timeout <= 0:
|
|
267
269
|
raise ValueError("timeout must be greater than zero")
|
|
268
270
|
|
|
269
|
-
return
|
|
271
|
+
return self
|
|
272
|
+
|
|
273
|
+
def _get_ls_params(
|
|
274
|
+
self, stop: Optional[List[str]] = None, **kwargs: Any
|
|
275
|
+
) -> LangSmithParams:
|
|
276
|
+
"""Get standard params for tracing."""
|
|
277
|
+
ls_params = super()._get_ls_params(stop=stop, **kwargs)
|
|
278
|
+
ls_params["ls_provider"] = "google_genai"
|
|
279
|
+
if ls_max_tokens := kwargs.get("max_output_tokens", self.max_output_tokens):
|
|
280
|
+
ls_params["ls_max_tokens"] = ls_max_tokens
|
|
281
|
+
return ls_params
|
|
270
282
|
|
|
271
283
|
def _generate(
|
|
272
284
|
self,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "langchain-google-genai"
|
|
3
|
-
version = "
|
|
3
|
+
version = "2.0.0.dev1"
|
|
4
4
|
description = "An integration package connecting Google's genai package and LangChain"
|
|
5
5
|
authors = []
|
|
6
6
|
readme = "README.md"
|
|
@@ -12,9 +12,10 @@ license = "MIT"
|
|
|
12
12
|
|
|
13
13
|
[tool.poetry.dependencies]
|
|
14
14
|
python = ">=3.9,<4.0"
|
|
15
|
-
langchain-core = "
|
|
15
|
+
langchain-core = { version = "^0.3.0.dev4", allow-prereleases = true }
|
|
16
16
|
google-generativeai = "^0.7.0"
|
|
17
17
|
pillow = { version = "^10.1.0", optional = true }
|
|
18
|
+
pydantic = ">=2,<3"
|
|
18
19
|
|
|
19
20
|
[tool.poetry.extras]
|
|
20
21
|
images = ["pillow"]
|
|
@@ -30,8 +31,8 @@ syrupy = "^4.0.2"
|
|
|
30
31
|
pytest-watcher = "^0.3.4"
|
|
31
32
|
pytest-asyncio = "^0.21.1"
|
|
32
33
|
numpy = "^1.26.2"
|
|
33
|
-
langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" }
|
|
34
|
-
langchain-standard-tests = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/standard-tests" }
|
|
34
|
+
langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core", branch = "v0.3rc" }
|
|
35
|
+
langchain-standard-tests = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/standard-tests", branch = "v0.3rc" }
|
|
35
36
|
|
|
36
37
|
[tool.codespell]
|
|
37
38
|
ignore-words-list = "rouge"
|
|
@@ -56,12 +57,12 @@ optional = true
|
|
|
56
57
|
ruff = "^0.1.5"
|
|
57
58
|
|
|
58
59
|
[tool.poetry.group.typing.dependencies]
|
|
59
|
-
mypy = "^
|
|
60
|
+
mypy = "^1.10"
|
|
60
61
|
types-requests = "^2.28.11.5"
|
|
61
62
|
types-google-cloud-ndb = "^2.2.0.1"
|
|
62
63
|
types-pillow = "^10.1.0.2"
|
|
63
64
|
types-protobuf = "^4.24.0.20240302"
|
|
64
|
-
langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" }
|
|
65
|
+
langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core", branch = "v0.3rc" }
|
|
65
66
|
numpy = "^1.26.2"
|
|
66
67
|
|
|
67
68
|
[tool.poetry.group.dev]
|
|
@@ -72,7 +73,7 @@ pillow = "^10.1.0"
|
|
|
72
73
|
types-requests = "^2.31.0.10"
|
|
73
74
|
types-pillow = "^10.1.0.2"
|
|
74
75
|
types-google-cloud-ndb = "^2.2.0.1"
|
|
75
|
-
langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" }
|
|
76
|
+
langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core", branch = "v0.3rc" }
|
|
76
77
|
|
|
77
78
|
[tool.ruff.lint]
|
|
78
79
|
select = [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/_common.py
RENAMED
|
File without changes
|
{langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/_enums.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{langchain_google_genai-1.0.9 → langchain_google_genai-2.0.0.dev1}/langchain_google_genai/py.typed
RENAMED
|
File without changes
|