Skip to content

Commit

Permalink
Added Unit Standard tests (#32)
Browse files Browse the repository at this point in the history
* Added Unit standard tests

* Updated Unit standard tests

* update for unit standard test v2
  • Loading branch information
MateuszOssGit authored Oct 16, 2024
1 parent 086cc32 commit 3501127
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libs/ibm/langchain_ibm/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ class ChatWatsonx(BaseChatModel):
* True - default path to truststore will be taken
* False - no verification will be made"""

validate_model: bool = True
"""Model ID validation."""

streaming: bool = False
""" Whether to stream the results or not. """

Expand Down Expand Up @@ -532,6 +535,7 @@ def validate_environment(self) -> Self:
project_id=self.project_id,
space_id=self.space_id,
verify=self.verify,
validate=self.validate_model,
)
self.watsonx_model = watsonx_model

Expand Down Expand Up @@ -584,6 +588,8 @@ def validate_environment(self) -> Self:
params=self.params,
project_id=self.project_id,
space_id=self.space_id,
verify=self.verify,
validate=self.validate_model,
)
self.watsonx_model = watsonx_chat

Expand Down
30 changes: 30 additions & 0 deletions libs/ibm/tests/unit_tests/test_chat_models_standard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import Type

from ibm_watsonx_ai import APIClient, Credentials # type: ignore
from ibm_watsonx_ai.service_instance import ServiceInstance # type: ignore
from langchain_core.language_models import BaseChatModel
from langchain_standard_tests.unit_tests import ChatModelUnitTests

from langchain_ibm import ChatWatsonx

client = APIClient.__new__(APIClient)
client.CLOUD_PLATFORM_SPACES = True
client.ICP_PLATFORM_SPACES = True
credentials = Credentials(api_key="api_key")
client.credentials = credentials
client.service_instance = ServiceInstance.__new__(ServiceInstance)
client.service_instance._credentials = credentials


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

@property
def chat_model_params(self) -> dict:
return {
"model_id": "ibm/granite-13b-instruct-v2",
"validate_model": False,
"watsonx_client": client,
}

0 comments on commit 3501127

Please sign in to comment.