Skip to content

Commit afd457d

Browse files
authored
perplexity[patch]: Fix #30767: Handle missing citations attribute in ChatPerplexity (#30805)
This PR fixes an issue where ChatPerplexity would raise an AttributeError when the citations attribute was missing from the model response (e.g., when using offline models like r1-1776). The fix checks for the presence of citations, images, and related_questions before attempting to access them, avoiding crashes in models that don't provide these fields. Tested locally with models that omit citations, and the fix works as expected.
1 parent 42944f3 commit afd457d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libs/partners/perplexity/langchain_perplexity/chat_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ def _generate(
375375
else:
376376
usage_metadata = None
377377

378-
additional_kwargs = {"citations": response.citations}
379-
for attr in ["images", "related_questions"]:
378+
additional_kwargs = {}
379+
for attr in ["citations", "images", "related_questions"]:
380380
if hasattr(response, attr):
381381
additional_kwargs[attr] = getattr(response, attr)
382382

0 commit comments

Comments
 (0)