Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vertexai: update standard tests library #704

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions libs/vertexai/langchain_google_vertexai/functions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,21 @@ def _format_to_gapic_function_declaration(
tool: _FunctionDeclarationLike,
) -> gapic.FunctionDeclaration:
"Format tool into the Vertex function declaration."
print("_format_to_gapic_function_declaration")
print(tool)
if isinstance(tool, BaseTool):
return _format_base_tool_to_function_declaration(tool)
elif isinstance(tool, type) and issubclass(tool, BaseModel):
return _format_pydantic_to_function_declaration(tool)
elif callable(tool):
elif callable(tool) and not (
isinstance(tool, type) and hasattr(tool, "__annotations__")
):
return _format_base_tool_to_function_declaration(callable_as_lc_tool()(tool))
elif isinstance(tool, vertexai.FunctionDeclaration):
return _format_vertex_to_function_declaration(tool)
elif isinstance(tool, dict):
elif isinstance(tool, dict) or (
isinstance(tool, type) and hasattr(tool, "__annotations__")
):
# this could come from
# 'langchain_core.utils.function_calling.convert_to_openai_tool'
function = convert_to_openai_tool(cast(dict, tool))["function"]
Expand Down
923 changes: 515 additions & 408 deletions libs/vertexai/poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions libs/vertexai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT"

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
langchain-core = ">=0.3.27,<0.4"
langchain-core = ">=0.3.31,<0.4"
google-cloud-aiplatform = "^1.76.0"
google-cloud-storage = "^2.18.0"
# optional dependencies
Expand All @@ -28,7 +28,7 @@ optional = true
[tool.poetry.group.test.dependencies]
pytest = "^7.3.0"
pytest-xdist = "^3.0"
pytest-order = "^1.3"
pytest-order = "^1.3"
pytest-retry = "^1.6.3"
freezegun = "^1.2.2"
pytest-mock = "^3.10.0"
Expand All @@ -44,7 +44,7 @@ numpy = [
]
google-api-python-client = "^2.117.0"
langchain = "^0.3.7"
langchain-tests = "0.3.6"
langchain-tests = "0.3.9"
anthropic = { extras = ["vertexai"], version = ">=0.35.0,<1" }


Expand Down
25 changes: 1 addition & 24 deletions libs/vertexai/tests/integration_tests/test_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest
from langchain_core.language_models import BaseChatModel
from langchain_core.rate_limiters import InMemoryRateLimiter
from langchain_core.tools import BaseTool
from langchain_tests.integration_tests import ChatModelIntegrationTests

from langchain_google_vertexai import ChatVertexAI
Expand Down Expand Up @@ -41,28 +40,6 @@ def supports_audio_inputs(self) -> bool:
return True


@pytest.mark.first
class TestGeminiAIStandard(ChatModelIntegrationTests):
@property
def chat_model_class(self) -> Type[BaseChatModel]:
return ChatVertexAI

@property
def chat_model_params(self) -> dict:
return {
"model_name": "gemini-1.0-pro-001",
"rate_limiter": rate_limiter,
"temperature": 0,
"api_transport": None,
}

@pytest.mark.xfail(reason="Gemini 1.0 doesn't support tool_choice='any'")
def test_structured_few_shot_examples(
self, model: BaseChatModel, my_adder_tool: BaseTool
) -> None:
super().test_structured_few_shot_examples(model, my_adder_tool)


class TestGemini_15_AIStandard(ChatModelIntegrationTests):
@property
def chat_model_class(self) -> Type[BaseChatModel]:
Expand All @@ -71,7 +48,7 @@ def chat_model_class(self) -> Type[BaseChatModel]:
@property
def chat_model_params(self) -> dict:
return {
"model_name": "gemini-1.5-pro-001",
"model_name": "gemini-1.5-pro-002",
"rate_limiter": rate_limiter,
"temperature": 0,
"api_transport": None,
Expand Down
28 changes: 0 additions & 28 deletions libs/vertexai/tests/unit_tests/__snapshots__/test_standard.ambr
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
# serializer version: 1
# name: TestGeminiAIStandard.test_serdes[serialized]
dict({
'id': list([
'langchain',
'chat_models',
'vertexai',
'ChatVertexAI',
]),
'kwargs': dict({
'default_metadata': list([
]),
'location': 'us-central1',
'max_output_tokens': 100,
'max_retries': 2,
'model_family': '1',
'model_name': 'gemini-1.0-pro-001',
'n': 1,
'project': 'test-project',
'request_parallelism': 5,
'stop': list([
]),
'temperature': 0.0,
}),
'lc': 1,
'name': 'ChatVertexAI',
'type': 'constructor',
})
# ---
# name: TestGemini_15_AIStandard.test_serdes[serialized]
dict({
'id': list([
Expand Down
5 changes: 4 additions & 1 deletion libs/vertexai/tests/unit_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
PydanticToolsParser,
)
from pydantic import BaseModel
from vertexai.generative_models import ( # type: ignore
SafetySetting as VertexSafetySetting,
)
from vertexai.language_models import ( # type: ignore
ChatMessage,
InputOutputTextPair,
Expand Down Expand Up @@ -945,7 +948,7 @@ def test_safety_settings_gemini() -> None:

def test_safety_settings_gemini_init() -> None:
expected_safety_setting = [
SafetySetting(
VertexSafetySetting(
category=HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold=SafetySetting.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
method=SafetySetting.HarmBlockMethod.SEVERITY,
Expand Down
10 changes: 0 additions & 10 deletions libs/vertexai/tests/unit_tests/test_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
from langchain_google_vertexai import ChatVertexAI


class TestGeminiAIStandard(ChatModelUnitTests):
@property
def chat_model_class(self) -> Type[BaseChatModel]:
return ChatVertexAI

@property
def chat_model_params(self) -> dict:
return {"model_name": "gemini-1.0-pro-001"}


class TestGemini_15_AIStandard(ChatModelUnitTests):
@property
def chat_model_class(self) -> Type[BaseChatModel]:
Expand Down
Loading