Skip to content

Commit

Permalink
fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lkuligin committed Nov 27, 2024
1 parent 7df7cad commit b60ba6a
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 12 deletions.
4 changes: 3 additions & 1 deletion libs/vertexai/langchain_google_vertexai/_anthropic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
from pydantic import BaseModel

if TYPE_CHECKING:
from anthropic.types import RawMessageStreamEvent # type: ignore[import-not-found]
from anthropic.types import (
RawMessageStreamEvent, # type: ignore[unused-ignore, import-not-found]
)

_message_type_lookups = {
"human": "user",
Expand Down
2 changes: 1 addition & 1 deletion libs/vertexai/langchain_google_vertexai/model_garden.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __init__(self, **kwargs: Any) -> None:

@model_validator(mode="after")
def validate_environment(self) -> Self:
from anthropic import ( # type: ignore[import-not-found]
from anthropic import ( # type: ignore[unused-ignore, import-not-found]
AnthropicVertex,
AsyncAnthropicVertex,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,15 @@ def mset(self, key_value_pairs: Sequence[Tuple[str, Document]]) -> None:
entities = []
for key, document in zip(keys, documents):
entity = self._client.entity(
key=key, exclude_from_indexes=self.exclude_from_indexes
key=key,
exclude_from_indexes=self.exclude_from_indexes
if self.exclude_from_indexes
else [],
)
metadata_entity = self._client.entity(
exclude_from_indexes=self.exclude_from_indexes
if self.exclude_from_indexes
else []
)
metadata_entity.update(document.metadata)
entity[self._text_property_name] = document.page_content
Expand Down
19 changes: 18 additions & 1 deletion libs/vertexai/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libs/vertexai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ optional = true
pytest = "^7.3.0"
pytest-xdist = "^3.0"
pytest-order = "^1.3"
pytest-retry = "^1.6.3"
freezegun = "^1.2.2"
pytest-mock = "^3.10.0"
syrupy = "^4.0.2"
Expand Down
1 change: 1 addition & 0 deletions libs/vertexai/tests/integration_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ class Response(BaseModel):
assert isinstance(response, Response)


@pytest.mark.flaky(retries=3)
@pytest.mark.release
def test_chat_vertexai_gemini_function_calling_with_multiple_parts() -> None:
@tool
Expand Down
2 changes: 2 additions & 0 deletions libs/vertexai/tests/integration_tests/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_evaluate() -> None:


@pytest.mark.extended
@pytest.mark.flaky(retries=3)
def test_evaluate_strings() -> None:
evaluator = VertexStringEvaluator(
metric="safety", project_id=os.environ["PROJECT_ID"]
Expand All @@ -40,6 +41,7 @@ def test_evaluate_strings() -> None:


@pytest.mark.extended
@pytest.mark.flaky(retries=3)
async def test_aevaluate_strings() -> None:
evaluator = VertexStringEvaluator(
metric="question_answering_quality", project_id=os.environ["PROJECT_ID"]
Expand Down
14 changes: 6 additions & 8 deletions libs/vertexai/tests/integration_tests/test_maas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
)

model_names = _LLAMA_MODELS + _MISTRAL_MODELS
model_names_with_tools_support = _MISTRAL_MODELS + [
"meta/llama3-405b-instruct-maas",
"meta/llama-3.2-90b-vision-instruct-maas",
]
model_names_with_tools_support = _MISTRAL_MODELS + ["meta/llama3-405b-instruct-maas"]


@pytest.mark.extended
Expand All @@ -45,8 +42,8 @@ async def test_agenerate(model_name: str) -> None:
@pytest.mark.extended
@pytest.mark.parametrize("model_name", model_names)
def test_stream(model_name: str) -> None:
# b/371631576
if model_name == "meta/llama3-8b-instruct-maas":
# streaming currently fails with mistral-nemo@2407
if model_name == "mistral-nemo@2407":
return
llm = get_vertex_maas_model(model_name=model_name, location="us-central1")
output = llm.stream("What is the meaning of life?")
Expand All @@ -57,8 +54,8 @@ def test_stream(model_name: str) -> None:
@pytest.mark.extended
@pytest.mark.parametrize("model_name", model_names)
async def test_astream(model_name: str) -> None:
# b/371631576
if model_name == "meta/llama3-8b-instruct-maas":
# streaming currently fails with mistral-nemo@2407
if model_name == "mistral-nemo@2407":
return
llm = get_vertex_maas_model(model_name=model_name, location="us-central1")
output = llm.astream("What is the meaning of life?")
Expand All @@ -68,6 +65,7 @@ async def test_astream(model_name: str) -> None:

@pytest.mark.extended
@pytest.mark.parametrize("model_name", model_names_with_tools_support)
@pytest.mark.flaky(retries=3)
async def test_tools(model_name: str) -> None:
@tool
def search(
Expand Down
1 change: 1 addition & 0 deletions libs/vertexai/tests/integration_tests/test_model_garden.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def _check_tool_calls(response: BaseMessage, expected_name: str) -> None:


@pytest.mark.extended
@pytest.mark.flaky(retries=3)
def test_anthropic_tool_calling() -> None:
project = os.environ["PROJECT_ID"]
location = "us-east5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def test_vertex_ai_visual_qna_chat(base64_image: str):


@pytest.mark.release
@pytest.mark.flaky(retries=3)
def test_vertex_ai_image_generation_and_edition():
generator = VertexAIImageGeneratorChat()

Expand Down

0 comments on commit b60ba6a

Please sign in to comment.