From 230876a7c50eb7a200dfda35cce87486ea02e2f8 Mon Sep 17 00:00:00 2001 From: ccurme Date: Fri, 7 Mar 2025 09:19:08 -0500 Subject: [PATCH] anthropic[patch]: add PDF input example to API reference (#30156) --- .../langchain_anthropic/chat_models.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/libs/partners/anthropic/langchain_anthropic/chat_models.py b/libs/partners/anthropic/langchain_anthropic/chat_models.py index 09a4710610b..85ee01ef5f6 100644 --- a/libs/partners/anthropic/langchain_anthropic/chat_models.py +++ b/libs/partners/anthropic/langchain_anthropic/chat_models.py @@ -519,6 +519,41 @@ class ChatAnthropic(BaseChatModel): "The image depicts a sunny day with a partly cloudy sky. The sky is a brilliant blue color with scattered white clouds drifting across. The lighting and cloud patterns suggest pleasant, mild weather conditions. The scene shows a grassy field or meadow with a wooden boardwalk trail leading through it, indicating an outdoor setting on a nice day well-suited for enjoying nature." + PDF input: + .. code-block:: python + + from base64 import b64encode + from langchain_anthropic import ChatAnthropic + from langchain_core.messages import HumanMessage + import requests + + url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" + data = b64encode(requests.get(url).content).decode() + + llm = ChatAnthropic(model="claude-3-5-sonnet-latest") + ai_msg = llm.invoke( + [ + HumanMessage( + [ + "Summarize this document.", + { + "type": "document", + "source": { + "type": "base64", + "data": data, + "media_type": "application/pdf", + }, + }, + ] + ) + ] + ) + ai_msg.content + + .. code-block:: python + + "This appears to be a simple document..." + Extended thinking: Claude 3.7 Sonnet supports an `extended thinking `_