Skip to content

Commit

Permalink
Merge pull request #10 from langchain-ai/mattf/test-chat-serialization
Browse files Browse the repository at this point in the history
add a serialization test of ChatNVIDIA using dumps/loads
  • Loading branch information
mattf authored Mar 27, 2024
2 parents 5ba62a9 + 8c8b173 commit 4ab2ee7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libs/ai-endpoints/tests/integration_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import warnings

import pytest
from langchain_core.load.dump import dumps
from langchain_core.load.load import loads
from langchain_core.messages import BaseMessage, HumanMessage, SystemMessage

from langchain_nvidia_ai_endpoints.chat_models import ChatNVIDIA
Expand Down Expand Up @@ -273,3 +275,11 @@ def test_ai_endpoints_invoke_top_p_positive(chat_model: str, mode: dict) -> None
result1 = llm1.invoke("What's in a top_p?")
assert isinstance(result1.content, str)
assert result0.content != result1.content


def test_serialize_chatnvidia() -> None:
model = loads(
dumps(ChatNVIDIA()), valid_namespaces=["langchain_nvidia_ai_endpoints"]
)
result = model.invoke("What is there if there is nothing?")
assert isinstance(result.content, str)
16 changes: 16 additions & 0 deletions libs/ai-endpoints/tests/unit_tests/test_serialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from langchain_core.load.dump import dumps
from langchain_core.load.load import loads

from langchain_nvidia_ai_endpoints import ChatNVIDIA


def test_serialize_chatnvidia() -> None:
secret = "a-bogus-key"
x = ChatNVIDIA(nvidia_api_key=secret)
y = loads(
dumps(x),
secrets_map={"NVIDIA_API_KEY": secret},
valid_namespaces=["langchain_nvidia_ai_endpoints"],
)
assert x == y
assert isinstance(y, ChatNVIDIA)

0 comments on commit 4ab2ee7

Please sign in to comment.