docs: update docstring of the ChatAnthropic and AnthropicLLM classes (#18649)

**Description:** Update docstring of the ChatAnthropic and AnthropicLLM
classes
**Issue:** Not applicable
**Dependencies:** None
This commit is contained in:
aditya thomas 2024-03-29 04:03:54 +05:30 committed by GitHub
parent f19229c564
commit dc9e9a66db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 21 deletions

View File

@ -134,16 +134,15 @@ def _format_messages(messages: List[BaseMessage]) -> Tuple[Optional[str], List[D
class ChatAnthropic(BaseChatModel):
"""Anthropic chat model.
To use, you should have the packages ``anthropic`` and ``langchain-anthropic``
installed, and the environment variable ANTHROPIC_API_KEY set with your API key,
or pass it as a named parameter to the constructor.
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.
Example:
.. code-block:: python
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic()
model = ChatAnthropic(model='claude-3-opus-20240229')
"""
class Config:

View File

@ -139,29 +139,17 @@ class _AnthropicCommon(BaseLanguageModel):
class AnthropicLLM(LLM, _AnthropicCommon):
"""Anthropic large language models.
"""Anthropic large language model.
To use, you should have the ``anthropic`` python package installed, and the
environment variable ``ANTHROPIC_API_KEY`` set with your API key, or pass
it as a named parameter to the constructor.
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.
Example:
.. code-block:: python
import anthropic
from langchain_community.llms import Anthropic
from langchain_anthropic import AnthropicLLM
model = Anthropic(model="<model_name>", anthropic_api_key="my-api-key")
# Simplest invocation, automatically wrapped with HUMAN_PROMPT
# and AI_PROMPT.
response = model("What are the biggest risks facing humanity?")
# Or if you want to use the chat mode, build a few-shot-prompt, or
# put words in the Assistant's mouth, use HUMAN_PROMPT and AI_PROMPT:
raw_prompt = "What are the biggest risks facing humanity?"
prompt = f"{anthropic.HUMAN_PROMPT} {prompt}{anthropic.AI_PROMPT}"
response = model(prompt)
model = AnthropicLLM()
"""
class Config: