Skip to content

Commit

Permalink
feat: Chatbot Example Use CDP Config File
Browse files Browse the repository at this point in the history
  • Loading branch information
John-peterson-coinbase committed Nov 10, 2024
1 parent 000f308 commit 5aed8c4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cdp-langchain/examples/chatbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ pip install cdp-langchain

### Set ENV Vars
- Ensure the following ENV Vars are set:
- "CDP_API_KEY_NAME"
- "CDP_API_KEY_PRIVATE_KEY"
- "OPENAI_API_KEY"
- "NETWORK_ID" (Defaults to `base-sepolia`)
- Update `./cdp_config.json` with your CDP API Key name and private key

```bash
python chatbot.py
Expand Down
4 changes: 4 additions & 0 deletions cdp-langchain/examples/chatbot/cdp_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cdp_api_key_name": "paste-your-cdp-api-key-name-here",
"cdp_api_key_private_key": "paste-your-cdp-api-key-private-key-here"
}
9 changes: 9 additions & 0 deletions cdp-langchain/examples/chatbot/chatbot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import time
import json

from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI
Expand All @@ -14,6 +15,9 @@
# Configure a file to persist the agent's CDP MPC Wallet Data.
wallet_data_file = "wallet_data.txt"

# Configure a file to hold CDP config.
cdp_config_file_path = "cdp_config.json"


def initialize_agent():
"""Initialize the agent with CDP Agentkit."""
Expand All @@ -32,6 +36,11 @@ def initialize_agent():
# If there is a persisted agentic wallet, load it and pass to the CDP Agentkit Wrapper.
values = {"cdp_wallet_data": wallet_data}

with open(os.path.expanduser(cdp_config_file_path)) as f:
cdp_config_data = json.load(f)
values["cdp_api_key_name"] = cdp_config_data.get("cdp_api_key_name")
values["cdp_api_key_private_key"] = cdp_config_data.get("cdp_api_key_private_key")

agentkit = CdpAgentkitWrapper(**values)

# persist the agent's CDP MPC Wallet Data.
Expand Down

0 comments on commit 5aed8c4

Please sign in to comment.