Skip to content

Commit

Permalink
Merge branch 'main' into vi-test
Browse files Browse the repository at this point in the history
  • Loading branch information
emma0925 authored Dec 13, 2024
2 parents 72db52b + dbad3b8 commit 87d9008
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
)"""

Expand Down Expand Up @@ -390,14 +390,16 @@ 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}."
f"{self.table_name}_{uuid.uuid4().hex}"
)

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)
Expand Down Expand Up @@ -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.")
Expand Down
2 changes: 0 additions & 2 deletions libs/genai/langchain_google_genai/_function_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
6 changes: 5 additions & 1 deletion libs/genai/langchain_google_genai/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,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(
Expand Down
2 changes: 1 addition & 1 deletion libs/genai/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
30 changes: 30 additions & 0 deletions libs/genai/tests/integration_tests/test_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion libs/vertexai/langchain_google_vertexai/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/vertexai/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
27 changes: 27 additions & 0 deletions libs/vertexai/tests/integration_tests/test_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 87d9008

Please sign in to comment.