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 | PromptTemplate
'\nLangChain is a decentralized blockchain network that leverages AI and machine learning to provide language translation services.'