Skip to content

Commit

Permalink
Merge pull request #178 from valory-xyz/fix/misc
Browse files Browse the repository at this point in the history
  • Loading branch information
0xArdi authored Feb 23, 2024
2 parents 00a3ca2 + bcf1ad8 commit 71e278e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .example.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FILE_HASH_TO_TOOLS='[["bafybeiaodddyn4eruafqg5vldkkjfglj7jg76uvyi5xhi2cysktlu4w6r4",["openai-gpt-3.5-turbo-instruct","openai-gpt-3.5-turbo","openai-gpt-4"]],["bafybeiepc5v4ixwuu5m6p5stck5kf2ecgkydf6crj52i5umnl2qm5swb4i",["stabilityai-stable-diffusion-v1-5","stabilityai-stable-diffusion-xl-beta-v2-2-2","stabilityai-stable-diffusion-512-v2-1","stabilityai-stable-diffusion-768-v2-1"]],["bafybeidpbnqbruzqlq424qt3i5dcvyqmcimshjilftabnrroujmjhdmteu",["transfer-native"]],["bafybeiglhy5epaytvt5qqdx77ld23ekouli53qrf2hjyebd5xghlunidfi",["prediction-offline","prediction-online"]]]'
FILE_HASH_TO_TOOLS='[["bafybeibdcttrlgp5udygntka5fofi566pitkxhquke37ng7csvndhy4s2i",["openai-gpt-3.5-turbo-instruct","openai-gpt-3.5-turbo","openai-gpt-4"]],["bafybeiegbsq2ajxyipajac4mmxyvbt22ctwyuypuid6ziavqpndns6fsjy",["stabilityai-stable-diffusion-v1-5","stabilityai-stable-diffusion-xl-beta-v2-2-2","stabilityai-stable-diffusion-512-v2-1","stabilityai-stable-diffusion-768-v2-1"]],["bafybeihugaylajwh2fgypxatcw5qrw5qxadtrsi2h2s2246442wlvjirtm",["transfer-native"]],["bafybeiayity7o6c2yynrpe6libyak37hgf4fp7a4kjfcnqkkxwy3zkp3ie",["prediction-offline","prediction-online"]]]'
API_KEYS='[["openai","dummy_api_key"],["stabilityai","dummy_api_key"]]'
ETHEREUM_LEDGER_RPC_0=https://rpc.eu-central-2.gateway.fm/v4/gnosis/non-archival/mainnet
GNOSIS_RPC_0=https://rpc.eu-central-2.gateway.fm/v4/gnosis/non-archival/mainnet
ETHEREUM_WEBSOCKET_RPC_0=wss://rpc.eu-central-2.gateway.fm/ws/v4/gnosis/non-archival/mainnet
ETHEREUM_LEDGER_CHAIN_ID=100
ALL_PARTICIPANTS='["0x10E867Ac2Fb0Aa156ca81eF440a5cdf373bE1AaC"]'
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ Follow these instructions to have your local environment prepared to run the dem
1. Create a Poetry virtual environment and install the dependencies:

```bash
poetry run pip install openapi-core==0.13.2
poetry run pip install openapi-spec-validator==0.2.8
poetry install && poetry shell
```

Expand All @@ -71,7 +69,7 @@ Follow these instructions to have your local environment prepared to run the dem

## Run the demo

Follow the instructions below to run the AI Mech demo executing the tool in `./tools/openai_request.py`. Note that AI Mechs can be configured to work in two modes: *polling mode*, which periodically reads the chain, and *websocket mode*, which receives event updates from the chain. The default mode used by the demo is *polling*.
Follow the instructions below to run the AI Mech demo executing the tool in `./packages/valory/customs/openai_request.py`. Note that AI Mechs can be configured to work in two modes: *polling mode*, which periodically reads the chain, and *websocket mode*, which receives event updates from the chain. The default mode used by the demo is *polling*.

