From 3dfd0554115256647b1fe6f279483f298217acb4 Mon Sep 17 00:00:00 2001 From: Leonid Ganeline Date: Tue, 18 Jun 2024 19:26:45 -0700 Subject: [PATCH] anthropic: docstrings (#23145) Added missed docstrings. Format docstrings to the consistent format (used in the API Reference) --- libs/partners/anthropic/langchain_anthropic/chat_models.py | 5 ++++- libs/partners/anthropic/langchain_anthropic/experimental.py | 1 + libs/partners/anthropic/langchain_anthropic/llms.py | 2 ++ .../anthropic/langchain_anthropic/output_parsers.py | 6 ++++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/partners/anthropic/langchain_anthropic/chat_models.py b/libs/partners/anthropic/langchain_anthropic/chat_models.py index 6b3250e847..d0b279f170 100644 --- a/libs/partners/anthropic/langchain_anthropic/chat_models.py +++ b/libs/partners/anthropic/langchain_anthropic/chat_models.py @@ -231,7 +231,7 @@ def _format_messages(messages: List[BaseMessage]) -> Tuple[Optional[str], List[D 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. @@ -1008,6 +1008,8 @@ class ChatAnthropic(BaseChatModel): class AnthropicTool(TypedDict): + """Anthropic tool definition.""" + name: str description: str input_schema: Dict[str, Any] @@ -1016,6 +1018,7 @@ class AnthropicTool(TypedDict): def convert_to_anthropic_tool( tool: Union[Dict[str, Any], Type[BaseModel], Callable, BaseTool], ) -> AnthropicTool: + """Convert a tool-like object to an Anthropic tool definition.""" # already in Anthropic tool format if isinstance(tool, dict) and all( k in tool for k in ("name", "description", "input_schema") diff --git a/libs/partners/anthropic/langchain_anthropic/experimental.py b/libs/partners/anthropic/langchain_anthropic/experimental.py index 8b5c43acae..529ee2a745 100644 --- a/libs/partners/anthropic/langchain_anthropic/experimental.py +++ b/libs/partners/anthropic/langchain_anthropic/experimental.py @@ -55,6 +55,7 @@ def _get_type(parameter: Dict[str, Any]) -> str: def get_system_message(tools: List[Dict]) -> str: + """Generate a system message that describes the available tools.""" tools_data: List[Dict] = [ { "tool_name": tool["name"], diff --git a/libs/partners/anthropic/langchain_anthropic/llms.py b/libs/partners/anthropic/langchain_anthropic/llms.py index 9aed83df69..47ac9f4eb5 100644 --- a/libs/partners/anthropic/langchain_anthropic/llms.py +++ b/libs/partners/anthropic/langchain_anthropic/llms.py @@ -362,4 +362,6 @@ class AnthropicLLM(LLM, _AnthropicCommon): @deprecated(since="0.1.0", removal="0.3.0", alternative="AnthropicLLM") class Anthropic(AnthropicLLM): + """Anthropic large language model.""" + pass diff --git a/libs/partners/anthropic/langchain_anthropic/output_parsers.py b/libs/partners/anthropic/langchain_anthropic/output_parsers.py index 84840591f3..fa8d3bd419 100644 --- a/libs/partners/anthropic/langchain_anthropic/output_parsers.py +++ b/libs/partners/anthropic/langchain_anthropic/output_parsers.py @@ -7,9 +7,14 @@ from langchain_core.pydantic_v1 import BaseModel class ToolsOutputParser(BaseGenerationOutputParser): + """Output parser for tool calls.""" + first_tool_only: bool = False + """Whether to return only the first tool call.""" args_only: bool = False + """Whether to return only the arguments of the tool calls.""" pydantic_schemas: Optional[List[Type[BaseModel]]] = None + """Pydantic schemas to parse tool calls into.""" class Config: extra = "forbid" @@ -59,6 +64,7 @@ class ToolsOutputParser(BaseGenerationOutputParser): def extract_tool_calls(content: List[dict]) -> List[ToolCall]: + """Extract tool calls from a list of content blocks.""" tool_calls = [] for block in content: if block["type"] != "tool_use":