Skip to content

Commit 0a54aed

Browse files
author
Erick Friis
authored
anthropic: pdf integration test (#29142)
1 parent 8de8519 commit 0a54aed

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

libs/partners/anthropic/poetry.lock

+15-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/partners/anthropic/pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ ruff = "^0.5"
7676

7777
[tool.poetry.group.typing.dependencies]
7878
mypy = "^1.10"
79+
types-requests = "^2.32.0.20241016"
7980

8081
[tool.poetry.group.test.dependencies.langchain-core]
8182
path = "../../core"
@@ -89,6 +90,8 @@ develop = true
8990
path = "../../core"
9091
develop = true
9192

93+
[tool.poetry.group.test_integration.dependencies]
94+
requests = "^2.32.3"
9295
[tool.poetry.group.test_integration.dependencies.langchain-core]
9396
path = "../../core"
9497
develop = true

libs/partners/anthropic/tests/integration_tests/test_chat_models.py

+28
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Test ChatAnthropic chat model."""
22

33
import json
4+
from base64 import b64encode
45
from typing import List, Optional
56

67
import pytest
8+
import requests
79
from langchain_core.callbacks import CallbackManager
810
from langchain_core.messages import (
911
AIMessage,
@@ -575,3 +577,29 @@ def test_anthropic_bind_tools_tool_choice(tool_choice: str) -> None:
575577
chat_model_with_tools = chat_model.bind_tools([GetWeather], tool_choice=tool_choice)
576578
response = chat_model_with_tools.invoke("what's the weather in ny and la")
577579
assert isinstance(response, AIMessage)
580+
581+
582+
def test_pdf_document_input() -> None:
583+
url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
584+
data = b64encode(requests.get(url).content).decode()
585+
586+
result = ChatAnthropic(model_name=MODEL_NAME).invoke( # type: ignore[call-arg]
587+
[
588+
HumanMessage(
589+
[
590+
"summarize this document",
591+
{
592+
"type": "document",
593+
"source": {
594+
"type": "base64",
595+
"data": data,
596+
"media_type": "application/pdf",
597+
},
598+
},
599+
]
600+
)
601+
]
602+
)
603+
assert isinstance(result, AIMessage)
604+
assert isinstance(result.content, str)
605+
assert len(result.content) > 0

0 commit comments

Comments
 (0)