test_pdf_inputs() — langchain Function Reference
Architecture documentation for the test_pdf_inputs() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 52e8ff5d_3fd7_279c_6907_c4805cbd2b5f["test_pdf_inputs()"] 971e928f_9c9b_ce7a_b93d_e762f2f5aa54["ChatModelIntegrationTests"] 52e8ff5d_3fd7_279c_6907_c4805cbd2b5f -->|defined in| 971e928f_9c9b_ce7a_b93d_e762f2f5aa54 style 52e8ff5d_3fd7_279c_6907_c4805cbd2b5f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/standard-tests/langchain_tests/integration_tests/chat_models.py lines 2533–2619
def test_pdf_inputs(self, model: BaseChatModel) -> None:
"""Test that the model can process PDF inputs.
This test should be skipped (see configuration below) if the model does not
support PDF inputs. These will take the shape of the LangChain
`FileContentBlock`:
```python
{
"type": "image",
"base64": "<base64 image data>",
"mime_type": "application/pdf",
}
```
Furthermore, for backward-compatibility, we must also support OpenAI chat
completions file content blocks:
```python
(
{
"type": "file",
"file": {
"filename": "test_file.pdf",
"file_data": f"data:application/pdf;base64,{pdf_data}",
},
},
)
```
??? note "Configuration"
To disable this test, set `supports_pdf_inputs` to `False` in your
test class:
```python
class TestMyChatModelIntegration(ChatModelIntegrationTests):
@property
def supports_pdf_inputs(self) -> bool:
return False
```
??? question "Troubleshooting"
If this test fails, check that the model can correctly handle messages
with pdf content blocks, including base64-encoded files. Otherwise, set
the `supports_pdf_inputs` property to `False`.
"""
if not self.supports_pdf_inputs:
pytest.skip("Model does not support PDF inputs.")
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")
message = HumanMessage(
[
{
"type": "text",
"text": "Summarize this document:",
},
{
"type": "file",
"base64": pdf_data,
"mime_type": "application/pdf",
},
]
)
_ = model.invoke([message])
# Test OpenAI Chat Completions format
message = HumanMessage(
[
{
"type": "text",
"text": "Summarize this document:",
},
{
"type": "file",
"file": {
"filename": "test_file.pdf",
Domain
Subdomains
Source
Frequently Asked Questions
What does test_pdf_inputs() do?
test_pdf_inputs() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py.
Where is test_pdf_inputs() defined?
test_pdf_inputs() is defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py at line 2533.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free