anthropic: release 0.3.17 (#31852)

This commit is contained in:
ccurme 2025-07-03 13:18:43 -04:00 committed by GitHub
parent 7cb9388c33
commit f88fff0b8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 1271 additions and 1170 deletions

View File

@ -7,12 +7,12 @@ authors = []
license = { text = "MIT" }
requires-python = ">=3.9"
dependencies = [
"anthropic<1,>=0.52.0",
"langchain-core<1.0.0,>=0.3.66",
"anthropic<1,>=0.57.0",
"langchain-core<1.0.0,>=0.3.68",
"pydantic<3.0.0,>=2.7.4",
]
name = "langchain-anthropic"
version = "0.3.16"
version = "0.3.17"
description = "An integration package connecting AnthropicMessages and LangChain"
readme = "README.md"

View File

@ -1085,6 +1085,106 @@ def test_files_api_pdf(block_format: str) -> None:
_ = llm.invoke([input_message])
def test_search_result_tool_message() -> None:
"""Test that we can pass a search result tool message to the model."""
llm = ChatAnthropic(
model="claude-3-5-haiku-latest",
betas=["search-results-2025-06-09"],
)
@tool
def retrieval_tool(query: str) -> list[dict]:
"""Retrieve information from a knowledge base."""
return [
{
"type": "search_result",
"title": "Leave policy",
"source": "HR Leave Policy 2025",
"citations": {"enabled": True},
"content": [
{
"type": "text",
"text": (
"To request vacation days, submit a leave request form "
"through the HR portal. Approval will be sent by email."
),
}
],
}
]
tool_call = {
"type": "tool_call",
"name": "retrieval_tool",
"args": {"query": "vacation days request process"},
"id": "toolu_abc123",
}
tool_message = retrieval_tool.invoke(tool_call)
assert isinstance(tool_message, ToolMessage)
assert isinstance(tool_message.content, list)
messages = [
HumanMessage("How do I request vacation days?"),
AIMessage(
[{"type": "text", "text": "Let me look that up for you."}],
tool_calls=[tool_call],
),
tool_message,
]
result = llm.invoke(messages)
assert isinstance(result, AIMessage)
assert isinstance(result.content, list)
assert any("citations" in block for block in result.content)
def test_search_result_top_level() -> None:
llm = ChatAnthropic(
model="claude-3-5-haiku-latest",
betas=["search-results-2025-06-09"],
)
input_message = HumanMessage(
[
{
"type": "search_result",
"title": "Leave policy",
"source": "HR Leave Policy 2025 - page 1",
"citations": {"enabled": True},
"content": [
{
"type": "text",
"text": (
"To request vacation days, submit a leave request form "
"through the HR portal. Approval will be sent by email."
),
}
],
},
{
"type": "search_result",
"title": "Leave policy",
"source": "HR Leave Policy 2025 - page 2",
"citations": {"enabled": True},
"content": [
{
"type": "text",
"text": "Managers have 3 days to approve a request.",
}
],
},
{
"type": "text",
"text": "How do I request vacation days?",
},
]
)
result = llm.invoke([input_message])
assert isinstance(result, AIMessage)
assert isinstance(result.content, list)
assert any("citations" in block for block in result.content)
def test_async_shared_client() -> None:
llm = ChatAnthropic(model="claude-3-5-haiku-latest")
llm._async_client # Instantiates lazily

File diff suppressed because it is too large Load Diff