mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
feat(anthropic): support opus 4.7 features (#36847)
This commit is contained in:
@@ -2313,7 +2313,9 @@ def test_effort_in_output_config() -> None:
|
||||
model="claude-opus-4-5-20251101",
|
||||
output_config={"effort": "low"},
|
||||
)
|
||||
assert model.model_kwargs["output_config"] == {"effort": "low"}
|
||||
assert model.output_config == {"effort": "low"}
|
||||
payload = model._get_request_payload("Test query")
|
||||
assert payload["output_config"]["effort"] == "low"
|
||||
|
||||
|
||||
def test_effort_priority() -> None:
|
||||
@@ -2764,3 +2766,80 @@ def test_thinking_in_params_recognizes_adaptive() -> None:
|
||||
assert not _thinking_in_params({"thinking": {"type": "disabled"}})
|
||||
assert not _thinking_in_params({"thinking": {}})
|
||||
assert not _thinking_in_params({})
|
||||
|
||||
|
||||
def test_effort_xhigh() -> None:
|
||||
"""Test that xhigh effort level is accepted and lands in output_config."""
|
||||
model = ChatAnthropic(model="claude-opus-4-6", effort="xhigh")
|
||||
assert model.effort == "xhigh"
|
||||
payload = model._get_request_payload("Test query")
|
||||
assert payload["output_config"]["effort"] == "xhigh"
|
||||
|
||||
|
||||
def test_output_config_top_level_field() -> None:
|
||||
"""Test that output_config is a top-level field, not model_kwargs."""
|
||||
model = ChatAnthropic(
|
||||
model=MODEL_NAME,
|
||||
output_config={
|
||||
"effort": "low",
|
||||
"task_budget": {"type": "tokens", "total": 50000},
|
||||
},
|
||||
)
|
||||
assert model.output_config == {
|
||||
"effort": "low",
|
||||
"task_budget": {"type": "tokens", "total": 50000},
|
||||
}
|
||||
assert "output_config" not in model.model_kwargs
|
||||
|
||||
payload = model._get_request_payload("Test query")
|
||||
assert payload["output_config"]["effort"] == "low"
|
||||
assert payload["output_config"]["task_budget"] == {"type": "tokens", "total": 50000}
|
||||
|
||||
|
||||
def test_output_config_merged_with_kwargs() -> None:
|
||||
"""Test that call-time output_config overrides field-level output_config."""
|
||||
model = ChatAnthropic(
|
||||
model=MODEL_NAME,
|
||||
output_config={"effort": "low"},
|
||||
)
|
||||
payload = model._get_request_payload(
|
||||
"Test query",
|
||||
output_config={
|
||||
"effort": "high",
|
||||
"task_budget": {"type": "tokens", "total": 50000},
|
||||
},
|
||||
)
|
||||
# Call-time kwargs override field-level
|
||||
assert payload["output_config"]["effort"] == "high"
|
||||
assert payload["output_config"]["task_budget"] == {"type": "tokens", "total": 50000}
|
||||
|
||||
|
||||
def test_task_budget_auto_appends_beta() -> None:
|
||||
"""Test that task_budget in output_config triggers beta header."""
|
||||
model = ChatAnthropic(
|
||||
model=MODEL_NAME,
|
||||
output_config={"task_budget": {"type": "tokens", "total": 128000}},
|
||||
)
|
||||
payload = model._get_request_payload("Test query")
|
||||
assert "betas" in payload
|
||||
assert "task-budgets-2026-03-13" in payload["betas"]
|
||||
|
||||
|
||||
def test_task_budget_beta_not_duplicated() -> None:
|
||||
"""Test that task_budget beta is not duplicated if already present."""
|
||||
model = ChatAnthropic(
|
||||
model=MODEL_NAME,
|
||||
betas=["task-budgets-2026-03-13"],
|
||||
output_config={"task_budget": {"type": "tokens", "total": 128000}},
|
||||
)
|
||||
payload = model._get_request_payload("Test query")
|
||||
assert payload["betas"].count("task-budgets-2026-03-13") == 1
|
||||
|
||||
|
||||
def test_no_task_budget_no_beta() -> None:
|
||||
"""Test that task_budget beta is not added when no task_budget is set."""
|
||||
model = ChatAnthropic(model=MODEL_NAME, output_config={"effort": "high"})
|
||||
payload = model._get_request_payload("Test query")
|
||||
betas = payload.get("betas")
|
||||
if betas:
|
||||
assert "task-budgets-2026-03-13" not in betas
|
||||
|
||||
Reference in New Issue
Block a user