Skip to content

Commit

Permalink
anthropic: pdf integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis committed Jan 10, 2025
1 parent fa6f08f commit 6dabdda
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
16 changes: 15 additions & 1 deletion libs/partners/anthropic/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions libs/partners/anthropic/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ ruff = "^0.5"

[tool.poetry.group.typing.dependencies]
mypy = "^1.10"
types-requests = "^2.32.0.20241016"

[tool.poetry.group.test.dependencies.langchain-core]
path = "../../core"
Expand All @@ -89,6 +90,8 @@ develop = true
path = "../../core"
develop = true

[tool.poetry.group.test_integration.dependencies]
requests = "^2.32.3"
[tool.poetry.group.test_integration.dependencies.langchain-core]
path = "../../core"
develop = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Test ChatAnthropic chat model."""

import json
from base64 import b64encode
from typing import List, Optional

import pytest
import requests
from langchain_core.callbacks import CallbackManager
from langchain_core.messages import (
AIMessage,
Expand Down Expand Up @@ -575,3 +577,29 @@ def test_anthropic_bind_tools_tool_choice(tool_choice: str) -> None:
chat_model_with_tools = chat_model.bind_tools([GetWeather], tool_choice=tool_choice)
response = chat_model_with_tools.invoke("what's the weather in ny and la")
assert isinstance(response, AIMessage)


def test_pdf_document_input() -> None:
url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
data = b64encode(requests.get(url).content).decode()

result = ChatAnthropic(model_name=MODEL_NAME).invoke( # type: ignore[call-arg]
[
HumanMessage(
[
"summarize this document",
{
"type": "document",
"source": {
"type": "base64",
"data": data,
"media_type": "application/pdf",
},
},
]
)
]
)
assert isinstance(result, AIMessage)
assert isinstance(result.content, str)
assert len(result.content) > 0

0 comments on commit 6dabdda

Please sign in to comment.