First, you need to configure the worker service. You need to create a `.1env` file which contains the service configuration parameters. We provide a prefilled template (`.example.env`). You will need to provide or create an [OpenAI API key](https://platform.openai.com/account/api-keys).

Expand Down Expand Up @@ -129,15 +127,15 @@ Now, you have two options to run the worker: as a standalone agent or as a servi

You can create and mint your own AI Mech that handles requests for tasks that you can define.

1. **Create a new tool.** Tools are the components that execute the Requests for AI tasks submitted on [Mech Hub](https://aimechs.autonolas.network/mech). Tools must be located in the folder `./tools` as a single Python file. Such file must contain a `run` function that accepts `kwargs` and must **always** return a string (`str`). That is, the `run` function must not raise any exception. If exceptions occur inside the function, they must be processed, and the return value must be set accordingly, for example, returning an error code.
1. **Create a new tool.** Tools are the components that execute the Requests for AI tasks submitted on [Mech Hub](https://aimechs.autonolas.network/mech). Tools are custom components and should be under the `customs` packages (ex. [valory tools](./packages/valory/customs)). Such file must contain a `run` function that accepts `kwargs` and must **always** return a tuple (`Tuple[Optional[str], Optional[Dict[str, Any]], Any, Any]`). That is, the `run` function must not raise any exception. If exceptions occur inside the function, they must be processed, and the return value must be set accordingly, for example, returning an error code.
```python
def run(**kwargs) -> str:
def run(**kwargs) -> Tuple[Optional[str], Optional[Dict[str, Any]], Any, Any]::
"""Run the task"""
# Your code here
return result # a string
return result_str, prompt_used, generated_tx, counter_callback
```
The `kwargs` are guaranteed to contain:
Expand All @@ -148,17 +146,20 @@ You can create and mint your own AI Mech that handles requests for tasks that yo
* `prompt` (`kwargs["prompt"]`): a string containing the user prompt.
* `tool` (`kwargs["tool"]`): a string specifying the (sub-)tool to be used. The `run` command must parse this input and execute the task corresponding to the particular sub-tool referenced. These sub-tools will allow the user to fine-tune the use of your tool.
2. **Upload the tool file to IPFS.** You can use the following script:
2. **Upload the tool file to IPFS.** You can push your tool to IPFS like the other packages:
```bash
mechx push-to-ipfs "tools/<your_tool>.py"
autonomy push-all
```
You should see an output similar to this:
```
IPFS file hash v1: bafybei0123456789abcdef...0
IPFS file hash v1 hex: f017012200123456789abcdef...0
Pushing: /home/ardian/vlr/mech/packages/valory/customs/openai_request
Pushed component with:
PublicId: valory/openai_request:0.1.0
Package hash: bafybeibdcttrlgp5udygntka5fofi566pitkxhquke37ng7csvndhy4s2i
```
Note down the generated hashes for your tool.
Your tool will be available on [packages.json](packages/packages.json).
3. **Configure your service.** Edit the `.env` file. The demo service has this configuration:
```bash
Expand Down
4 changes: 1 addition & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Mechs address a critical need in the agent ecosystem: the ability to outsource c

## How it works

A Mech service consists of a library of tools. These can range from something as simple as an API call to highly complex business logic. Some examples of tools can be found on [the `tools` folder](https://github.com/valory-xyz/mech/tree/main/tools) of the first operational Mech service.
A Mech service consists of a library of tools. These can range from something as simple as an API call to highly complex business logic. Some examples of tools can be found on [the `valory/customs` folder](https://github.com/valory-xyz/mech/tree/main/packages/valory/customs) of the first operational Mech service.

For instance, if an agent service needs to perform a task requiring access to an API, instead of each operator having to manage their own keys, the service can make use of a Mech tool. Agents then only need to make a request to a Mech, which gets returned in the form of a deliver event. The agent can then use the deliver event to accomplish what it set out to do. Both the request and deliver events are executed on-chain and the associated data is stored on IPFS making them easily retrievable by agents or anyone else.

Expand Down Expand Up @@ -48,8 +48,6 @@ In order to run a local demo service based on the MechKit:

```bash
git clone https://github.com/valory-xyz/mech && cd mech
poetry run pip install openapi-core==0.13.2
poetry run pip install openapi-spec-validator==0.2.8
poetry install && poetry shell

autonomy init --remote --ipfs --reset --author=your_name
Expand Down
6 changes: 3 additions & 3 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"contract/valory/hash_checkpoint/0.1.0": "bafybeianr3zy3bb464jwlwwxtk2daeeh4cefy7ihw5bfn7zrn7vjs3fyga",
"connection/valory/websocket_client/0.1.0": "bafybeiflmystocxaqblhpzqlcop2vkhsknpzjx2jomohomaxamwskeokzm",
"skill/valory/contract_subscription/0.1.0": "bafybeicyugrkx5glat4p4ezwf6i7oduh26eycfie6ftd4uxrknztzl3ik4",
"skill/valory/mech_abci/0.1.0": "bafybeib6nqbsmlsgbomld2tsyk4cjni4t7rnx7css4tmsmssmhjzm4gs74",
"skill/valory/mech_abci/0.1.0": "bafybeiahkev6ur4otoeuprgedck3pk6ob4q44lyvdkvz733ftu54zicw3i",
"skill/valory/task_submission_abci/0.1.0": "bafybeifaqewhshy4xrm7nejtmwgm6wwm6k4ps2xn4v2kckpwqsr7wblslm",
"skill/valory/task_execution/0.1.0": "bafybeienkm3nxcyqllpnndsacaq27nhgwgs4v5vyynvqkyv5uc6aojatji",
"skill/valory/websocket_client/0.1.0": "bafybeidwntmkk4b2ixq5454ycbkknclqx7a6vpn7aqpm2nw3duszqrxvta",
"skill/valory/subscription_abci/0.1.0": "bafybeidtoiyzlenxawjkyogwbfjgui2a22srdo6zbajubgg6awgha5hm4m",
"agent/valory/mech/0.1.0": "bafybeiglzfdna5o7ffazzvmd57ph4ttvubznc4itxkxxcd6njvew2x2cve",
"service/valory/mech/0.1.0": "bafybeic7toq6xpfwonqzrq7sfe2njlscz2m336djql5bsshfj3zk5ghhde"
"agent/valory/mech/0.1.0": "bafybeigileaik3lno5mb3je2tfsmep33eq43qfxtp4razjfo7mzaxzqfxa",
"service/valory/mech/0.1.0": "bafybeianvggwocwrat6w6zirab44nwpptigb6aw533zawmqxgjg6eslkdm"
},
"third_party": {
"protocol/valory/default/1.0.0": "bafybeifqcqy5hfbnd7fjv4mqdjrtujh2vx3p2xhe33y67zoxa6ph7wdpaq",
Expand Down
7 changes: 4 additions & 3 deletions packages/valory/agents/mech/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ skills:
- valory/abstract_abci:0.1.0:bafybeihljirk3d4rgvmx2nmz3p2mp27iwh2o5euce5gccwjwrpawyjzuaq
- valory/abstract_round_abci:0.1.0:bafybeigjrepaqpb3m7zunmt4hryos4vto4yyj3u6iyofdb2fotwho3bqvm
- valory/contract_subscription:0.1.0:bafybeicyugrkx5glat4p4ezwf6i7oduh26eycfie6ftd4uxrknztzl3ik4
- valory/mech_abci:0.1.0:bafybeib6nqbsmlsgbomld2tsyk4cjni4t7rnx7css4tmsmssmhjzm4gs74
- valory/mech_abci:0.1.0:bafybeiahkev6ur4otoeuprgedck3pk6ob4q44lyvdkvz733ftu54zicw3i
- valory/registration_abci:0.1.0:bafybeif3ln6eg53ebrfe6uicjew4uqp2ynyrcxkw5wi4jm3ixqv3ykte4a
- valory/reset_pause_abci:0.1.0:bafybeicm7onl72rfnn33pbvzwjpkl5gafeieyobfcnyresxz7kunjwmqea
- valory/subscription_abci:0.1.0:bafybeidtoiyzlenxawjkyogwbfjgui2a22srdo6zbajubgg6awgha5hm4m
Expand Down Expand Up @@ -185,7 +185,7 @@ models:
on_chain_service_id: ${int:1}
agent_registry_address: ${str:0x0000000000000000000000000000000000000000}
agent_id: ${int:3}
metadata_hash: ${str:null}
metadata_hash: ${str:0000000000000000000000000000000000000000000000000000000000000000}
share_tm_config_on_startup: ${bool:false}
multisend_address: ${str:0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761}
service_registry_address: ${str:0x9338b5153AE39BB89f50468E608eD9d764B755fD}
Expand All @@ -196,6 +196,7 @@ models:
profit_split_freq: ${int:1}
agent_funding_amount: ${int:200000000000000000}
minimum_agent_balance: ${int:100000000000000000}
termination_from_block: ${int:0}
mech_to_subscription: ${list:[["0x77af31De935740567Cf4fF1986D04B2c964A786a",["0x0000000000000000000000000000000000000000","1"]]]}
hash_checkpoint_address: ${str:0x694e62BDF7Ff510A4EE66662cf4866A961a31653}
setup:
Expand All @@ -217,7 +218,7 @@ models:
agent_index: ${int:0}
num_agents: ${int:4}
from_block_range: ${int:50000}
mech_to_config: ${list:[["0x77af31De935740567Cf4fF1986D04B2c964A786a",["use_dynamic_pricing","false"]]]}
mech_to_config: ${list:[["0xFf82123dFB52ab75C417195c5fDB87630145ae81",["use_dynamic_pricing","false"]]]}
timeout_limit: ${int:3}
max_block_window: ${int:500}
---
Expand Down
6 changes: 5 additions & 1 deletion packages/valory/services/mech/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeif7ia4jdlazy6745ke2k2x5yoqlwsgwr6sbztbgqtwvs3ndm2p7ba
fingerprint_ignore_patterns: []
agent: valory/mech:0.1.0:bafybeiglzfdna5o7ffazzvmd57ph4ttvubznc4itxkxxcd6njvew2x2cve
agent: valory/mech:0.1.0:bafybeigileaik3lno5mb3je2tfsmep33eq43qfxtp4razjfo7mzaxzqfxa
number_of_agents: 4
deployment:
agent:
Expand Down Expand Up @@ -48,6 +48,7 @@ type: skill
reset_period_count: ${RESET_PERIOD_COUNT:int:1000}
service_endpoint_base: ${SERVICE_ENDPOINT_BASE:str:https://dummy_service.autonolas.tech/}
use_slashing: ${USE_SLASHING:bool:false}
termination_from_block: ${TERMINATION_FROM_BLOCK:int:0}
slash_cooldown_hours: ${SLASH_COOLDOWN_HOURS:int:3}
slash_threshold_amount: ${SLASH_THRESHOLD_AMOUNT:int:10000000000000000}
light_slash_unit_amount: ${LIGHT_SLASH_UNIT_AMOUNT:int:5000000000000000}
Expand Down Expand Up @@ -83,6 +84,7 @@ type: skill
use_slashing: ${USE_SLASHING:bool:false}
slash_cooldown_hours: ${SLASH_COOLDOWN_HOURS:int:3}
slash_threshold_amount: ${SLASH_THRESHOLD_AMOUNT:int:10000000000000000}
termination_from_block: ${TERMINATION_FROM_BLOCK:int:0}
light_slash_unit_amount: ${LIGHT_SLASH_UNIT_AMOUNT:int:5000000000000000}
serious_slash_unit_amount: ${SERIOUS_SLASH_UNIT_AMOUNT:int:8000000000000000}
agent_registry_address: ${AGENT_REGISTRY_ADDRESS:str:0xE49CB081e8d96920C38aA7AB90cb0294ab4Bc8EA}
Expand All @@ -108,6 +110,7 @@ type: skill
setup: *id001
share_tm_config_on_startup: ${USE_ACN:bool:false}
tendermint_com_url: ${TENDERMINT_COM_URL:str:http://localhost:8080}
termination_from_block: ${TERMINATION_FROM_BLOCK:int:0}
tendermint_url: ${TENDERMINT_URL:str:http://localhost:26657}
tendermint_p2p_url: ${TM_P2P_ENDPOINT_NODE_0:str:node0:26656}
termination_sleep: ${TERMINATION_SLEEP:int:900}
Expand Down Expand Up @@ -143,6 +146,7 @@ type: skill
manual_gas_limit: ${MANUAL_GAS_LIMIT:int:1000000}
tendermint_com_url: ${TENDERMINT_COM_URL:str:http://localhost:8080}
tendermint_url: ${TENDERMINT_URL:str:http://localhost:26657}
termination_from_block: ${TERMINATION_FROM_BLOCK:int:0}
tendermint_p2p_url: ${TM_P2P_ENDPOINT_NODE_0:str:node0:26656}
termination_sleep: ${TERMINATION_SLEEP:int:900}
use_termination: ${USE_TERMINATION:bool:false}
Expand Down
1 change: 1 addition & 0 deletions packages/valory/skills/mech_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ models:
slash_cooldown_hours: 3
hash_checkpoint_address: '0x0000000000000000000000000000000000000000'
slash_threshold_amount: 10000000000000000
termination_from_block: 0
light_slash_unit_amount: 5000000000000000
service_owner_share: 0.1
profit_split_freq: 100
Expand Down

0 comments on commit 71e278e

Please sign in to comment.