Skip to content

Commit

Permalink
genai[patch]: fix standard tests (#480)
Browse files Browse the repository at this point in the history
Existing tests do not run because they don't start with a `Test` prefix.
Here we separate them into their own modules and get them in a running
state.
  • Loading branch information
ccurme authored Sep 6, 2024
2 parents 7619534 + 7bf4938 commit 8958221
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 50 deletions.
26 changes: 1 addition & 25 deletions libs/genai/tests/integration_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import asyncio
import json
from typing import Generator, List, Optional, Type
from typing import Generator, List, Optional

import pytest
from langchain_core.language_models import BaseChatModel
from langchain_core.messages import (
AIMessage,
AIMessageChunk,
Expand All @@ -17,7 +16,6 @@
)
from langchain_core.pydantic_v1 import BaseModel
from langchain_core.tools import tool
from langchain_standard_tests.integration_tests import ChatModelIntegrationTests

from langchain_google_genai import (
ChatGoogleGenerativeAI,
Expand All @@ -31,28 +29,6 @@
_B64_string = """iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAABhGlDQ1BJQ0MgUHJvZmlsZQAAeJx9kT1Iw0AcxV8/xCIVQTuIKGSoTi2IijhqFYpQIdQKrTqYXPoFTRqSFBdHwbXg4Mdi1cHFWVcHV0EQ/ABxdXFSdJES/5cUWsR4cNyPd/ced+8Af6PCVDM4DqiaZaSTCSGbWxW6XxHECPoRQ0hipj4niil4jq97+Ph6F+dZ3uf+HL1K3mSATyCeZbphEW8QT29aOud94ggrSQrxOXHMoAsSP3JddvmNc9FhP8+MGJn0PHGEWCh2sNzBrGSoxFPEUUXVKN+fdVnhvMVZrdRY6578heG8trLMdZrDSGIRSxAhQEYNZVRgIU6rRoqJNO0nPPxDjl8kl0yuMhg5FlCFCsnxg//B727NwuSEmxROAF0vtv0xCnTvAs26bX8f23bzBAg8A1da219tADOfpNfbWvQI6NsGLq7bmrwHXO4Ag0+6ZEiOFKDpLxSA9zP6phwwcAv0rLm9tfZx+gBkqKvUDXBwCIwVKXvd492hz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BIVxJKzQECBDLF2qu2WTMmCovtDQ1f8iyoGkUADBCCGPsdnvTW2OtFm01VeB06msvdWlpPZU0wJRG85ns84umU3k+VyxeEcWqvYUBAGsUrbvme4be99HFeisP/pwUOIZaOqQX31ISgrKmZhLHtXNXuJq68orrr5/9mBCglCLAGGPyy81votEbcjlKLrC9E8mhH3wdHRdcyyvjidSlxjftPJpD+o25JYvRHGFoZDdks1mBQhxJu9uxvwEiXuHnHbLd1AAAAABJRU5ErkJggg==""" # noqa: E501


class GoogleGenerativeAIStandardTests(ChatModelIntegrationTests):
@property
def chat_model_class(self) -> Type[BaseChatModel]:
return ChatGoogleGenerativeAI

@property
def chat_model_params(self) -> dict:
return {"model": _MODEL}

@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


def _check_usage_metadata(message: AIMessage) -> None:
assert message.usage_metadata is not None
assert message.usage_metadata["input_tokens"] > 0
Expand Down
44 changes: 44 additions & 0 deletions libs/genai/tests/integration_tests/test_standard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Standard LangChain interface tests"""

from typing import Type

import pytest
from langchain_core.language_models import BaseChatModel
from langchain_core.rate_limiters import InMemoryRateLimiter
from langchain_standard_tests.integration_tests import ChatModelIntegrationTests

from langchain_google_genai import ChatGoogleGenerativeAI

rate_limiter = InMemoryRateLimiter(requests_per_second=0.25)


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

@property
def chat_model_params(self) -> dict:
return {
"model": "models/gemini-1.0-pro-001",
"rate_limiter": rate_limiter,
}

@pytest.mark.xfail(reason="Gemini 1.0 doesn't support tool_choice='any'")
def test_structured_few_shot_examples(self, model: BaseChatModel) -> None:
super().test_structured_few_shot_examples(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="Not yet supported")
def test_tool_message_histories_list_content(self, model: BaseChatModel) -> None:
super().test_tool_message_histories_list_content(model)


# TODO: increase quota on gemini-1.5-pro-001 and test as well
26 changes: 1 addition & 25 deletions libs/genai/tests/unit_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import json
from concurrent.futures import ThreadPoolExecutor
from typing import Dict, List, Optional, Type, Union
from typing import Dict, List, Optional, Union
from unittest.mock import ANY, Mock, patch

import google.ai.generativelanguage as glm
Expand All @@ -14,7 +14,6 @@
GenerateContentResponse,
Part,
)
from langchain_core.language_models import BaseChatModel
from langchain_core.load import dumps, loads
from langchain_core.messages import (
AIMessage,
Expand All @@ -25,7 +24,6 @@
)
from langchain_core.messages.tool import tool_call as create_tool_call
from langchain_core.pydantic_v1 import SecretStr
from langchain_standard_tests.unit_tests import ChatModelUnitTests
from pytest import CaptureFixture

from langchain_google_genai.chat_models import (
Expand All @@ -35,28 +33,6 @@
)


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

@property
def chat_model_params(self) -> dict:
return {"model": "gemini-1.5-pro"}

@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


def test_integration_initialization() -> None:
"""Test chat model initialization."""
llm = ChatGoogleGenerativeAI(
Expand Down
26 changes: 26 additions & 0 deletions libs/genai/tests/unit_tests/test_standard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Type

from langchain_core.language_models import BaseChatModel
from langchain_standard_tests.unit_tests import ChatModelUnitTests

from langchain_google_genai import ChatGoogleGenerativeAI


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

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


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

@property
def chat_model_params(self) -> dict:
return {"model": "models/gemini-1.5-pro-001"}

0 comments on commit 8958221

Please sign in to comment.