AnthropicLLM 硕士
谨慎
此示例介绍了如何使用 LangChain 与Anthropic模型。
安装
%pip install -qU langchain-anthropic
环境设置
我们需要获取 Anthropic API 密钥并将ANTHROPIC_API_KEY环境变量:
import os
from getpass import getpass
if "ANTHROPIC_API_KEY" not in os.environ:
os.environ["ANTHROPIC_API_KEY"] = getpass()
用法
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?"})
API 参考:AnthropicLLM | 提示模板
'\nLangChain is a decentralized blockchain network that leverages AI and machine learning to provide language translation services.'