Anthropic模型交互。
安装
环境配置
我们需要获取Anthropic API密钥并设置ANTHROPIC_API_KEY环境变量:
使用方法
官方原文:src/oss/python/integrations/llms/anthropic.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
使用 LangChain Python 集成 AnthropicLLM。
Anthropic模型交互。
pip install -qU langchain-anthropic
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?"})
'\nLangChain is a decentralized blockchain network that leverages AI and machine learning to provide language translation services.'
官方原文:src/oss/python/integrations/llms/anthropic.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。