StripeAgentToolkit
此筆記本提供 Stripe 代理工具組入門的快速概觀。
您可以在 Stripe 的發布部落格或專案的 PyPi 頁面上閱讀更多關於 StripeAgentToolkit
的資訊。
概觀
整合詳細資訊
類別 | 套件 | 可序列化 | JS 支援 | 最新套件 |
---|---|---|---|---|
StripeAgentToolkit | stripe-agent-toolkit | ❌ | ✅ |
設定
此外部管理的套件託管於 stripe-agent-toolkit
專案之外,該專案由 Stripe 團隊管理。
您可以透過 pip
安裝它,以及用於以下範例的 langgraph
%pip install --quiet -U langgraph stripe-agent-toolkit
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m A new release of pip is available: [0m[31;49m24.2[0m[39;49m -> [0m[32;49m24.3.1[0m
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m To update, run: [0m[32;49mpip install --upgrade pip[0m
Note: you may need to restart the kernel to use updated packages.
憑證
除了安裝套件外,您還需要使用您的 Stripe 帳戶的密鑰設定整合,該密鑰可在您的 Stripe 儀表板中找到。
import getpass
import os
if not os.environ.get("STRIPE_SECRET_KEY"):
os.environ["STRIPE_SECRET_KEY"] = getpass.getpass("STRIPE API key:\n")
設定 LangSmith 以獲得最佳可觀察性也很有幫助(但非必要)
# os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()
例項化
此處我們示範如何建立 Stripe 工具組的例項
from stripe_agent_toolkit.crewai.toolkit import StripeAgentToolkit
stripe_agent_toolkit = StripeAgentToolkit(
secret_key=os.getenv("STRIPE_SECRET_KEY"),
configuration={
"actions": {
"payment_links": {
"create": True,
},
}
},
)
代理程式
以下說明如何使用工具組在 langgraph 中建立基本代理程式
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
llm = ChatAnthropic(
model="claude-3-5-sonnet-20240620",
)
langgraph_agent_executor = create_react_agent(llm, stripe_agent_toolkit.get_tools())
input_state = {
"messages": """
Create a payment link for a new product called 'test' with a price
of $100. Come up with a funny description about buy bots,
maybe a haiku.
""",
}
output_state = langgraph_agent_executor.invoke(input_state)
print(output_state["messages"][-1].content)
API 參考:ChatAnthropic | create_react_agent