mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-26 16:43:35 +00:00
Add needed sections to doc
This commit is contained in:
parent
dce8ed57a3
commit
0e3c1d3639
@ -75,6 +75,154 @@
|
||||
" - [Crossmint](https://github.com/goat-sdk/goat/tree/main/python/examples/by-wallet/crossmint)\n",
|
||||
"- **See all python quickstarts [here](https://github.com/goat-sdk/goat/tree/main/python/examples).**\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "abd26764",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Setup\n",
|
||||
"\n",
|
||||
"1. Install the core package and langchain adapter:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install goat-sdk goat-sdk-adapter-langchain\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"2. Install the type of wallet you want to use (e.g solana):\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install goat-sdk-wallet-solana\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"3. Install the plugins you want to use in that chain:\n",
|
||||
"\n",
|
||||
"```bash\n",
|
||||
"pip install goat-sdk-plugin-spl-token\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Instantiation\n",
|
||||
"\n",
|
||||
"Now we can instantiate our toolkit:\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"from goat_adapters.langchain import get_on_chain_tools\n",
|
||||
"from goat_wallets.solana import solana, send_solana\n",
|
||||
"from goat_plugins.spl_token import spl_token, SplTokenPluginOptions\n",
|
||||
"from goat_plugins.spl_token.tokens import SPL_TOKENS\n",
|
||||
"\n",
|
||||
"# Initialize Solana client\n",
|
||||
"client = SolanaClient(os.getenv(\"SOLANA_RPC_ENDPOINT\"))\n",
|
||||
"\n",
|
||||
"# Initialize regular Solana wallet\n",
|
||||
"keypair = Keypair.from_base58_string(os.getenv(\"SOLANA_WALLET_SEED\") or \"\")\n",
|
||||
"wallet = solana(client, keypair)\n",
|
||||
"\n",
|
||||
"tools = get_on_chain_tools(\n",
|
||||
" wallet=wallet,\n",
|
||||
" plugins=[\n",
|
||||
" send_solana(),\n",
|
||||
" spl_token(SplTokenPluginOptions(\n",
|
||||
" network=\"mainnet\", # Using devnet as specified in .env\n",
|
||||
" tokens=SPL_TOKENS\n",
|
||||
" )),\n",
|
||||
" ],\n",
|
||||
" )\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Invocation\n",
|
||||
"```python\n",
|
||||
"tools[\"get_balance\"].invoke({ \"address\": \"0x1234567890123456789012345678901234567890\" })\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## Use within an agent\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"import os\n",
|
||||
"import asyncio\n",
|
||||
"from dotenv import load_dotenv\n",
|
||||
"\n",
|
||||
"# Load environment variables\n",
|
||||
"load_dotenv()\n",
|
||||
"\n",
|
||||
"from langchain_openai import ChatOpenAI\n",
|
||||
"from langchain.agents import AgentExecutor, create_tool_calling_agent\n",
|
||||
"from langchain_core.prompts import ChatPromptTemplate\n",
|
||||
"from solana.rpc.api import Client as SolanaClient\n",
|
||||
"from solders.keypair import Keypair\n",
|
||||
"\n",
|
||||
"from goat_adapters.langchain import get_on_chain_tools\n",
|
||||
"from goat_wallets.solana import solana, send_solana\n",
|
||||
"from goat_plugins.spl_token import spl_token, SplTokenPluginOptions\n",
|
||||
"from goat_plugins.spl_token.tokens import SPL_TOKENS\n",
|
||||
"\n",
|
||||
"# Initialize Solana client\n",
|
||||
"client = SolanaClient(os.getenv(\"SOLANA_RPC_ENDPOINT\"))\n",
|
||||
"\n",
|
||||
"# Initialize regular Solana wallet\n",
|
||||
"keypair = Keypair.from_base58_string(os.getenv(\"SOLANA_WALLET_SEED\") or \"\")\n",
|
||||
"wallet = solana(client, keypair)\n",
|
||||
"\n",
|
||||
"# Initialize LLM\n",
|
||||
"llm = ChatOpenAI(model=\"gpt-4o-mini\")\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" \n",
|
||||
" # Get the prompt template\n",
|
||||
" prompt = ChatPromptTemplate.from_messages(\n",
|
||||
" [\n",
|
||||
" (\"system\", \"You are a helpful assistant\"),\n",
|
||||
" (\"placeholder\", \"{chat_history}\"),\n",
|
||||
" (\"human\", \"{input}\"),\n",
|
||||
" (\"placeholder\", \"{agent_scratchpad}\"),\n",
|
||||
" ]\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Initialize tools with Solana wallet\n",
|
||||
" tools = get_on_chain_tools(\n",
|
||||
" wallet=wallet,\n",
|
||||
" plugins=[\n",
|
||||
" send_solana(),\n",
|
||||
" spl_token(SplTokenPluginOptions(\n",
|
||||
" network=\"mainnet\", # Using devnet as specified in .env\n",
|
||||
" tokens=SPL_TOKENS\n",
|
||||
" )),\n",
|
||||
" ],\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" agent = create_tool_calling_agent(llm, tools, prompt)\n",
|
||||
" agent_executor = AgentExecutor(\n",
|
||||
" agent=agent, tools=tools, handle_parsing_errors=True, verbose=True\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" while True:\n",
|
||||
" user_input = input(\"\\nYou: \").strip()\n",
|
||||
"\n",
|
||||
" if user_input.lower() == \"quit\":\n",
|
||||
" print(\"Goodbye!\")\n",
|
||||
" break\n",
|
||||
"\n",
|
||||
" try:\n",
|
||||
" response = agent_executor.invoke(\n",
|
||||
" {\n",
|
||||
" \"input\": user_input,\n",
|
||||
" }\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" print(\"\\nAssistant:\", response[\"output\"])\n",
|
||||
" except Exception as e:\n",
|
||||
" print(\"\\nError:\", str(e))\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == \"__main__\":\n",
|
||||
" main()\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"## API reference\n",
|
||||
"\n",
|
||||
"- For a complete list of tools, see the [GOAT SDK documentation](https://github.com/goat-sdk/goat).\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
Loading…
Reference in New Issue
Block a user