From 21c0e77f7a1463903cd3a8833171ab0c4327a02b Mon Sep 17 00:00:00 2001 From: Leonid Kuligin Date: Thu, 12 Dec 2024 08:39:17 +0100 Subject: [PATCH 1/6] added gemini-2.0 to the correct model family (#639) --- .../langchain_google_vertexai/_utils.py | 6 ++++- .../tests/integration_tests/test_standard.py | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/libs/vertexai/langchain_google_vertexai/_utils.py b/libs/vertexai/langchain_google_vertexai/_utils.py index f0e4d39d..a31c0d22 100644 --- a/libs/vertexai/langchain_google_vertexai/_utils.py +++ b/libs/vertexai/langchain_google_vertexai/_utils.py @@ -131,7 +131,11 @@ def _missing_(cls, value: Any) -> "GoogleModelFamily": "medlm-large-1.5-001", "medlm-large-1.5@001", } - if "gemini-1.5" in model_name or model_name in gemini_advanced_models: + if ( + "gemini-1.5" in model_name + or model_name in gemini_advanced_models + or "gemini-2" in model_name + ): return GoogleModelFamily.GEMINI_ADVANCED if "gemini" in model_name: return GoogleModelFamily.GEMINI diff --git a/libs/vertexai/tests/integration_tests/test_standard.py b/libs/vertexai/tests/integration_tests/test_standard.py index 960795f0..60db75c7 100644 --- a/libs/vertexai/tests/integration_tests/test_standard.py +++ b/libs/vertexai/tests/integration_tests/test_standard.py @@ -12,6 +12,33 @@ rate_limiter = InMemoryRateLimiter(requests_per_second=0.5) +@pytest.mark.first +class TestGemini2AIStandard(ChatModelIntegrationTests): + @property + def chat_model_class(self) -> Type[BaseChatModel]: + return ChatVertexAI + + @property + def chat_model_params(self) -> dict: + return { + "model_name": "gemini-2.0-flash-exp", + "rate_limiter": rate_limiter, + "temperature": 0, + } + + @property + def supports_image_inputs(self) -> bool: + return True + + @property + def supports_video_inputs(self) -> bool: + return True + + @property + def supports_audio_inputs(self) -> bool: + return True + + @pytest.mark.first class TestGeminiAIStandard(ChatModelIntegrationTests): @property From c46a26c84dff79e76bd967152e3934d1912c406d Mon Sep 17 00:00:00 2001 From: Leonid Kuligin Date: Thu, 12 Dec 2024 09:31:28 +0100 Subject: [PATCH 2/6] release vertexai 2.0.9 (#641) --- libs/vertexai/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/vertexai/pyproject.toml b/libs/vertexai/pyproject.toml index 7d8ce79d..6d12f431 100644 --- a/libs/vertexai/pyproject.toml +++ b/libs/vertexai/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langchain-google-vertexai" -version = "2.0.8" +version = "2.0.9" description = "An integration package connecting Google VertexAI and LangChain" authors = [] readme = "README.md" From 999eb7860dcd66f491283f684893ea18af335f2c Mon Sep 17 00:00:00 2001 From: Khaled El-hady <77120188+khaledelhady44@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:08:17 +0200 Subject: [PATCH 3/6] Removed redundant lines that added the "title" field to the schema. (#634) --- libs/genai/langchain_google_genai/_function_utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/genai/langchain_google_genai/_function_utils.py b/libs/genai/langchain_google_genai/_function_utils.py index e187577f..d7227268 100644 --- a/libs/genai/langchain_google_genai/_function_utils.py +++ b/libs/genai/langchain_google_genai/_function_utils.py @@ -342,8 +342,6 @@ def _get_items_from_schema(schema: Union[Dict, List, str]) -> Dict[str, Any]: items["type_"] = _get_type_from_schema(schema) if items["type_"] == glm.Type.OBJECT and "properties" in schema: items["properties"] = _get_properties_from_schema_any(schema["properties"]) - if "title" in schema: - items["title"] = schema if "title" in schema or "description" in schema: items["description"] = ( schema.get("description") or schema.get("title") or "" From 11cf22dc0418a24ed1a0e5c2ed019b59b387c493 Mon Sep 17 00:00:00 2001 From: lspataroG <167472995+lspataroG@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:50:00 +0100 Subject: [PATCH 4/6] fixed BQ vector search batch_search (#629) --- .../bq_storage_vectorstores/bigquery.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_google_community/bq_storage_vectorstores/bigquery.py b/libs/community/langchain_google_community/bq_storage_vectorstores/bigquery.py index b28a1da8..fa41473b 100644 --- a/libs/community/langchain_google_community/bq_storage_vectorstores/bigquery.py +++ b/libs/community/langchain_google_community/bq_storage_vectorstores/bigquery.py @@ -301,7 +301,7 @@ def _create_search_query( if table_to_query is not None: embeddings_query = f""" with embeddings as ( - SELECT {self.embedding_field}, ROW_NUMBER() OVER() as row_num + SELECT {self.embedding_field}, row_num from `{table_to_query}` )""" @@ -390,6 +390,7 @@ def _create_temp_bq_table( df = pd.DataFrame([]) df[self.embedding_field] = embeddings + df["row_num"] = list(range(len(df))) table_id = ( f"{self.project_id}." f"{self.temp_dataset_name}." @@ -397,7 +398,8 @@ def _create_temp_bq_table( ) schema = [ - bigquery.SchemaField(self.embedding_field, "FLOAT64", mode="REPEATED") + bigquery.SchemaField(self.embedding_field, "FLOAT64", mode="REPEATED"), + bigquery.SchemaField("row_num", "INT64"), ] table_ref = bigquery.Table(table_id, schema=schema) table = self._bq_client.create_table(table_ref) @@ -483,7 +485,7 @@ def batch_search( ) if queries is not None: - embeddings = self.embedding.embed_documents(queries) + embeddings = [self.embedding.embed_query(query) for query in queries] if embeddings is None: raise ValueError("Could not obtain embeddings - value is None.") From d71155d4250e28124680b7b5944be7a1350a8f5c Mon Sep 17 00:00:00 2001 From: Leonid Kuligin Date: Thu, 12 Dec 2024 13:56:41 +0100 Subject: [PATCH 5/6] release 2.0.7 (#643) --- libs/genai/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/genai/pyproject.toml b/libs/genai/pyproject.toml index 3bd5caab..561e65f3 100644 --- a/libs/genai/pyproject.toml +++ b/libs/genai/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langchain-google-genai" -version = "2.0.6" +version = "2.0.7" description = "An integration package connecting Google's genai package and LangChain" authors = [] readme = "README.md" From dbad3b8c9bbe33671f18ef86612d2bfd46ad959b Mon Sep 17 00:00:00 2001 From: Leonid Kuligin Date: Thu, 12 Dec 2024 15:00:36 +0100 Subject: [PATCH 6/6] enabled tool support for gemini2 (#640) --- .../langchain_google_genai/chat_models.py | 6 +++- .../tests/integration_tests/test_standard.py | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/libs/genai/langchain_google_genai/chat_models.py b/libs/genai/langchain_google_genai/chat_models.py index 45ad1cec..086fa23e 100644 --- a/libs/genai/langchain_google_genai/chat_models.py +++ b/libs/genai/langchain_google_genai/chat_models.py @@ -1374,7 +1374,11 @@ def create_cached_content( @property def _supports_tool_choice(self) -> bool: - return "gemini-1.5-pro" in self.model or "gemini-1.5-flash" in self.model + return ( + "gemini-1.5-pro" in self.model + or "gemini-1.5-flash" in self.model + or "gemini-2" in self.model + ) def _get_tool_name( diff --git a/libs/genai/tests/integration_tests/test_standard.py b/libs/genai/tests/integration_tests/test_standard.py index e8feaee9..a5a7d230 100644 --- a/libs/genai/tests/integration_tests/test_standard.py +++ b/libs/genai/tests/integration_tests/test_standard.py @@ -11,6 +11,36 @@ from langchain_google_genai import ChatGoogleGenerativeAI rate_limiter = InMemoryRateLimiter(requests_per_second=0.25) +rate_limiter_2_0 = InMemoryRateLimiter(requests_per_second=0.1) + + +class TestGeminiAI2Standard(ChatModelIntegrationTests): + @property + def chat_model_class(self) -> Type[BaseChatModel]: + return ChatGoogleGenerativeAI + + @property + def chat_model_params(self) -> dict: + return { + "model": "models/gemini-2.0-flash-exp", + "rate_limiter": rate_limiter_2_0, + } + + @pytest.mark.xfail(reason="with_structured_output with JSON schema not supported.") + async def test_structured_output_async(self, model: BaseChatModel) -> None: + await super().test_structured_output_async(model) + + @pytest.mark.xfail(reason="with_structured_output with JSON schema not supported.") + def test_structured_output(self, model: BaseChatModel) -> None: + super().test_structured_output(model) + + @pytest.mark.xfail(reason="with_structured_output with JSON schema not supported.") + def test_structured_output_pydantic_2_v1(self, model: BaseChatModel) -> None: + super().test_structured_output_pydantic_2_v1(model) + + @pytest.mark.xfail(reason="investigate") + def test_bind_runnables_as_tools(self, model: BaseChatModel) -> None: + super().test_bind_runnables_as_tools(model) class TestGeminiAIStandard(ChatModelIntegrationTests):