test_pdf_tool_message() — langchain Function Reference
Architecture documentation for the test_pdf_tool_message() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD f1a469e9_a281_3da6_5dcc_b240a2bb8d66["test_pdf_tool_message()"] 971e928f_9c9b_ce7a_b93d_e762f2f5aa54["ChatModelIntegrationTests"] f1a469e9_a281_3da6_5dcc_b240a2bb8d66 -->|defined in| 971e928f_9c9b_ce7a_b93d_e762f2f5aa54 style f1a469e9_a281_3da6_5dcc_b240a2bb8d66 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/integration_tests/chat_models.py lines 2943–3025
def test_pdf_tool_message(self, model: BaseChatModel) -> None:
"""Test that the model can process `ToolMessage` objects with PDF inputs.
This test should be skipped if the model does not support messages of the
LangChain `FileContentBlock` format:
```python
ToolMessage(
content=[
{
"type": "file",
"base64": pdf_data,
"mime_type": "application/pdf",
},
],
tool_call_id="1",
name="random_pdf",
)
```
This test can be skipped by setting the `supports_pdf_tool_message` property
to `False` (see configuration below).
??? note "Configuration"
To disable this test, set `supports_pdf_tool_message` to `False` in your
test class:
```python
class TestMyChatModelIntegration(ChatModelIntegrationTests):
@property
def supports_pdf_tool_message(self) -> bool:
return False
```
??? question "Troubleshooting"
If this test fails, check that the model can correctly handle messages
with PDF content blocks in `ToolMessage` objects, specifically
base64-encoded PDFs. Otherwise, set the `supports_pdf_tool_message` property
to `False`.
"""
if not self.supports_pdf_tool_message:
pytest.skip("Model does not support PDF tool message.")
url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
pdf_data = base64.b64encode(httpx.get(url).content).decode("utf-8")
tool_message = ToolMessage(
content_blocks=[
{
"type": "file",
"base64": pdf_data,
"mime_type": "application/pdf",
},
],
tool_call_id="1",
name="random_pdf",
)
messages = [
HumanMessage(
"Get a random PDF using the tool and relay the title verbatim."
),
AIMessage(
[],
tool_calls=[
{
"type": "tool_call",
"id": "1",
"name": "random_pdf",
"args": {},
}
],
),
tool_message,
]
def random_pdf() -> str:
"""Return a random PDF."""
return ""
Domain
Subdomains
Source
Frequently Asked Questions
What does test_pdf_tool_message() do?
test_pdf_tool_message() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py.
Where is test_pdf_tool_message() defined?
test_pdf_tool_message() is defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py at line 2943.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free