Skip to main content

An integration package connecting AnthropicMessages and LangChain

Reason this release was yanked:

Cached input token counting incorrect, fixed in 0.2.3

Project description

langchain-anthropic

This package contains the LangChain integration for Anthropic's generative models.

Installation

pip install -U langchain-anthropic

Chat Models

Anthropic recommends using their chat models over text completions.

You can see their recommended models here.

To use, you should have an Anthropic API key configured. Initialize the model as:

from langchain_anthropic import ChatAnthropic
from langchain_core.messages import AIMessage, HumanMessage

model = ChatAnthropic(model="claude-3-opus-20240229", temperature=0, max_tokens=1024)

Define the input message

message = HumanMessage(content="What is the capital of France?")

Generate a response using the model

response = model.invoke([message])

For a more detailed walkthrough see here.

LLMs (Legacy)

You can use the Claude 2 models for text completions.

from langchain_anthropic import AnthropicLLM

model = AnthropicLLM(model="claude-2.1", temperature=0, max_tokens=1024)
response = model.invoke("The best restaurant in San Francisco is: ")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_anthropic-0.2.2.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

langchain_anthropic-0.2.2-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file langchain_anthropic-0.2.2.tar.gz.

File metadata

  • Download URL: langchain_anthropic-0.2.2.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for langchain_anthropic-0.2.2.tar.gz
Algorithm Hash digest
SHA256 fadf830b5231688e75faec015abbd22013fde2d99144c88cab585f15750b2a66
MD5 f927008c70ef060a6fc489731f5da2c6
BLAKE2b-256 8fb1a9effc7296dc65504953060ceff166bfe9e53b7ddeaa3b84c41da28051f1

See more details on using hashes here.

File details

Details for the file langchain_anthropic-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_anthropic-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 52b5fb40abb561bbb3de15a3533fcf7aa4e29ab5bfe0ca4a252fdda17cefd541
MD5 df9f48d07cdd4942be1249338808f058
BLAKE2b-256 e4cd8a0dba08e10d0761a78e96164b49950166c35a851c6aa38d55cf4324e1f4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page