From 97dc906a18b4de3911b933ac73a4ec161e937e48 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Thu, 2 Jan 2025 16:03:37 -0800 Subject: [PATCH] docs: add stripe toolkit (#28122) --- docs/docs/integrations/tools/stripe.ipynb | 196 ++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 docs/docs/integrations/tools/stripe.ipynb diff --git a/docs/docs/integrations/tools/stripe.ipynb b/docs/docs/integrations/tools/stripe.ipynb new file mode 100644 index 00000000000..0edc4cdd6d6 --- /dev/null +++ b/docs/docs/integrations/tools/stripe.ipynb @@ -0,0 +1,196 @@ +{ + "cells": [ + { + "cell_type": "raw", + "id": "10238e62-3465-4973-9279-606cbb7ccf16", + "metadata": {}, + "source": [ + "---\n", + "sidebar_label: Stripe\n", + "---" + ] + }, + { + "cell_type": "markdown", + "id": "a6f91f20", + "metadata": {}, + "source": [ + "# StripeAgentToolkit\n", + "\n", + "This notebook provides a quick overview for getting started with Stripe's agent toolkit.\n", + "\n", + "You can read more about `StripeAgentToolkit` in [Stripe's launch blog](https://stripe.dev/blog/adding-payments-to-your-agentic-workflows) or on the project's [PyPi page](https://pypi.org/project/stripe-agent-toolkit/).\n", + "\n", + "## Overview\n", + "\n", + "### Integration details\n", + "\n", + "| Class | Package | Serializable | [JS Support](https://github.com/stripe/agent-toolkit?tab=readme-ov-file#typescript) | Package latest |\n", + "| :--- | :--- | :---: | :---: | :---: |\n", + "| StripeAgentToolkit | [stripe-agent-toolkit](https://pypi.org/project/stripe-agent-toolkit) | ❌ | ✅ | ![PyPI - Version](https://img.shields.io/pypi/v/stripe-agent-toolkit?style=flat-square&label=%20) |\n", + "\n", + "\n", + "## Setup\n", + "\n", + "This externally-managed package is hosted out of the `stripe-agent-toolkit` project, which is managed by Stripe's team.\n", + "\n", + "You can install it, along with langgraph for the following examples, with `pip`:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "f85b4089", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip install --quiet -U langgraph stripe-agent-toolkit" + ] + }, + { + "cell_type": "markdown", + "id": "b15e9266", + "metadata": {}, + "source": [ + "### Credentials\n", + "\n", + "In addition to installing the package, you will need to configure the integration with your Stripe account's secret key, which is available in your [Stripe Dashboard](https://dashboard.stripe.com/account/apikeys)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e0b178a2-8816-40ca-b57c-ccdd86dde9c9", + "metadata": {}, + "outputs": [], + "source": [ + "import getpass\n", + "import os\n", + "\n", + "if not os.environ.get(\"STRIPE_SECRET_KEY\"):\n", + " os.environ[\"STRIPE_SECRET_KEY\"] = getpass.getpass(\"STRIPE API key:\\n\")" + ] + }, + { + "cell_type": "markdown", + "id": "bc5ab717-fd27-4c59-b912-bdd099541478", + "metadata": {}, + "source": [ + "It's also helpful (but not needed) to set up [LangSmith](https://smith.langchain.com/) for best-in-class observability:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "a6c2f136-6367-4f1f-825d-ae741e1bf281", + "metadata": {}, + "outputs": [], + "source": [ + "# os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n", + "# os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass()" + ] + }, + { + "cell_type": "markdown", + "id": "1c97218f-f366-479d-8bf7-fe9f2f6df73f", + "metadata": {}, + "source": [ + "## Instantiation\n", + "\n", + "Here we show how to create an instance of the Stripe Toolkit" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b3ddfe9-ca79-494c-a7ab-1f56d9407a64", + "metadata": {}, + "outputs": [], + "source": [ + "from stripe_agent_toolkit.crewai.toolkit import StripeAgentToolkit\n", + "\n", + "stripe_agent_toolkit = StripeAgentToolkit(\n", + " secret_key=os.getenv(\"STRIPE_SECRET_KEY\"),\n", + " configuration={\n", + " \"actions\": {\n", + " \"payment_links\": {\n", + " \"create\": True,\n", + " },\n", + " }\n", + " },\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "4f53188e", + "metadata": {}, + "source": [ + "## Agent\n", + "\n", + "Here's how to use the toolkit to create a basic agent in langgraph:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4975924e", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_anthropic import ChatAnthropic\n", + "from langgraph.prebuilt import create_react_agent\n", + "\n", + "llm = ChatAnthropic(\n", + " model=\"claude-3-5-sonnet-20240620\",\n", + ")\n", + "\n", + "langgraph_agent_executor = create_react_agent(llm, stripe_agent_toolkit.get_tools())\n", + "\n", + "input_state = {\n", + " \"messages\": \"\"\"\n", + " Create a payment link for a new product called 'test' with a price\n", + " of $100. Come up with a funny description about buy bots,\n", + " maybe a haiku.\n", + " \"\"\",\n", + "}\n", + "\n", + "output_state = langgraph_agent_executor.invoke(input_state)\n", + "\n", + "print(output_state[\"messages\"][-1].content)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}