Skip to content

Commit

Permalink
enabled tool support for gemini2 (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkuligin authored Dec 12, 2024
1 parent d71155d commit dbad3b8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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 @@ -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(
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

0 comments on commit dbad3b8

Please sign in to comment.