Skip to main content

An AI Agent

Project description

Aser

[!Warning]
Aser does not issue any tokens!

Aser is a lightweight, self-assembling AI agent. It focuses on building interactive applications that combine AI with social content.

Installation

Install from pypi:

pip3 install aser

Clone the repository:

git clone https://github.com/AmeNetwork/aser.git
cd aser
pip3 install -r requirements.txt

Set up environment variables

Please refer to .env.example file, and create a .env file with your own settings. You can use two methods to import environment variables.

Using python-dotenv:

pip install python-dotenv

Then add the following code to your python file.

from dotenv import load_dotenv
load_dotenv()

Exporting all variables in the terminal:

export $(grep -v '^#' .env | xargs)

Examples

Create a simple AI Agent:

from aser.agent import Agent
agent=Agent(name="aser agent",model="gpt-3.5-turbo")
response=agent.chat("What is Bitcoin?")

Create Discord and Telegram AI Agent in 1 minute:

# Discord AI Agent
from aser.social.discord import DiscordClient
from aser.agent import Agent
agent=Agent(name="discord agent", description="discord agent",model="gpt-3.5-turbo")
discord_agent = DiscordClient(agent)
discord_agent.run()
# Telegram AI Agent
from aser.social.telegram import TelegramClient
from aser.agent import Agent
agent=Agent(name="telegram agent", description="telegram agent",model="gpt-3.5-turbo")
telegram_agent=TelegramClient(agent)
telegram_agent.run()

Create an AI Agent with Memory:

from aser.agent import Agent
from aser.memory import Memory
memory = Memory(type="sqlite")
agent = Agent(
    name="aser agent", model="gpt-3.5-turbo", memory=memory
)
response = agent.chat("What is Bitcoin?", uid=1)

Create an AI Agent with Knowledge:

from aser.agent import Agent
from aser.knowledge import Knowledge

knowledge = Knowledge(name="CryptoHistory", query_ns=1)
knowledge_data = [
    {
        "id": "1",
        "document": "Ethereum is a decentralized blockchain with smart contract functionality.",
        "metadata": {"founder": "Vitalik Buterin", "token": "ETH", "year": 2013},
    },
    {
        "id": "2",
        "document": "Bitcoin is a decentralized digital currency.",
        "metadata": {"founder": "Satoshi Nakamoto", "token": "BTC", "year": 2009},
    },
    {
        "id": "3",
        "document": "Binance is a cryptocurrency exchange.",
        "metadata": {"founder": "CZ", "token": "BNB", "year": 2017},
    },
]
knowledge.upsert(knowledge_data)
agent = Agent(
    name="aser agent",
    description="aser agent",
    model="gpt-3.5-turbo",
    knowledge=knowledge,
)
response = agent.chat("what is Ethereum?")

Create an AI Agent with Tools:

from aser.tools import Tools
from aser.agent import Agent
tools=Tools()
def get_btc_price():
    return "$10,0000"

tools.add(
    name="get_bitcoin_price",
    description="when user ask bitcoin price, return bitcoin price",
    parameters=None,
    function=get_btc_price,
)

agent=Agent(name="aser",model="gpt-3.5-turbo",tools=tools)

response=agent.chat("what is bitcoin price?")

Create an AI Agent with Toolkits:

from aser.tools import Tools
from aser.toolkits import erc20
from aser.agent import Agent
tools=Tools()
tools.load_toolkits([erc20])
agent=Agent(name="token agent",model="gpt-3.5-turbo")
response=agent.chat("deploy a erc20 token, name is test, symbol is tst")

Create an AI Agent with Trace:

from aser.trace import Trace
from aser.agent import Agent
trace=Trace(session=1)
agent=Agent(name="aser agent",model="gpt-3.5-turbo",trace=trace)
response=agent.chat("what is bitcoin?")

Create an AI Agent with Model Smart Contract Protocol:

from aser import Agent
from aser.mscp import Connector
from eth_account import Account
import os
from aser.mscp.chat2web3 import Chat2Web3

# Create a connector to connect to the component
component = Connector(
    "http://127.0.0.1:8545", # RPC of the component network
    "0x29a79095352a718B3D7Fe84E1F14E9F34A35598e"  # component address
)

# Get the methods of the contract
methods = component.get_methods()

#Import the private key from the environment variable
account = Account.from_key(os.getenv("EVM_PRIVATE_KEY"))

# Initialize Chat2Web3 object for handling blockchain interactions
chat2web3 = Chat2Web3(account)

# Add a method named "getUserInfoByAddress" to chat2web3
chat2web3.add(
    name="getUserInfoByAddress",
    prompt="When a user wants to get a user's name and age, it will return 2 values: one is the name, and the other is the age.",
    method=methods["getUser"],  # Use the getUser method from the contract
)

# Create an Agent instance
agent = Agent(
    name="chat2web3",  # Agent name
    model="gpt-4o",  # Specify the model to use
    chat2web3=chat2web3  # Use the previously created chat2web3 object
)

# Agent responds with final answer
response = agent.chat("What is the user's name and age?0xa0Ee7A142d267C1f36714E4a8F75612F20a79720")

print(response)

Create an AI Agent Server:

from aser.api import API
from aser.agent import Agent
agent=Agent(name="api-agent",model="gpt-3.5-turbo")
api=API(agent)
api.run()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aser-0.1.2.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aser-0.1.2-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file aser-0.1.2.tar.gz.

File metadata

  • Download URL: aser-0.1.2.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for aser-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a7b5331c34ce8d27548d13f050ac5ef2e5f8790cb339aeb6c580005aa6df38f8
MD5 31718f0fb871534eb0b84a18fc14f082
BLAKE2b-256 3e0b5ae547ec088a5aa54459ebf913cd9fac267918cf97d5411f869fefb04de4

See more details on using hashes here.

File details

Details for the file aser-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aser-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for aser-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a93faba0e6b661da54a9a15f5cc80c91f04b49e1f8ed58aba77f562ed0611f1d
MD5 61f6a1879257040156fdda05e3e303b0
BLAKE2b-256 6621ce52e8c026ee7b11af7bc372059e72f6cd5478153579ba138e927a6ed646

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page