本页还没有译文
本页 8 段还没译成한국어,下面显示的是英文原文。AnthropicLLM integration
还没翻译译自英文(docs.langchain.com)本页 8 段都还没译
Warning
You are currently on a page documenting the use of Anthropic legacy Claude 2 models as text completion models. The latest and most popular Anthropic models are chat completion models, and the text completion models have been deprecated.
You are probably looking for this page instead.
This example goes over how to use LangChain to interact with Anthropic models.
Installation
pip install -qU langchain-anthropicEnvironment setup
We'll need to get an Anthropic API key and set the ANTHROPIC_API_KEY environment variable:
import os
from getpass import getpass
if "ANTHROPIC_API_KEY" not in os.environ:
os.environ["ANTHROPIC_API_KEY"] = getpass()Usage
from langchain_anthropic import AnthropicLLM
from langchain_core.prompts import PromptTemplate
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate.from_template(template)
model = AnthropicLLM(model="claude-2.1")
chain = prompt | model
chain.invoke({"question": "What is LangChain?"})'\nLangChain is a decentralized blockchain network that leverages AI and machine learning to provide language translation services.'AI 翻译查看英文原文