Home / Class/ TestChatPerplexityIntegration Class — langchain Architecture

TestChatPerplexityIntegration Class — langchain Architecture

Architecture documentation for the TestChatPerplexityIntegration class in test_chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  974a163b_6ea0_9385_8678_c36e3c96fcdf["TestChatPerplexityIntegration"]
  107b4517_5d8d_c2f0_26fe_e47232c7ca12["test_chat_models.py"]
  974a163b_6ea0_9385_8678_c36e3c96fcdf -->|defined in| 107b4517_5d8d_c2f0_26fe_e47232c7ca12
  6796af7b_3011_76ca_f40d_fa8186d8b184["test_standard_generation()"]
  974a163b_6ea0_9385_8678_c36e3c96fcdf -->|method| 6796af7b_3011_76ca_f40d_fa8186d8b184
  1d3eb916_69ad_5f58_39e4_e351c5602fb6["test_async_generation()"]
  974a163b_6ea0_9385_8678_c36e3c96fcdf -->|method| 1d3eb916_69ad_5f58_39e4_e351c5602fb6
  fc634cbc_84a6_4b8b_0d52_511f11b72627["test_pro_search()"]
  974a163b_6ea0_9385_8678_c36e3c96fcdf -->|method| fc634cbc_84a6_4b8b_0d52_511f11b72627
  23a9ed7e_9b6b_b952_bf83_acf91b723c0e["test_streaming()"]
  974a163b_6ea0_9385_8678_c36e3c96fcdf -->|method| 23a9ed7e_9b6b_b952_bf83_acf91b723c0e
  fffc55c5_1247_49b0_8605_4a25a6dc3963["test_citations_and_search_results()"]
  974a163b_6ea0_9385_8678_c36e3c96fcdf -->|method| fffc55c5_1247_49b0_8605_4a25a6dc3963
  ae33c12d_bded_193c_b3ef_0b08116fd4e6["test_search_control()"]
  974a163b_6ea0_9385_8678_c36e3c96fcdf -->|method| ae33c12d_bded_193c_b3ef_0b08116fd4e6
  24c3429d_6d58_c3c0_4d7b_fbb9b44fe0d2["test_search_recency_filter()"]
  974a163b_6ea0_9385_8678_c36e3c96fcdf -->|method| 24c3429d_6d58_c3c0_4d7b_fbb9b44fe0d2
  453ba8ad_5979_edb8_755c_2f78e32db84c["test_search_domain_filter()"]
  974a163b_6ea0_9385_8678_c36e3c96fcdf -->|method| 453ba8ad_5979_edb8_755c_2f78e32db84c
  0ee987f0_a583_79cf_b439_1e4ae6cfbd20["test_media_and_metadata()"]
  974a163b_6ea0_9385_8678_c36e3c96fcdf -->|method| 0ee987f0_a583_79cf_b439_1e4ae6cfbd20

Relationship Graph

Source Code

libs/partners/perplexity/tests/integration_tests/test_chat_models.py lines 12–125

class TestChatPerplexityIntegration:
    def test_standard_generation(self) -> None:
        """Test standard generation."""
        chat = ChatPerplexity(model="sonar", temperature=0)
        message = HumanMessage(content="Hello! How are you?")
        response = chat.invoke([message])
        assert response.content
        assert isinstance(response.content, str)

    async def test_async_generation(self) -> None:
        """Test async generation."""
        chat = ChatPerplexity(model="sonar", temperature=0)
        message = HumanMessage(content="Hello! How are you?")
        response = await chat.ainvoke([message])
        assert response.content
        assert isinstance(response.content, str)

    def test_pro_search(self) -> None:
        """Test Pro Search (reasoning_steps extraction)."""
        # Pro search is available on sonar-pro
        chat = ChatPerplexity(
            model="sonar-pro",
            temperature=0,
            web_search_options=WebSearchOptions(search_type="pro"),
            streaming=True,
        )
        message = HumanMessage(content="Who won the 2024 US election and why?")

        # We need to collect chunks to check reasoning steps
        chunks = list(chat.stream([message]))
        full_content = "".join(c.content for c in chunks if isinstance(c.content, str))
        assert full_content

        # Check if any chunk has reasoning_steps
        has_reasoning = any("reasoning_steps" in c.additional_kwargs for c in chunks)
        if has_reasoning:
            assert True
        else:
            # Fallback assertion if no reasoning steps returned
            assert len(chunks) > 0

    async def test_streaming(self) -> None:
        """Test streaming."""
        chat = ChatPerplexity(model="sonar", temperature=0)
        message = HumanMessage(content="Count to 5")
        async for chunk in chat.astream([message]):
            assert isinstance(chunk.content, str)

    def test_citations_and_search_results(self) -> None:
        """Test that citations and search results are returned."""
        chat = ChatPerplexity(model="sonar", temperature=0)
        message = HumanMessage(content="Who is the CEO of OpenAI?")
        response = chat.invoke([message])

        # Citations are usually in additional_kwargs
        assert "citations" in response.additional_kwargs
        # Search results might be there too
        # Note: presence depends on whether search was performed
        if response.additional_kwargs.get("citations"):
            assert len(response.additional_kwargs["citations"]) > 0

    def test_search_control(self) -> None:
        """Test search control parameters."""
        # Test disabled search (should complete without citations)
        chat = ChatPerplexity(model="sonar", disable_search=True)
        message = HumanMessage(content="What is 2+2?")
        response = chat.invoke([message])
        assert response.content

        # Test search classifier
        chat_classifier = ChatPerplexity(model="sonar", enable_search_classifier=True)
        response_classifier = chat_classifier.invoke([message])
        assert response_classifier.content

    def test_search_recency_filter(self) -> None:
        """Test search_recency_filter parameter."""
        chat = ChatPerplexity(model="sonar", search_recency_filter="month")
        message = HumanMessage(content="Latest AI news")
        response = chat.invoke([message])
        assert response.content

Frequently Asked Questions

What is the TestChatPerplexityIntegration class?
TestChatPerplexityIntegration is a class in the langchain codebase, defined in libs/partners/perplexity/tests/integration_tests/test_chat_models.py.
Where is TestChatPerplexityIntegration defined?
TestChatPerplexityIntegration is defined in libs/partners/perplexity/tests/integration_tests/test_chat_models.py at line 12.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free