From 5779ee2cbfbc7ab680d12c35f9e6ab56238e1153 Mon Sep 17 00:00:00 2001 From: jinno Date: Wed, 24 Jul 2024 20:37:05 +0900 Subject: [PATCH] genai: update pyproject.toml same as vertexai --- .../langchain_google_genai/_function_utils.py | 14 ++--- .../_genai_extension.py | 2 +- .../langchain_google_genai/_image_utils.py | 2 +- .../langchain_google_genai/chat_models.py | 20 +++---- libs/genai/langchain_google_genai/llms.py | 13 ++--- libs/genai/poetry.lock | 53 ++++++++++++++++--- libs/genai/pyproject.toml | 24 +++++++-- .../integration_tests/test_chat_models.py | 7 +-- .../tests/integration_tests/test_llms.py | 2 +- .../tests/unit_tests/test_chat_models.py | 18 +++---- .../tests/unit_tests/test_function_utils.py | 4 +- libs/genai/tests/unit_tests/test_genai_aqa.py | 15 +++--- libs/genai/tests/unit_tests/test_llms.py | 6 ++- 13 files changed, 117 insertions(+), 63 deletions(-) diff --git a/libs/genai/langchain_google_genai/_function_utils.py b/libs/genai/langchain_google_genai/_function_utils.py index e187577f0..2be3cd2ae 100644 --- a/libs/genai/langchain_google_genai/_function_utils.py +++ b/libs/genai/langchain_google_genai/_function_utils.py @@ -21,8 +21,10 @@ import google.ai.generativelanguage as glm import google.ai.generativelanguage_v1beta.types as gapic -import proto # type: ignore[import] -from google.generativeai.types.content_types import ToolDict # type: ignore[import] +import proto # type: ignore[import-untyped] +from google.generativeai.types.content_types import ( # type: ignore[import-untyped] + ToolDict, +) from langchain_core.tools import BaseTool from langchain_core.tools import tool as callable_as_lc_tool from langchain_core.utils.function_calling import ( @@ -144,7 +146,7 @@ def convert_to_genai_function_declarations( tools: Sequence[_ToolsType], ) -> gapic.Tool: if not isinstance(tools, collections.abc.Sequence): - logger.warning( + logger.warning( # type: ignore[unreachable] "convert_to_genai_function_declarations expects a Sequence " "and not a single tool." ) @@ -237,7 +239,7 @@ def _format_base_tool_to_function_declaration( if issubclass(tool.args_schema, BaseModel): schema = tool.args_schema.model_json_schema() - elif issubclass(tool.args_schema, BaseModelV1): + elif issubclass(tool.args_schema, BaseModelV1): # type: ignore[unreachable] schema = tool.args_schema.schema() else: raise NotImplementedError( @@ -259,7 +261,7 @@ def _convert_pydantic_to_genai_function( ) -> gapic.FunctionDeclaration: if issubclass(pydantic_model, BaseModel): schema = pydantic_model.model_json_schema() - elif issubclass(pydantic_model, BaseModelV1): + elif issubclass(pydantic_model, BaseModelV1): # type: ignore[unreachable] schema = pydantic_model.schema() else: raise NotImplementedError( @@ -460,7 +462,7 @@ def _tool_choice_to_tool_config( def is_basemodel_subclass_safe(tool: Type) -> bool: if safe_import("langchain_core.utils.pydantic", "is_basemodel_subclass"): from langchain_core.utils.pydantic import ( - is_basemodel_subclass, # type: ignore[import] + is_basemodel_subclass, ) return is_basemodel_subclass(tool) diff --git a/libs/genai/langchain_google_genai/_genai_extension.py b/libs/genai/langchain_google_genai/_genai_extension.py index f7b39163b..4d0e0044c 100644 --- a/libs/genai/langchain_google_genai/_genai_extension.py +++ b/libs/genai/langchain_google_genai/_genai_extension.py @@ -21,7 +21,7 @@ from google.api_core import client_options as client_options_lib from google.api_core import exceptions as gapi_exception from google.api_core import gapic_v1 -from google.auth import credentials, exceptions # type: ignore +from google.auth import credentials, exceptions from google.protobuf import timestamp_pb2 _logger = logging.getLogger(__name__) diff --git a/libs/genai/langchain_google_genai/_image_utils.py b/libs/genai/langchain_google_genai/_image_utils.py index a0baba496..d30989ae7 100644 --- a/libs/genai/langchain_google_genai/_image_utils.py +++ b/libs/genai/langchain_google_genai/_image_utils.py @@ -54,7 +54,7 @@ def load_bytes(self, image_string: str) -> bytes: "Please pass in images as Google Cloud Storage URI, " "b64 encoded image string (data:image/...), or valid image url." ) - return self._bytes_from_file(image_string) + return self._bytes_from_file(image_string) # type: ignore[unreachable] raise ValueError( "Image string must be one of: Google Cloud Storage URI, " diff --git a/libs/genai/langchain_google_genai/chat_models.py b/libs/genai/langchain_google_genai/chat_models.py index 91a1cfa81..1c79313e2 100644 --- a/libs/genai/langchain_google_genai/chat_models.py +++ b/libs/genai/langchain_google_genai/chat_models.py @@ -25,7 +25,7 @@ import google.api_core # TODO: remove ignore once the google package is published with types -import proto # type: ignore[import] +import proto # type: ignore[import-untyped] from google.ai.generativelanguage_v1beta import ( GenerativeServiceAsyncClient as v1betaGenerativeServiceAsyncClient, ) @@ -44,10 +44,10 @@ ToolConfig, VideoMetadata, ) -from google.generativeai.caching import CachedContent # type: ignore[import] -from google.generativeai.types import Tool as GoogleTool # type: ignore[import] +from google.generativeai.caching import CachedContent # type: ignore[import-untyped] +from google.generativeai.types import Tool as GoogleTool # type: ignore[import-untyped] from google.generativeai.types import caching_types, content_types -from google.generativeai.types.content_types import ( # type: ignore[import] +from google.generativeai.types.content_types import ( # type: ignore[import-untyped] FunctionDeclarationType, ToolDict, ) @@ -212,7 +212,7 @@ async def _achat_with_retry(generation_method: Callable, **kwargs: Any) -> Any: Any: The result from the chat generation method. """ retry_decorator = _create_retry_decorator() - from google.api_core.exceptions import InvalidArgument # type: ignore + from google.api_core.exceptions import InvalidArgument @retry_decorator async def _achat_with_retry(**kwargs: Any) -> Any: @@ -787,10 +787,10 @@ class Joke(BaseModel): raise an error.""" cached_content: Optional[str] = None - """The name of the cached content used as context to serve the prediction. + """The name of the cached content used as context to serve the prediction. - Note: only used in explicit caching, where users can have control over caching - (e.g. what content to cache) and enjoy guaranteed cost savings. Format: + Note: only used in explicit caching, where users can have control over caching + (e.g. what content to cache) and enjoy guaranteed cost savings. Format: ``cachedContents/{cachedContent}``. """ @@ -1275,7 +1275,7 @@ def bind_tools( f"both:\n\n{tool_choice=}\n\n{tool_config=}" ) try: - formatted_tools: list = [convert_to_openai_tool(tool) for tool in tools] # type: ignore[arg-type] + formatted_tools: list = [convert_to_openai_tool(tool) for tool in tools] except Exception: formatted_tools = [ tool_to_dict(convert_to_genai_function_declarations(tools)) @@ -1381,4 +1381,4 @@ def _get_tool_name( tool: Union[ToolDict, GoogleTool], ) -> str: genai_tool = tool_to_dict(convert_to_genai_function_declarations([tool])) - return [f["name"] for f in genai_tool["function_declarations"]][0] # type: ignore[index] + return [f["name"] for f in genai_tool["function_declarations"]][0] diff --git a/libs/genai/langchain_google_genai/llms.py b/libs/genai/langchain_google_genai/llms.py index 0da089ce3..da73335a8 100644 --- a/libs/genai/langchain_google_genai/llms.py +++ b/libs/genai/langchain_google_genai/llms.py @@ -4,7 +4,7 @@ from typing import Any, Callable, Dict, Iterator, List, Optional, Union import google.api_core -import google.generativeai as genai # type: ignore[import] +import google.generativeai as genai # type: ignore[import-untyped] from langchain_core.callbacks import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, @@ -16,10 +16,7 @@ from pydantic import BaseModel, ConfigDict, Field, SecretStr, model_validator from typing_extensions import Self -from langchain_google_genai._enums import ( - HarmBlockThreshold, - HarmCategory, -) +from langchain_google_genai._enums import HarmBlockThreshold, HarmCategory class GoogleModelFamily(str, Enum): @@ -170,9 +167,9 @@ class _BaseGoogleGenerativeAI(BaseModel): ) safety_settings: Optional[Dict[HarmCategory, HarmBlockThreshold]] = None - """The default safety settings to use for all generations. - - For example: + """The default safety settings to use for all generations. + + For example: from google.generativeai.types.safety_types import HarmBlockThreshold, HarmCategory diff --git a/libs/genai/poetry.lock b/libs/genai/poetry.lock index 4f0f797fe..f63e32713 100644 --- a/libs/genai/poetry.lock +++ b/libs/genai/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "annotated-types" @@ -265,8 +265,8 @@ grpcio-status = [ {version = ">=1.33.2,<2.0.dev0", optional = true, markers = "python_version < \"3.11\" and extra == \"grpc\""}, ] proto-plus = [ - {version = ">=1.25.0,<2.0.0dev", markers = "python_version >= \"3.13\""}, {version = ">=1.22.3,<2.0.0dev", markers = "python_version < \"3.13\""}, + {version = ">=1.25.0,<2.0.0dev", markers = "python_version >= \"3.13\""}, ] protobuf = ">=3.19.5,<3.20.0 || >3.20.0,<3.20.1 || >3.20.1,<4.21.0 || >4.21.0,<4.21.1 || >4.21.1,<4.21.2 || >4.21.2,<4.21.3 || >4.21.3,<4.21.4 || >4.21.4,<4.21.5 || >4.21.5,<6.0.0.dev0" requests = ">=2.18.0,<3.0.0.dev0" @@ -591,8 +591,8 @@ jsonpatch = "^1.33" langsmith = "^0.1.125" packaging = ">=23.2,<25" pydantic = [ - {version = ">=2.7.4,<3.0.0", markers = "python_full_version >= \"3.12.4\""}, {version = ">=2.5.2,<3.0.0", markers = "python_full_version < \"3.12.4\""}, + {version = ">=2.7.4,<3.0.0", markers = "python_full_version >= \"3.12.4\""}, ] PyYAML = ">=5.3" tenacity = ">=8.1.0,!=8.4.0,<10.0.0" @@ -637,8 +637,8 @@ files = [ httpx = ">=0.23.0,<1" orjson = ">=3.9.14,<4.0.0" pydantic = [ - {version = ">=2.7.4,<3.0.0", markers = "python_full_version >= \"3.12.4\""}, {version = ">=1,<3", markers = "python_full_version < \"3.12.4\""}, + {version = ">=2.7.4,<3.0.0", markers = "python_full_version >= \"3.12.4\""}, ] requests = ">=2,<3" requests-toolbelt = ">=1.0.0,<2.0.0" @@ -707,6 +707,47 @@ files = [ {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, ] +[[package]] +name = "numexpr" +version = "2.10.1" +description = "Fast numerical expression evaluator for NumPy" +optional = false +python-versions = ">=3.9" +files = [ + {file = "numexpr-2.10.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:bbd35f17f6efc00ebd4a480192af1ee30996094a0d5343b131b0e90e61e8b554"}, + {file = "numexpr-2.10.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:fecdf4bf3c1250e56583db0a4a80382a259ba4c2e1efa13e04ed43f0938071f5"}, + {file = "numexpr-2.10.1-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b2efa499f460124538a5b4f1bf2e77b28eb443ee244cc5573ed0f6a069ebc635"}, + {file = "numexpr-2.10.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ac23a72eff10f928f23b147bdeb0f1b774e862abe332fc9bf4837e9f1bc0bbf9"}, + {file = "numexpr-2.10.1-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:b28eaf45f1cc1048aad9e90e3a8ada1aef58c5f8155a85267dc781b37998c046"}, + {file = "numexpr-2.10.1-cp310-cp310-win32.whl", hash = "sha256:4f0985bd1c493b23b5aad7d81fa174798f3812efb78d14844194834c9fee38b8"}, + {file = "numexpr-2.10.1-cp310-cp310-win_amd64.whl", hash = "sha256:44f6d12a8c44be90199bbb10d3abf467f88951f48a3d1fbbd3c219d121f39c9d"}, + {file = "numexpr-2.10.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:a3c0b0bf165b2d886eb981afa4e77873ca076f5d51c491c4d7b8fc10f17c876f"}, + {file = "numexpr-2.10.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:56648a04679063175681195670ad53e5c8ca19668166ed13875199b5600089c7"}, + {file = "numexpr-2.10.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ce04ae6efe2a9d0be1a0e114115c3ae70c68b8b8fbc615c5c55c15704b01e6a4"}, + {file = "numexpr-2.10.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:45f598182b4f5c153222e47d5163c3bee8d5ebcaee7e56dd2a5898d4d97e4473"}, + {file = "numexpr-2.10.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:6a50370bea77ba94c3734a44781c716751354c6bfda2d369af3aed3d67d42871"}, + {file = "numexpr-2.10.1-cp311-cp311-win32.whl", hash = "sha256:fa4009d84a8e6e21790e718a80a22d57fe7f215283576ef2adc4183f7247f3c7"}, + {file = "numexpr-2.10.1-cp311-cp311-win_amd64.whl", hash = "sha256:fcbf013bb8494e8ef1d11fa3457827c1571c6a3153982d709e5d17594999d4dd"}, + {file = "numexpr-2.10.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:82fc95c301b15ff4823f98989ee363a2d5555d16a7cfd3710e98ddee726eaaaa"}, + {file = "numexpr-2.10.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:cbf79fef834f88607f977ab9867061dcd9b40ccb08bb28547c6dc6c73e560895"}, + {file = "numexpr-2.10.1-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:552c8d4b2e3b87cdb2abb40a781b9a61a9090a9f66ac7357fc5a0b93aff76be3"}, + {file = "numexpr-2.10.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:22cc65e9121aeb3187a2b50827715b2b087ea70e8ab21416ea52662322087b43"}, + {file = "numexpr-2.10.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:00204e5853713b5eba5f3d0bc586a5d8d07f76011b597c8b4087592cc2ec2928"}, + {file = "numexpr-2.10.1-cp312-cp312-win32.whl", hash = "sha256:82bf04a1495ac475de4ab49fbe0a3a2710ed3fd1a00bc03847316b5d7602402d"}, + {file = "numexpr-2.10.1-cp312-cp312-win_amd64.whl", hash = "sha256:300e577b3c006dd7a8270f1bb2e8a00ee15bf235b1650fe2a6febec2954bc2c3"}, + {file = "numexpr-2.10.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:fb704620657a1c99d64933e8a982148d8bfb2b738a1943e107a2bfdee887ce56"}, + {file = "numexpr-2.10.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:368a1972c3186355160f6ee330a7eea146d8443da75a38a30083289ae251ef5a"}, + {file = "numexpr-2.10.1-cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ca8ae46481d0b0689ca0d00a8670bc464ce375e349599fe674a6d4957e7b7eb6"}, + {file = "numexpr-2.10.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5a4db4456e0779d5e024220b7b6a7477ac900679bfa74836b06fa526aaed4e3c"}, + {file = "numexpr-2.10.1-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:926dd426c68f1d927412a2ad843831c1eb9a95871e7bb0bd8b20d547c12238d2"}, + {file = "numexpr-2.10.1-cp39-cp39-win32.whl", hash = "sha256:37598cca41f8f50dc889b0b72be1616a288758c16ab7d48c9ac8719e1a39d835"}, + {file = "numexpr-2.10.1-cp39-cp39-win_amd64.whl", hash = "sha256:78b14c19c403df7498954468385768c86b0d2c52ad03dffb74e45d44ae5a9c77"}, + {file = "numexpr-2.10.1.tar.gz", hash = "sha256:9bba99d354a65f1a008ab8b87f07d84404c668e66bab624df5b6b5373403cf81"}, +] + +[package.dependencies] +numpy = ">=1.23.0" + [[package]] name = "numpy" version = "1.26.4" @@ -922,8 +963,8 @@ files = [ annotated-types = ">=0.6.0" pydantic-core = "2.23.4" typing-extensions = [ - {version = ">=4.12.2", markers = "python_version >= \"3.13\""}, {version = ">=4.6.1", markers = "python_version < \"3.13\""}, + {version = ">=4.12.2", markers = "python_version >= \"3.13\""}, ] [package.extras] @@ -1470,4 +1511,4 @@ watchmedo = ["PyYAML (>=3.10)"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<4.0" -content-hash = "988b5a557506419d3750476d499929c8e3d3f7a0f37f4ca8c5ec5064227f2671" +content-hash = "23623d4763ae33f4d578dec6e84827f747b38cdec0f264bcd051545f80443ee8" diff --git a/libs/genai/pyproject.toml b/libs/genai/pyproject.toml index 3f3e41053..5f947089b 100644 --- a/libs/genai/pyproject.toml +++ b/libs/genai/pyproject.toml @@ -15,6 +15,7 @@ python = ">=3.9,<4.0" langchain-core = ">=0.3.15,<0.4" google-generativeai = "^0.8.0" pydantic = ">=2,<3" +grpcio = "^1.66.2" [tool.poetry.group.test] optional = true @@ -26,8 +27,15 @@ pytest-mock = "^3.10.0" syrupy = "^4.0.2" pytest-watcher = "^0.3.4" pytest-asyncio = "^0.21.1" -numpy = "^1.26.2" +types-requests = "^2.31.0.20231231" +types-protobuf = "^4.24.0.4" +numexpr = "^2.8.6" +numpy = [ + { version = "^1", python = "<3.12" }, + { version = "^1.26.2", python = ">=3.12" }, +] langchain-tests = "0.3.1" +google-generativeai = "^0.8.0" [tool.codespell] ignore-words-list = "rouge" @@ -59,7 +67,6 @@ mypy = "^1.10" types-requests = "^2.28.11.5" types-google-cloud-ndb = "^2.2.0.1" types-protobuf = "^4.24.0.20240302" -numpy = "^1.26.2" [tool.poetry.group.dev] @@ -68,6 +75,7 @@ optional = true [tool.poetry.group.dev.dependencies] types-requests = "^2.31.0.10" types-google-cloud-ndb = "^2.2.0.1" +langchain-core = { git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core" } [tool.ruff.lint] select = [ @@ -77,7 +85,17 @@ select = [ ] [tool.mypy] -disallow_untyped_defs = "True" +disallow_untyped_defs = true +check_untyped_defs = true +error_summary = false +pretty = true +show_column_numbers = true +show_error_codes = true +show_error_context = true +warn_redundant_casts = true +warn_unreachable = true +warn_unused_configs = true +warn_unused_ignores = true [tool.coverage.run] omit = ["tests/*"] diff --git a/libs/genai/tests/integration_tests/test_chat_models.py b/libs/genai/tests/integration_tests/test_chat_models.py index 225ffa79b..ceb02d87d 100644 --- a/libs/genai/tests/integration_tests/test_chat_models.py +++ b/libs/genai/tests/integration_tests/test_chat_models.py @@ -17,11 +17,8 @@ from langchain_core.tools import tool from pydantic import BaseModel -from langchain_google_genai import ( - ChatGoogleGenerativeAI, - HarmBlockThreshold, - HarmCategory, -) +from langchain_google_genai import ChatGoogleGenerativeAI +from langchain_google_genai._enums import HarmBlockThreshold, HarmCategory from langchain_google_genai.chat_models import ChatGoogleGenerativeAIError _MODEL = "models/gemini-1.0-pro-001" # TODO: Use nano when it's available. diff --git a/libs/genai/tests/integration_tests/test_llms.py b/libs/genai/tests/integration_tests/test_llms.py index 53b9ddb52..e7c72c53e 100644 --- a/libs/genai/tests/integration_tests/test_llms.py +++ b/libs/genai/tests/integration_tests/test_llms.py @@ -23,7 +23,7 @@ def test_google_generativeai_call(model_name: str) -> None: if model_name: llm = GoogleGenerativeAI(max_tokens=10, model=model_name) else: - llm = GoogleGenerativeAI(max_tokens=10) # type: ignore[call-arg] + llm = GoogleGenerativeAI(max_tokens=10, model=model_names[0]) output = llm("Say foo:") assert isinstance(output, str) assert llm._llm_type == "google_palm" diff --git a/libs/genai/tests/unit_tests/test_chat_models.py b/libs/genai/tests/unit_tests/test_chat_models.py index 7be08fa36..5898823e4 100644 --- a/libs/genai/tests/unit_tests/test_chat_models.py +++ b/libs/genai/tests/unit_tests/test_chat_models.py @@ -37,7 +37,7 @@ def test_integration_initialization() -> None: """Test chat model initialization.""" llm = ChatGoogleGenerativeAI( model="gemini-nano", - google_api_key=SecretStr("..."), # type: ignore[call-arg] + google_api_key="...", top_k=2, top_p=1, temperature=0.7, @@ -53,7 +53,7 @@ def test_integration_initialization() -> None: llm = ChatGoogleGenerativeAI( model="gemini-nano", - google_api_key=SecretStr("..."), # type: ignore[call-arg] + google_api_key=SecretStr("..."), max_output_tokens=10, ) ls_params = llm._get_ls_params() @@ -81,14 +81,14 @@ def test_initialization_inside_threadpool() -> None: executor.submit( ChatGoogleGenerativeAI, model="gemini-nano", - google_api_key=SecretStr("secret-api-key"), # type: ignore[call-arg] + google_api_key=SecretStr("secret-api-key"), ).result() def test_initalization_without_async() -> None: chat = ChatGoogleGenerativeAI( model="gemini-nano", - google_api_key=SecretStr("secret-api-key"), # type: ignore[call-arg] + google_api_key=SecretStr("secret-api-key"), ) assert chat.async_client is None @@ -97,7 +97,7 @@ def test_initialization_with_async() -> None: async def initialize_chat_with_async_client() -> ChatGoogleGenerativeAI: model = ChatGoogleGenerativeAI( model="gemini-nano", - google_api_key=SecretStr("secret-api-key"), # type: ignore[call-arg] + google_api_key=SecretStr("secret-api-key"), ) _ = model.async_client return model @@ -110,7 +110,7 @@ async def initialize_chat_with_async_client() -> ChatGoogleGenerativeAI: def test_api_key_is_string() -> None: chat = ChatGoogleGenerativeAI( model="gemini-nano", - google_api_key=SecretStr("secret-api-key"), # type: ignore[call-arg] + google_api_key=SecretStr("secret-api-key"), ) assert isinstance(chat.google_api_key, SecretStr) @@ -118,7 +118,7 @@ def test_api_key_is_string() -> None: def test_api_key_masked_when_passed_via_constructor(capsys: CaptureFixture) -> None: chat = ChatGoogleGenerativeAI( model="gemini-nano", - google_api_key=SecretStr("secret-api-key"), # type: ignore[call-arg] + google_api_key=SecretStr("secret-api-key"), ) print(chat.google_api_key, end="") # noqa: T201 captured = capsys.readouterr() @@ -271,7 +271,7 @@ def test_additional_headers_support(headers: Optional[Dict[str, str]]) -> None: ): chat = ChatGoogleGenerativeAI( model="gemini-pro", - google_api_key=param_secret_api_key, # type: ignore[call-arg] + google_api_key=param_secret_api_key, client_options=param_client_options, transport=param_transport, additional_headers=headers, @@ -547,7 +547,7 @@ def test_parse_response_candidate(raw_candidate: Dict, expected: AIMessage) -> N def test_serialize() -> None: - llm = ChatGoogleGenerativeAI(model="gemini-pro-1.5", google_api_key="test-key") # type: ignore[call-arg] + llm = ChatGoogleGenerativeAI(model="gemini-pro-1.5", api_key=SecretStr("test-key")) serialized = dumps(llm) llm_loaded = loads( serialized, diff --git a/libs/genai/tests/unit_tests/test_function_utils.py b/libs/genai/tests/unit_tests/test_function_utils.py index 536c2a997..ba9f62934 100644 --- a/libs/genai/tests/unit_tests/test_function_utils.py +++ b/libs/genai/tests/unit_tests/test_function_utils.py @@ -41,7 +41,7 @@ def sum_two_numbers(a: float, b: float) -> str: """ return str(a + b) - schema = convert_to_genai_function_declarations([sum_two_numbers]) # type: ignore + schema = convert_to_genai_function_declarations([sum_two_numbers]) function_declaration = schema.function_declarations[0] assert function_declaration.name == "sum_two_numbers" assert function_declaration.parameters @@ -52,7 +52,7 @@ def do_something_optional(a: float, b: float = 0) -> str: """Some description""" return str(a + b) - schema = convert_to_genai_function_declarations([do_something_optional]) # type: ignore + schema = convert_to_genai_function_declarations([do_something_optional]) function_declaration = schema.function_declarations[0] assert function_declaration.name == "do_something_optional" assert function_declaration.parameters diff --git a/libs/genai/tests/unit_tests/test_genai_aqa.py b/libs/genai/tests/unit_tests/test_genai_aqa.py index c8cd521b5..4deaaf9d2 100644 --- a/libs/genai/tests/unit_tests/test_genai_aqa.py +++ b/libs/genai/tests/unit_tests/test_genai_aqa.py @@ -3,11 +3,9 @@ import google.ai.generativelanguage as genai import pytest -from langchain_google_genai import ( - AqaInput, - GenAIAqa, -) +from langchain_google_genai import AqaInput, GenAIAqa from langchain_google_genai import _genai_extension as genaix +from langchain_google_genai._enums import HarmBlockThreshold, HarmCategory # Make sure the tests do not hit actual production servers. genaix.set_config( @@ -54,8 +52,8 @@ def test_invoke(mock_generate_answer: MagicMock) -> None: answer_style=genai.GenerateAnswerRequest.AnswerStyle.EXTRACTIVE, safety_settings=[ genai.SafetySetting( - category=genai.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, - threshold=genai.SafetySetting.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, + category=HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, + threshold=HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, ) ], ) @@ -80,11 +78,10 @@ def test_invoke(mock_generate_answer: MagicMock) -> None: assert len(request.safety_settings) == 1 assert ( request.safety_settings[0].category - == genai.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT + == HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT ) assert ( - request.safety_settings[0].threshold - == genai.SafetySetting.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE + request.safety_settings[0].threshold == HarmBlockThreshold.BLOCK_LOW_AND_ABOVE ) assert request.temperature == 0.5 diff --git a/libs/genai/tests/unit_tests/test_llms.py b/libs/genai/tests/unit_tests/test_llms.py index 29a689806..73b6762f6 100644 --- a/libs/genai/tests/unit_tests/test_llms.py +++ b/libs/genai/tests/unit_tests/test_llms.py @@ -1,3 +1,5 @@ +from pydantic import SecretStr + from langchain_google_genai.llms import GoogleGenerativeAI, GoogleModelFamily @@ -10,7 +12,7 @@ def test_model_family() -> None: def test_tracing_params() -> None: # Test standard tracing params - llm = GoogleGenerativeAI(model="gemini-pro", google_api_key="foo") # type: ignore[call-arg] + llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=SecretStr("foo")) ls_params = llm._get_ls_params() assert ls_params == { "ls_provider": "google_genai", @@ -23,7 +25,7 @@ def test_tracing_params() -> None: model="gemini-pro", temperature=0.1, max_output_tokens=10, - google_api_key="foo", # type: ignore[call-arg] + google_api_key=SecretStr("foo"), ) ls_params = llm._get_ls_params() assert ls_params == {