Skip to content

community: fix perplexity response parameters not being included in model response#30440

Merged
ccurme (ccurme) merged 10 commits into
langchain-ai:masterfrom
DavidSanSan110:davidsansan/handle-perplexity-response-args
Mar 27, 2025
Merged

community: fix perplexity response parameters not being included in model response#30440
ccurme (ccurme) merged 10 commits into
langchain-ai:masterfrom
DavidSanSan110:davidsansan/handle-perplexity-response-args

Conversation

@DavidSanSan110
Copy link
Copy Markdown
Contributor

This pull request includes enhancements to the perplexity.py file in the chat_models module, focusing on improving the handling of additional keyword arguments (additional_kwargs) in message processing methods. Additionally, new unit tests have been added to ensure the correct inclusion of citations, images, and related questions in the additional_kwargs.

Issue: resolves #30439

Enhancements to perplexity.py:

New unit tests:

  • libs/community/tests/unit_tests/chat_models/test_perplexity.py: Added new tests test_perplexity_stream_includes_citations_and_images and test_perplexity_stream_includes_citations_and_related_questions to verify that the stream method correctly includes citations, images, and related questions in the additional_kwargs.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Mar 26, 2025 8:51pm

@dosubot dosubot Bot added size:L bug Related to a bug, vulnerability, unexpected error with an existing feature labels Mar 23, 2025

chunk = self._convert_delta_to_message_chunk(
choice["delta"], default_chunk_class
choice["delta"], default_chunk_class, additional_kwargs
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick but could we update chunk.additional_kwargs below in this function, as we were doing before, instead of passing it into _convert_delta_to_message_chunk and mutating it there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the code to add additional_kwargs after calling _convert_delta_to_message_chunk, rather than modifying it inside the function. 👌

@ccurme ccurme (ccurme) self-assigned this Mar 26, 2025
@ccurme ccurme (ccurme) requested a review from Copilot March 26, 2025 19:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the handling of additional keyword arguments in the Perplexity chat model responses and adds new tests to verify that citations, images, and related questions are correctly included.

  • Updated the _stream and _generate methods in perplexity.py to merge additional keyword arguments from API responses.
  • Added new unit tests to verify that the stream method correctly includes citations with images and related questions.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
libs/community/langchain_community/chat_models/perplexity.py Updated _stream and _generate to build and merge additional_kwargs from API responses.
libs/community/tests/unit_tests/chat_models/test_perplexity.py Added tests to verify that citations, images, and related_questions are included in the streamed output.
Comments suppressed due to low confidence (2)

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

  • [nitpick] The test function's docstring indicates it only checks citations, yet the test also verifies that images are included. Consider updating the docstring to accurately reflect that both citations and images are being tested.
def test_perplexity_stream_includes_citations_and_images(mocker: MockerFixture) -> None:

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

  • [nitpick] The test function's docstring states it only checks citations while the test verifies both citations and related questions. Update the docstring for clarity.
def test_perplexity_stream_includes_citations_and_related_questions(mocker: MockerFixture) -> None:

@dosubot dosubot Bot added the lgtm label Mar 26, 2025
@ccurme ccurme (ccurme) merged commit 75823d5 into langchain-ai:master Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Related to a bug, vulnerability, unexpected error with an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perplexity response parameters not being included in model response

3 participants