mirror of
https://github.com/hwchase17/langchain.git
synced 2025-05-29 19:18:53 +00:00
anthropic: pdf integration test (#29142)
This commit is contained in:
parent
8de8519daf
commit
0a54aedb85
16
libs/partners/anthropic/poetry.lock
generated
16
libs/partners/anthropic/poetry.lock
generated
@ -1270,6 +1270,20 @@ files = [
|
||||
{file = "tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "types-requests"
|
||||
version = "2.32.0.20241016"
|
||||
description = "Typing stubs for requests"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
files = [
|
||||
{file = "types-requests-2.32.0.20241016.tar.gz", hash = "sha256:0d9cad2f27515d0e3e3da7134a1b6f28fb97129d86b867f24d9c726452634d95"},
|
||||
{file = "types_requests-2.32.0.20241016-py3-none-any.whl", hash = "sha256:4195d62d6d3e043a4eaaf08ff8a62184584d2e8684e9d2aa178c7915a7da3747"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
urllib3 = ">=2"
|
||||
|
||||
[[package]]
|
||||
name = "typing-extensions"
|
||||
version = "4.12.2"
|
||||
@ -1343,4 +1357,4 @@ watchmedo = ["PyYAML (>=3.10)"]
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">=3.9,<4.0"
|
||||
content-hash = "c22d86d391e97dc8befa33fbd7ca674410eb318e2bef08e28284449b2a57aedf"
|
||||
content-hash = "743255e1fe91bc0e2185a1bfe1b4c6bb13f6522affe5bb35bdfda419e93736ae"
|
||||
|
@ -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"
|
||||
@ -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
|
||||
|
@ -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,
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user