test_chat_models.py — langchain Source File
Architecture documentation for test_chat_models.py, a python file in the langchain codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 4abfcafd_dd82_ade2_c55b_57b710b18828["test_chat_models.py"] 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c["os"] 4abfcafd_dd82_ade2_c55b_57b710b18828 --> 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] 4abfcafd_dd82_ade2_c55b_57b710b18828 --> 120e2591_3e15_b895_72b6_cb26195e40a6 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] 4abfcafd_dd82_ade2_c55b_57b710b18828 --> d758344f_537f_649e_f467_b9d7442e86df 0a64b352_1be7_5fff_8155_512d479e612f["langchain_perplexity"] 4abfcafd_dd82_ade2_c55b_57b710b18828 --> 0a64b352_1be7_5fff_8155_512d479e612f style 4abfcafd_dd82_ade2_c55b_57b710b18828 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Integration tests for ChatPerplexity."""
import os
import pytest
from langchain_core.messages import HumanMessage
from langchain_perplexity import ChatPerplexity, MediaResponse, WebSearchOptions
@pytest.mark.skipif(not os.environ.get("PPLX_API_KEY"), reason="PPLX_API_KEY not set")
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:
// ... (66 more lines)
Domain
Subdomains
Classes
Dependencies
- langchain_core.messages
- langchain_perplexity
- os
- pytest
Source
Frequently Asked Questions
What does test_chat_models.py do?
test_chat_models.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What does test_chat_models.py depend on?
test_chat_models.py imports 4 module(s): langchain_core.messages, langchain_perplexity, os, pytest.
Where is test_chat_models.py in the architecture?
test_chat_models.py is located at libs/partners/perplexity/tests/integration_tests/test_chat_models.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/partners/perplexity/tests/integration_tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free