Skip to content

Commit 16a422f

Browse files
authored
community: add standard tests for Perplexity (#29534)
1 parent 21d8d41 commit 16a422f

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Standard LangChain interface tests"""
2+
3+
from typing import Type
4+
5+
import pytest
6+
from langchain_core.language_models import BaseChatModel
7+
from langchain_tests.integration_tests import ChatModelIntegrationTests
8+
9+
from langchain_community.chat_models import ChatPerplexity
10+
11+
12+
class TestPerplexityStandard(ChatModelIntegrationTests):
13+
@property
14+
def chat_model_class(self) -> Type[BaseChatModel]:
15+
return ChatPerplexity
16+
17+
@property
18+
def chat_model_params(self) -> dict:
19+
return {"model": "sonar"}
20+
21+
@property
22+
def returns_usage_metadata(self) -> bool:
23+
# TODO: add usage metadata and delete this property
24+
# https://docs.perplexity.ai/api-reference/chat-completions#response-usage
25+
return False
26+
27+
@pytest.mark.xfail(reason="TODO: handle in integration.")
28+
def test_double_messages_conversation(self, model: BaseChatModel) -> None:
29+
super().test_double_messages_conversation(model)
30+
31+
@pytest.mark.xfail(reason="Raises 400: Custom stop words not supported.")
32+
def test_stop_sequence(self, model: BaseChatModel) -> None:
33+
super().test_stop_sequence(model)

libs/community/tests/unit_tests/chat_models/test_perplexity.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
"""Test Perplexity Chat API wrapper."""
22

33
import os
4-
from typing import Any, Dict, List, Optional
4+
from typing import Any, Dict, List, Optional, Tuple, Type
55
from unittest.mock import MagicMock
66

77
import pytest
8+
from langchain_core.language_models import BaseChatModel
89
from langchain_core.messages import AIMessageChunk, BaseMessageChunk
10+
from langchain_tests.unit_tests import ChatModelUnitTests
911
from pytest_mock import MockerFixture
1012

1113
from langchain_community.chat_models import ChatPerplexity
1214

1315
os.environ["PPLX_API_KEY"] = "foo"
1416

1517

18+
@pytest.mark.requires("openai")
19+
class TestPerplexityStandard(ChatModelUnitTests):
20+
@property
21+
def chat_model_class(self) -> Type[BaseChatModel]:
22+
return ChatPerplexity
23+
24+
@property
25+
def init_from_env_params(self) -> Tuple[dict, dict, dict]:
26+
return (
27+
{"PPLX_API_KEY": "api_key"},
28+
{},
29+
{"pplx_api_key": "api_key"},
30+
)
31+
32+
1633
@pytest.mark.requires("openai")
1734
def test_perplexity_model_name_param() -> None:
1835
llm = ChatPerplexity(model="foo") # type: ignore[call-arg]

0 commit comments

Comments
 (0)