style: some cleanup (#33857)

This commit is contained in:
Mason Daugherty
2025-11-06 23:50:46 -05:00
committed by GitHub
parent d40e340479
commit e023201d42
79 changed files with 662 additions and 531 deletions

View File

@@ -91,8 +91,11 @@ class AnthropicTool(TypedDict):
"""Anthropic tool definition."""
name: str
input_schema: dict[str, Any]
description: NotRequired[str]
cache_control: NotRequired[dict[str, str]]
@@ -2189,11 +2192,11 @@ class ChatAnthropic(BaseChatModel):
Args:
schema: The output schema. Can be passed in as:
- an Anthropic tool schema,
- an OpenAI function/tool schema,
- a JSON Schema,
- a `TypedDict` class,
- or a Pydantic class.
- An Anthropic tool schema,
- An OpenAI function/tool schema,
- A JSON Schema,
- A `TypedDict` class,
- Or a Pydantic class.
If `schema` is a Pydantic class then the model output will be a
Pydantic instance of that class, and the model-generated fields will be
@@ -2204,11 +2207,15 @@ class ChatAnthropic(BaseChatModel):
more on how to properly specify types and descriptions of schema fields
when specifying a Pydantic or `TypedDict` class.
include_raw:
If `False` then only the parsed structured output is returned. If
an error occurs during model output parsing it will be raised. If `True`
then both the raw model response (a `BaseMessage`) and the parsed model
response will be returned. If an error occurs during output parsing it
will be caught and returned as well.
If `False` then only the parsed structured output is returned.
If an error occurs during model output parsing it will be raised.
If `True` then both the raw model response (a `BaseMessage`) and the
parsed model response will be returned.
If an error occurs during output parsing it will be caught and returned
as well.
The final output is always a `dict` with keys `'raw'`, `'parsed'`, and
`'parsing_error'`.

View File

@@ -1,4 +1,4 @@
"""Anthropic LLM wrapper. Chat models are in chat_models.py."""
"""Anthropic LLM wrapper. Chat models are in `chat_models.py`."""
from __future__ import annotations
@@ -23,8 +23,10 @@ from typing_extensions import Self
class _AnthropicCommon(BaseLanguageModel):
client: Any = None #: :meta private:
async_client: Any = None #: :meta private:
client: Any = None
async_client: Any = None
model: str = Field(default="claude-sonnet-4-5", alias="model_name")
"""Model name to use."""
@@ -70,8 +72,11 @@ class _AnthropicCommon(BaseLanguageModel):
"""Automatically read from env var `ANTHROPIC_API_KEY` if not provided."""
HUMAN_PROMPT: str | None = None
AI_PROMPT: str | None = None
count_tokens: Callable[[str], int] | None = None
model_kwargs: dict[str, Any] = Field(default_factory=dict)
@model_validator(mode="before")
@@ -127,7 +132,7 @@ class _AnthropicCommon(BaseLanguageModel):
class AnthropicLLM(LLM, _AnthropicCommon):
"""Anthropic large language model.
"""Anthropic text completion large language model (legacy LLM).
To use, you should have the environment variable `ANTHROPIC_API_KEY`
set with your API key, or pass it as a named parameter to the constructor.
@@ -136,7 +141,7 @@ class AnthropicLLM(LLM, _AnthropicCommon):
```python
from langchain_anthropic import AnthropicLLM
model = AnthropicLLM()
model = AnthropicLLM(model="claude-sonnet-4-5")
```
"""

View File

@@ -3,18 +3,19 @@ requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
authors = []
name = "langchain-anthropic"
description = "Integration package connecting Claude (Anthropic) APIs and LangChain"
license = { text = "MIT" }
readme = "README.md"
authors = []
version = "1.0.1"
requires-python = ">=3.10.0,<4.0.0"
dependencies = [
"anthropic>=0.69.0,<1.0.0",
"langchain-core>=1.0.0,<2.0.0",
"pydantic>=2.7.4,<3.0.0",
]
name = "langchain-anthropic"
version = "1.0.1"
description = "Integration package connecting Claude (Anthropic) APIs and LangChain"
readme = "README.md"
[project.urls]
Homepage = "https://docs.langchain.com/oss/python/integrations/providers/anthropic"