AINetwork Toolkit
AI Network is a layer 1 blockchain designed to accommodate large-scale AI models, utilizing a decentralized GPU network powered by the $AIN token, enriching AI-driven
NFTs
(AINFTs
).The
AINetwork Toolkit
is a set of tools for interacting with the AINetwork Blockchain. These tools allow you to transferAIN
, read and write values, create apps, and set permissions for specific paths within the blockchain database.
Installing dependencies
Before using the AINetwork Toolkit, you need to install the ain-py package. You can install it with pip:
%pip install --upgrade --quiet ain-py langchain-community
Set environmental variables
You need to set the AIN_BLOCKCHAIN_ACCOUNT_PRIVATE_KEY
environmental variable to your AIN Blockchain Account Private Key.
import os
os.environ["AIN_BLOCKCHAIN_ACCOUNT_PRIVATE_KEY"] = ""
Get AIN Blockchain private key
import os
from ain.account import Account
if os.environ.get("AIN_BLOCKCHAIN_ACCOUNT_PRIVATE_KEY", None):
account = Account(os.environ["AIN_BLOCKCHAIN_ACCOUNT_PRIVATE_KEY"])
else:
account = Account.create()
os.environ["AIN_BLOCKCHAIN_ACCOUNT_PRIVATE_KEY"] = account.private_key
print(
f"""
address: {account.address}
private_key: {account.private_key}
"""
)
# IMPORTANT: If you plan to use this account in the future, make sure to save the
# private key in a secure place. Losing access to your private key means losing
# access to your account.
address: 0x5BEB4Defa2ccc274498416Fd7Cb34235DbC122Ac
private_key: f5e2f359bb6b7836a2ac70815473d1a290c517f847d096f5effe818de8c2cf14
Initialize the AINetwork Toolkit
You can initialize the AINetwork Toolkit like this:
from langchain_community.agent_toolkits.ainetwork.toolkit import AINetworkToolkit
toolkit = AINetworkToolkit()
tools = toolkit.get_tools()
address = tools[0].interface.wallet.defaultAccount.address
Initialize the Agent with the AINetwork Toolkit
You can initialize the agent with the AINetwork Toolkit like this:
from langchain.agents import AgentType, initialize_agent
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(temperature=0)
agent = initialize_agent(
tools=tools,
llm=llm,
verbose=True,
agent=AgentType.OPENAI_FUNCTIONS,
)
Example Usage
Here are some examples of how you can use the agent with the AINetwork Toolkit: