mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-08 22:15:08 +00:00
anthropic: release 0.3.17 (#31852)
This commit is contained in:
parent
7cb9388c33
commit
f88fff0b8a
@ -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"
|
||||
|
||||
|
@ -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
Loading…
Reference in New Issue
Block a user