From afd457d8e177020898319da588c3a042e001c129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marina=20G=C3=B3mez?= <55047412+Margo3s@users.noreply.github.com> Date: Sun, 13 Apr 2025 15:24:05 +0200 Subject: [PATCH] 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. --- libs/partners/perplexity/langchain_perplexity/chat_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/partners/perplexity/langchain_perplexity/chat_models.py b/libs/partners/perplexity/langchain_perplexity/chat_models.py index 69ff64696f1..6ca9809352b 100644 --- a/libs/partners/perplexity/langchain_perplexity/chat_models.py +++ b/libs/partners/perplexity/langchain_perplexity/chat_models.py @@ -375,8 +375,8 @@ class ChatPerplexity(BaseChatModel): else: usage_metadata = None - additional_kwargs = {"citations": response.citations} - for attr in ["images", "related_questions"]: + additional_kwargs = {} + for attr in ["citations", "images", "related_questions"]: if hasattr(response, attr): additional_kwargs[attr] = getattr(response, attr)