mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
anthropic: docstrings (#23145)
Added missed docstrings. Format docstrings to the consistent format (used in the API Reference)
This commit is contained in:
@@ -231,7 +231,7 @@ def _format_messages(messages: List[BaseMessage]) -> Tuple[Optional[str], List[D
|
|||||||
|
|
||||||
|
|
||||||
class ChatAnthropic(BaseChatModel):
|
class ChatAnthropic(BaseChatModel):
|
||||||
"""Anthropic chat model integration.
|
"""Anthropic chat models.
|
||||||
|
|
||||||
See https://docs.anthropic.com/en/docs/models-overview for a list of the latest models.
|
See https://docs.anthropic.com/en/docs/models-overview for a list of the latest models.
|
||||||
|
|
||||||
@@ -1008,6 +1008,8 @@ class ChatAnthropic(BaseChatModel):
|
|||||||
|
|
||||||
|
|
||||||
class AnthropicTool(TypedDict):
|
class AnthropicTool(TypedDict):
|
||||||
|
"""Anthropic tool definition."""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
description: str
|
description: str
|
||||||
input_schema: Dict[str, Any]
|
input_schema: Dict[str, Any]
|
||||||
@@ -1016,6 +1018,7 @@ class AnthropicTool(TypedDict):
|
|||||||
def convert_to_anthropic_tool(
|
def convert_to_anthropic_tool(
|
||||||
tool: Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool],
|
tool: Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool],
|
||||||
) -> AnthropicTool:
|
) -> AnthropicTool:
|
||||||
|
"""Convert a tool-like object to an Anthropic tool definition."""
|
||||||
# already in Anthropic tool format
|
# already in Anthropic tool format
|
||||||
if isinstance(tool, dict) and all(
|
if isinstance(tool, dict) and all(
|
||||||
k in tool for k in ("name", "description", "input_schema")
|
k in tool for k in ("name", "description", "input_schema")
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ def _get_type(parameter: Dict[str, Any]) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def get_system_message(tools: List[Dict]) -> str:
|
def get_system_message(tools: List[Dict]) -> str:
|
||||||
|
"""Generate a system message that describes the available tools."""
|
||||||
tools_data: List[Dict] = [
|
tools_data: List[Dict] = [
|
||||||
{
|
{
|
||||||
"tool_name": tool["name"],
|
"tool_name": tool["name"],
|
||||||
|
|||||||
@@ -362,4 +362,6 @@ class AnthropicLLM(LLM, _AnthropicCommon):
|
|||||||
|
|
||||||
@deprecated(since="0.1.0", removal="0.3.0", alternative="AnthropicLLM")
|
@deprecated(since="0.1.0", removal="0.3.0", alternative="AnthropicLLM")
|
||||||
class Anthropic(AnthropicLLM):
|
class Anthropic(AnthropicLLM):
|
||||||
|
"""Anthropic large language model."""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -7,9 +7,14 @@ from langchain_core.pydantic_v1 import BaseModel
|
|||||||
|
|
||||||
|
|
||||||
class ToolsOutputParser(BaseGenerationOutputParser):
|
class ToolsOutputParser(BaseGenerationOutputParser):
|
||||||
|
"""Output parser for tool calls."""
|
||||||
|
|
||||||
first_tool_only: bool = False
|
first_tool_only: bool = False
|
||||||
|
"""Whether to return only the first tool call."""
|
||||||
args_only: bool = False
|
args_only: bool = False
|
||||||
|
"""Whether to return only the arguments of the tool calls."""
|
||||||
pydantic_schemas: Optional[List[Type[BaseModel]]] = None
|
pydantic_schemas: Optional[List[Type[BaseModel]]] = None
|
||||||
|
"""Pydantic schemas to parse tool calls into."""
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
extra = "forbid"
|
extra = "forbid"
|
||||||
@@ -59,6 +64,7 @@ class ToolsOutputParser(BaseGenerationOutputParser):
|
|||||||
|
|
||||||
|
|
||||||
def extract_tool_calls(content: List[dict]) -> List[ToolCall]:
|
def extract_tool_calls(content: List[dict]) -> List[ToolCall]:
|
||||||
|
"""Extract tool calls from a list of content blocks."""
|
||||||
tool_calls = []
|
tool_calls = []
|
||||||
for block in content:
|
for block in content:
|
||||||
if block["type"] != "tool_use":
|
if block["type"] != "tool_use":
|
||||||
|
|||||||
Reference in New Issue
Block a user