Skip to content

Commit

Permalink
add test for merging
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme committed Jan 18, 2025
1 parent a672688 commit 98ba7a8
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Test Perplexity Chat API wrapper."""

import os
from typing import Any, Dict, List
from typing import Any, Dict, List, Optional
from unittest.mock import MagicMock

import pytest
from langchain_core.messages import AIMessageChunk, BaseMessageChunk
from pytest_mock import MockerFixture

from langchain_community.chat_models import ChatPerplexity
Expand Down Expand Up @@ -82,7 +83,9 @@ def test_perplexity_stream_includes_citations(mocker: MockerFixture) -> None:
llm.client.chat.completions, "create", return_value=mock_stream
)
stream = llm.stream("Hello langchain")
full: Optional[BaseMessageChunk] = None
for i, chunk in enumerate(stream):
full = chunk if full is None else full + chunk
assert chunk.content == mock_chunks[i]["choices"][0]["delta"]["content"]
if i == 0:
assert chunk.additional_kwargs["citations"] == [
Expand All @@ -91,5 +94,8 @@ def test_perplexity_stream_includes_citations(mocker: MockerFixture) -> None:
]
else:
assert "citations" not in chunk.additional_kwargs
assert isinstance(full, AIMessageChunk)
assert full.content == "Hello Perplexity"
assert full.additional_kwargs == {"citations": ["example.com", "example2.com"]}

patcher.assert_called_once()

0 comments on commit 98ba7a8

Please sign in to comment.