anthropic[patch]: add PDF input example to API reference (#30156)

This commit is contained in:
ccurme 2025-03-07 09:19:08 -05:00 committed by GitHub
parent 5c7440c201
commit 230876a7c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 <https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking>`_