mech-client 0.2.12__py3-none-any.whl → 0.2.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mech_client/__init__.py +1 -1
- mech_client/configs/mechs.json +8 -2
- mech_client/interact.py +29 -13
- mech_client/wss.py +22 -15
- mech_client-0.2.14.dist-info/METADATA +293 -0
- {mech_client-0.2.12.dist-info → mech_client-0.2.14.dist-info}/RECORD +9 -9
- mech_client-0.2.12.dist-info/METADATA +0 -184
- {mech_client-0.2.12.dist-info → mech_client-0.2.14.dist-info}/LICENSE +0 -0
- {mech_client-0.2.12.dist-info → mech_client-0.2.14.dist-info}/WHEEL +0 -0
- {mech_client-0.2.12.dist-info → mech_client-0.2.14.dist-info}/entry_points.txt +0 -0
mech_client/__init__.py
CHANGED
mech_client/configs/mechs.json
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"gas_limit": 100000,
|
|
14
14
|
"contract_abi_url": "https://gnosis.blockscout.com/api/v2/smart-contracts/{contract_address}",
|
|
15
|
+
"transaction_url": "https://gnosisscan.io/tx/{transaction_digest}",
|
|
15
16
|
"subgraph_url": "https://api.studio.thegraph.com/query/57238/mech/version/latest"
|
|
16
17
|
},
|
|
17
18
|
"arbitrum": {
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
},
|
|
28
29
|
"gas_limit": 100000,
|
|
29
30
|
"contract_abi_url": "https://api.arbiscan.io/api?module=contract&action=getabi&address={contract_address}",
|
|
31
|
+
"transaction_url": "https://arbiscan.io/tx/{transaction_digest}",
|
|
30
32
|
"subgraph_url": ""
|
|
31
33
|
},
|
|
32
34
|
"polygon": {
|
|
@@ -42,6 +44,7 @@
|
|
|
42
44
|
},
|
|
43
45
|
"gas_limit": 100000,
|
|
44
46
|
"contract_abi_url": "https://api.polygonscan.com/api?module=contract&action=getabi&address={contract_address}",
|
|
47
|
+
"transaction_url": "https://polygonscan.com/tx/{transaction_digest}",
|
|
45
48
|
"subgraph_url": ""
|
|
46
49
|
},
|
|
47
50
|
"base": {
|
|
@@ -57,6 +60,7 @@
|
|
|
57
60
|
},
|
|
58
61
|
"gas_limit": 100000,
|
|
59
62
|
"contract_abi_url": "https://api.basescan.org/api?module=contract&action=getabi&address={contract_address}",
|
|
63
|
+
"transaction_url": "https://basescan.org/tx/{transaction_digest}",
|
|
60
64
|
"subgraph_url": ""
|
|
61
65
|
},
|
|
62
66
|
"celo": {
|
|
@@ -66,12 +70,13 @@
|
|
|
66
70
|
"ledger_config": {
|
|
67
71
|
"address": "https://forno.celo.org",
|
|
68
72
|
"chain_id": 42220,
|
|
69
|
-
"poa_chain":
|
|
73
|
+
"poa_chain": true,
|
|
70
74
|
"default_gas_price_strategy": "eip1559",
|
|
71
75
|
"is_gas_estimation_enabled": false
|
|
72
76
|
},
|
|
73
|
-
"gas_limit":
|
|
77
|
+
"gas_limit": 250000,
|
|
74
78
|
"contract_abi_url": "https://api.celoscan.io/api?module=contract&action=getabi&address={contract_address}",
|
|
79
|
+
"transaction_url": "https://celoscan.io/tx/{transaction_digest}",
|
|
75
80
|
"subgraph_url": ""
|
|
76
81
|
},
|
|
77
82
|
"optimism": {
|
|
@@ -87,6 +92,7 @@
|
|
|
87
92
|
},
|
|
88
93
|
"gas_limit": 100000,
|
|
89
94
|
"contract_abi_url": "https://api-optimistic.etherscan.io/api?module=contract&action=getabi&address={contract_address}",
|
|
95
|
+
"transaction_url": "https://optimistic.etherscan.io/tx/{transaction_digest}",
|
|
90
96
|
"subgraph_url": ""
|
|
91
97
|
}
|
|
92
98
|
}
|
mech_client/interact.py
CHANGED
|
@@ -101,7 +101,7 @@ class LedgerConfig:
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
@dataclass
|
|
104
|
-
class MechConfig:
|
|
104
|
+
class MechConfig: # pylint: disable=too-many-instance-attributes
|
|
105
105
|
"""Mech configuration"""
|
|
106
106
|
|
|
107
107
|
agent_registry_contract: str
|
|
@@ -110,6 +110,7 @@ class MechConfig:
|
|
|
110
110
|
ledger_config: LedgerConfig
|
|
111
111
|
gas_limit: int
|
|
112
112
|
contract_abi_url: str
|
|
113
|
+
transaction_url: str
|
|
113
114
|
subgraph_url: str
|
|
114
115
|
|
|
115
116
|
def __post_init__(self) -> None:
|
|
@@ -134,6 +135,10 @@ class MechConfig:
|
|
|
134
135
|
if contract_abi_url:
|
|
135
136
|
self.contract_abi_url = contract_abi_url
|
|
136
137
|
|
|
138
|
+
transaction_url = os.getenv("MECHX_TRANSACTION_URL")
|
|
139
|
+
if transaction_url:
|
|
140
|
+
self.transaction_url = transaction_url
|
|
141
|
+
|
|
137
142
|
subgraph_url = os.getenv("MECHX_SUBGRAPH_URL")
|
|
138
143
|
if subgraph_url:
|
|
139
144
|
self.subgraph_url = subgraph_url
|
|
@@ -396,7 +401,6 @@ def send_request( # pylint: disable=too-many-arguments,too-many-locals
|
|
|
396
401
|
signed_transaction,
|
|
397
402
|
raise_on_try=True,
|
|
398
403
|
)
|
|
399
|
-
print(f"Transaction sent: https://gnosisscan.io/tx/{transaction_digest}")
|
|
400
404
|
return transaction_digest
|
|
401
405
|
except Exception as e: # pylint: disable=broad-except
|
|
402
406
|
print(
|
|
@@ -462,12 +466,16 @@ def wait_for_data_url( # pylint: disable=too-many-arguments
|
|
|
462
466
|
loop=loop,
|
|
463
467
|
)
|
|
464
468
|
)
|
|
465
|
-
mech_task = loop.create_task(
|
|
466
|
-
watch_for_data_url_from_subgraph(request_id=request_id, url=subgraph_url)
|
|
467
|
-
)
|
|
468
|
-
tasks.append(mech_task)
|
|
469
469
|
tasks.append(on_chain_task)
|
|
470
470
|
|
|
471
|
+
if subgraph_url:
|
|
472
|
+
mech_task = loop.create_task(
|
|
473
|
+
watch_for_data_url_from_subgraph(
|
|
474
|
+
request_id=request_id, url=subgraph_url
|
|
475
|
+
)
|
|
476
|
+
)
|
|
477
|
+
tasks.append(mech_task)
|
|
478
|
+
|
|
471
479
|
async def _wait_for_tasks() -> Any: # type: ignore
|
|
472
480
|
"""Wait for tasks to finish."""
|
|
473
481
|
(finished, *_), unfinished = await asyncio.wait(
|
|
@@ -476,7 +484,8 @@ def wait_for_data_url( # pylint: disable=too-many-arguments
|
|
|
476
484
|
)
|
|
477
485
|
for task in unfinished:
|
|
478
486
|
task.cancel()
|
|
479
|
-
|
|
487
|
+
if unfinished:
|
|
488
|
+
await asyncio.wait(unfinished)
|
|
480
489
|
return finished.result()
|
|
481
490
|
|
|
482
491
|
result = loop.run_until_complete(_wait_for_tasks())
|
|
@@ -564,7 +573,8 @@ def interact( # pylint: disable=too-many-arguments,too-many-locals
|
|
|
564
573
|
request_signature=request_event_signature,
|
|
565
574
|
deliver_signature=deliver_event_signature,
|
|
566
575
|
)
|
|
567
|
-
|
|
576
|
+
print("Sending request...")
|
|
577
|
+
transaction_digest = send_request(
|
|
568
578
|
crypto=crypto,
|
|
569
579
|
ledger_api=ledger_api,
|
|
570
580
|
mech_contract=mech_contract,
|
|
@@ -576,6 +586,10 @@ def interact( # pylint: disable=too-many-arguments,too-many-locals
|
|
|
576
586
|
timeout=timeout,
|
|
577
587
|
sleep=sleep,
|
|
578
588
|
)
|
|
589
|
+
transaction_url_formatted = mech_config.transaction_url.format(
|
|
590
|
+
transaction_digest=transaction_digest
|
|
591
|
+
)
|
|
592
|
+
print(f"Transaction sent: {transaction_url_formatted}")
|
|
579
593
|
print("Waiting for transaction receipt...")
|
|
580
594
|
request_id = watch_for_request_id(
|
|
581
595
|
wss=wss,
|
|
@@ -584,6 +598,7 @@ def interact( # pylint: disable=too-many-arguments,too-many-locals
|
|
|
584
598
|
request_signature=request_event_signature,
|
|
585
599
|
)
|
|
586
600
|
print(f"Created on-chain request with ID {request_id}")
|
|
601
|
+
print("Waiting for Mech response...")
|
|
587
602
|
data_url = wait_for_data_url(
|
|
588
603
|
request_id=request_id,
|
|
589
604
|
wss=wss,
|
|
@@ -594,8 +609,9 @@ def interact( # pylint: disable=too-many-arguments,too-many-locals
|
|
|
594
609
|
crypto=crypto,
|
|
595
610
|
confirmation_type=confirmation_type,
|
|
596
611
|
)
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
612
|
+
if data_url:
|
|
613
|
+
print(f"Data arrived: {data_url}")
|
|
614
|
+
data = requests.get(f"{data_url}/{request_id}").json()
|
|
615
|
+
print(f"Data from agent: {data}")
|
|
616
|
+
return data
|
|
617
|
+
return None
|
mech_client/wss.py
CHANGED
|
@@ -170,19 +170,26 @@ async def watch_for_data_url_from_wss( # pylint: disable=too-many-arguments
|
|
|
170
170
|
:rtype: Any
|
|
171
171
|
"""
|
|
172
172
|
with ThreadPoolExecutor() as executor:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
try:
|
|
174
|
+
while True:
|
|
175
|
+
msg = await loop.run_in_executor(executor=executor, func=wss.recv)
|
|
176
|
+
data = json.loads(msg)
|
|
177
|
+
tx_hash = data["params"]["result"]["transactionHash"]
|
|
178
|
+
tx_receipt = await loop.run_in_executor(
|
|
179
|
+
executor, wait_for_receipt, tx_hash, ledger_api
|
|
180
|
+
)
|
|
181
|
+
event_signature = tx_receipt["logs"][0]["topics"][0].hex()
|
|
182
|
+
if event_signature != deliver_signature:
|
|
183
|
+
continue
|
|
184
|
+
|
|
185
|
+
rich_logs = mech_contract.events.Deliver().process_receipt(tx_receipt)
|
|
186
|
+
data = cast(bytes, rich_logs[0]["args"]["data"])
|
|
187
|
+
if request_id != str(rich_logs[0]["args"]["requestId"]):
|
|
188
|
+
continue
|
|
189
|
+
return f"https://gateway.autonolas.tech/ipfs/f01701220{data.hex()}"
|
|
190
|
+
except websocket.WebSocketConnectionClosedException as e:
|
|
191
|
+
print(f"WebSocketConnectionClosedException {repr(e)}")
|
|
192
|
+
print(
|
|
193
|
+
"Error: The WSS connection was likely closed by the remote party. Please, try using another WSS provider."
|
|
179
194
|
)
|
|
180
|
-
|
|
181
|
-
if event_signature != deliver_signature:
|
|
182
|
-
continue
|
|
183
|
-
|
|
184
|
-
rich_logs = mech_contract.events.Deliver().process_receipt(tx_receipt)
|
|
185
|
-
data = cast(bytes, rich_logs[0]["args"]["data"])
|
|
186
|
-
if request_id != str(rich_logs[0]["args"]["requestId"]):
|
|
187
|
-
continue
|
|
188
|
-
return f"https://gateway.autonolas.tech/ipfs/f01701220{data.hex()}"
|
|
195
|
+
return None
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mech-client
|
|
3
|
+
Version: 0.2.14
|
|
4
|
+
Summary: Basic client to interact with a mech
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Author: David Minarsch
|
|
7
|
+
Author-email: david.minarsch@googlemail.com
|
|
8
|
+
Requires-Python: >=3.10,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Requires-Dist: asn1crypto (>=1.4.0,<1.5.0)
|
|
14
|
+
Requires-Dist: gql (>=3.4.1)
|
|
15
|
+
Requires-Dist: open-aea-cli-ipfs (>=1.53.0,<2.0.0)
|
|
16
|
+
Requires-Dist: open-aea-ledger-cosmos (>=1.53.0,<2.0.0)
|
|
17
|
+
Requires-Dist: open-aea-ledger-ethereum (>=1.53.0,<2.0.0)
|
|
18
|
+
Requires-Dist: open-aea[cli] (>=1.53.0,<2.0.0)
|
|
19
|
+
Requires-Dist: websocket-client (>=0.32.0,<1)
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# Mech Client
|
|
23
|
+
|
|
24
|
+
A basic client to interact with an AI Mech. [AI Mechs](https://github.com/valory-xyz/mech) allow users to post requests for AI tasks on-chain, and get their result delivered.
|
|
25
|
+
|
|
26
|
+
> **:warning: Warning** <br />
|
|
27
|
+
> **This is a *hacky* alpha version of the client. Don't rely on it as production software.**
|
|
28
|
+
|
|
29
|
+
## Requirements
|
|
30
|
+
|
|
31
|
+
- Python >=3.10
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
Find the latest available release on [PyPi](https://pypi.org/project/mech-client/#description).
|
|
36
|
+
|
|
37
|
+
We recommend that you create a virtual Python environment using [Poetry](https://python-poetry.org/). Set up your virtual environment as follows:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
poetry new my_project
|
|
41
|
+
cd my_project
|
|
42
|
+
poetry shell
|
|
43
|
+
poetry add mech-client
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Alternatively, you can also install the Mech Client in your local Python installation:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install mech-client
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
If you require to use the Mech Client programmatically, please see [this section](#programmatic-usage) below.
|
|
53
|
+
|
|
54
|
+
## CLI Usage
|
|
55
|
+
|
|
56
|
+
Display the available options:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
mechx --help
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
Usage: mechx [OPTIONS] COMMAND [ARGS]...
|
|
64
|
+
|
|
65
|
+
Command-line tool for interacting with mechs.
|
|
66
|
+
|
|
67
|
+
Options:
|
|
68
|
+
--version Show the version and exit.
|
|
69
|
+
--help Show this message and exit.
|
|
70
|
+
|
|
71
|
+
Commands:
|
|
72
|
+
interact Interact with a mech specifying a prompt and tool.
|
|
73
|
+
prompt-to-ipfs Upload a prompt and tool to IPFS as metadata.
|
|
74
|
+
push-to-ipfs Upload a file to IPFS.
|
|
75
|
+
to-png Convert a stability AI API's diffusion model output...
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Set up the EOA and private key
|
|
79
|
+
|
|
80
|
+
To use the Mech Client you need an EOA account and its associated private key stored in a text file `ethereum_private_key.txt`. You can set it up in two ways:
|
|
81
|
+
|
|
82
|
+
- Use any software of your choice (e.g., [Metamask](https://metamask.io/)) and copy the private key:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
echo -n YOUR_PRIVATE_KEY > ethereum_private_key.txt
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Do not include any leading or trailing spaces, tabs or newlines, or any other character in the file `ethereum_private_key.txt`.
|
|
89
|
+
|
|
90
|
+
- Alternatively, use the Open AEA command `generate-key` (you'll need to install [Open AEA](https://pypi.org/project/open-aea/) and its [Ethereum ledger plugin](https://pypi.org/project/open-aea-ledger-ethereum/)):
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
aea generate-key ethereum
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
and display the corresponding EOA:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
python -c "from web3 import Web3; print(Web3().eth.account.from_key(open('ethereum_private_key.txt').read()).address)"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The EOA you use must have enough funds to pay for the Mech requests, or alternatively, use a Nevermined subscription.
|
|
103
|
+
|
|
104
|
+
> **:warning: Warning** <br />
|
|
105
|
+
> * **If the generated EOA account is for development purposes, make sure it does not contain large amounts of funds.**
|
|
106
|
+
>
|
|
107
|
+
> * **If you store the key file in a local Git repository, we recommend that you add it to `.gitignore` in order to avoid publishing it unintentionally:**
|
|
108
|
+
>
|
|
109
|
+
> ```bash
|
|
110
|
+
> echo ethereum_private_key.txt >> .gitignore
|
|
111
|
+
> ```
|
|
112
|
+
|
|
113
|
+
### Select the mech you are going to send requests to
|
|
114
|
+
|
|
115
|
+
Mechs are deployed to several networks. Find the list of supported networks and corresponging mech addresses [here](https://github.com/valory-xyz/mech?tab=readme-ov-file#examples-of-deployed-mechs).
|
|
116
|
+
|
|
117
|
+
### Generate Mech requests
|
|
118
|
+
|
|
119
|
+
The basic usage of the Mech Client is as follows:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
mechx interact <prompt> <agent_id>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
where agent with `<agent_id>` will process `<prompt>` with the default options. Each chain has its own set of Mech agents. You can find the agent IDs for each chain on the [Mech Hub](https://aimechs.autonolas.network/registry) or on the [Mech repository](https://github.com/valory-xyz/mech?tab=readme-ov-file#examples-of-deployed-mechs).
|
|
126
|
+
|
|
127
|
+
Some useful options:
|
|
128
|
+
|
|
129
|
+
- `--key <private_key_path>`: Specifies the path of the private key. The default value is `./ethereum_private_key.txt`.
|
|
130
|
+
- `--tool <name>`: Name of the tool to process the prompt. If you are aware about the tools that are provided by an agent you can directly provide its name using this option. If not provided, it will show a list of available tools for the agent so that you can select which one you want to use:
|
|
131
|
+
|
|
132
|
+
```text
|
|
133
|
+
Select prompting tool
|
|
134
|
+
|--------------------------------------------------|
|
|
135
|
+
| ID | Tool |
|
|
136
|
+
|--------------------------------------------------|
|
|
137
|
+
| 0 | openai-text-davinci-002 |
|
|
138
|
+
| ...| ... |
|
|
139
|
+
|--------------------------------------------------|
|
|
140
|
+
Tool ID >
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
- `--chain-config <name>`: Use default chain configuration parameters (RPC, WSS, ...). [See below](#chain-configuration) for more details. Available values are
|
|
144
|
+
- `arbitrum`
|
|
145
|
+
- `base`
|
|
146
|
+
- `celo`
|
|
147
|
+
- `gnosis` (Default)
|
|
148
|
+
- `optimism`
|
|
149
|
+
- `polygon`
|
|
150
|
+
|
|
151
|
+
- `--confirm <type>`: Specify how to wait for the result of your request:
|
|
152
|
+
- `off-chain`: Wait for the result using the ACN.
|
|
153
|
+
- `on-chain`: Wait for the result using the Subgraph and the Websocket subscription (whichever arrives first).
|
|
154
|
+
- `wait-for-both` (Default): Wait for the result using both `off-chain` and `on-chain` (whichever arrives first).
|
|
155
|
+
|
|
156
|
+
### Example
|
|
157
|
+
|
|
158
|
+
Example of a request specifying a key file and tool:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
mechx interact "write a short poem" 6 --key ~/ethereum_private_key.txt --tool openai-gpt-3.5-turbo --chain-config gnosis --confirm on-chain
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
You will see an output like this:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
Chain configuration: gnosis
|
|
168
|
+
Prompt uploaded: https://gateway.autonolas.tech/ipfs/f01701220af9e4e8b4bd62d76394064f493081917bcc0b9c34a4aff60f82623b717617279
|
|
169
|
+
Transaction sent: https://gnosisscan.io/tx/0x61359f9cc6a1debb07d34ce1038f6aa30d25257c17edeb2b161741805e43e8d0
|
|
170
|
+
Waiting for transaction receipt...
|
|
171
|
+
Created on-chain request with ID 100407405856633966395081711430940962809568685031934329025999216833965518452765
|
|
172
|
+
Data arrived: https://gateway.autonolas.tech/ipfs/f01701220a462120d5bb03f406fa5ef3573df77184a20ab6343d7bade76bd321654aa7251
|
|
173
|
+
Data from agent: {'requestId': 100407405856633966395081711430940962809568685031934329025999216833965518452765, 'result': "In a world of chaos and strife,\nThere's beauty in the simplest of life.\nA gentle breeze whispers through the trees,\nAnd birds sing melodies with ease.\n\nThe sun sets in a fiery hue,\nPainting the sky in shades of blue.\nStars twinkle in the darkness above,\nGuiding us with their light and love.\n\nSo take a moment to pause and see,\nThe wonders of this world so free.\nEmbrace the joy that each day brings,\nAnd let your heart soar on gentle wings.", 'prompt': 'write a short poem', 'cost_dict': {}, 'metadata': {'model': None, 'tool': 'openai-gpt-3.5-turbo'}}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
> **:pencil2: Note** <br />
|
|
177
|
+
> **If you encounter an "Out of gas" error when executing the Mech Client, you will need to increase the gas limit, e.g.,**
|
|
178
|
+
>
|
|
179
|
+
> ```bash
|
|
180
|
+
> export MECHX_GAS_LIMIT=200000
|
|
181
|
+
> ```
|
|
182
|
+
|
|
183
|
+
### Chain configuration
|
|
184
|
+
|
|
185
|
+
Default configurations for different chains are stored in the file [configs/mechs.json](./mech_client/configs/mechs.json). If `--chain-config` parameter is not specified, the Mech Client will choose the first configuration on the JSON.
|
|
186
|
+
|
|
187
|
+
Additionally, you can override any configuration parameter by exporting any of the following environment variables:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
MECHX_CHAIN_RPC
|
|
191
|
+
MECHX_WSS_ENDPOINT
|
|
192
|
+
MECHX_GAS_LIMIT
|
|
193
|
+
MECHX_CONTRACT_ABI_URL
|
|
194
|
+
MECHX_TRANSACTION_URL
|
|
195
|
+
MECHX_SUBGRAPH_URL
|
|
196
|
+
|
|
197
|
+
MECHX_LEDGER_ADDRESS
|
|
198
|
+
MECHX_LEDGER_CHAIN_ID
|
|
199
|
+
MECHX_LEDGER_POA_CHAIN
|
|
200
|
+
MECHX_LEDGER_DEFAULT_GAS_PRICE_STRATEGY
|
|
201
|
+
MECHX_LEDGER_IS_GAS_ESTIMATION_ENABLED
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Programmatic usage
|
|
205
|
+
|
|
206
|
+
You can also use the Mech Client as a library on your Python project.
|
|
207
|
+
|
|
208
|
+
1. Set up the private key as specified [above](#set-up-the-private-key). Store the resulting key file (e.g., `ethereum_private_key.txt`) in a convenient and secure location.
|
|
209
|
+
|
|
210
|
+
2. Create Python script `my_script.py`:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
touch my_script.py
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
3. Edit `my_script.py` as follows:
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
from mech_client.interact import interact, ConfirmationType
|
|
220
|
+
|
|
221
|
+
prompt_text = 'Will Gnosis pay reach 100k cards in 2024?'
|
|
222
|
+
agent_id = 6
|
|
223
|
+
tool_name = "prediction-online"
|
|
224
|
+
chain_config = "gnosis"
|
|
225
|
+
private_key_path="ethereum_private_key.txt"
|
|
226
|
+
|
|
227
|
+
result = interact(
|
|
228
|
+
prompt=prompt_text,
|
|
229
|
+
agent_id=agent_id,
|
|
230
|
+
tool=tool_name,
|
|
231
|
+
chain_config=chain_config,
|
|
232
|
+
confirmation_type=ConfirmationType.ON_CHAIN,
|
|
233
|
+
private_key_path=private_key_path
|
|
234
|
+
)
|
|
235
|
+
print(result)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Developer installation
|
|
239
|
+
|
|
240
|
+
To setup the development environment for this project, clone the repository and run the following commands:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
poetry install
|
|
244
|
+
poetry shell
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Release guide
|
|
248
|
+
|
|
249
|
+
- Bump versions in `pyproject.toml`.`mech_client/__init__.py` and `SECURITY.md`
|
|
250
|
+
- `poetry lock`
|
|
251
|
+
- `rm -rf dist`
|
|
252
|
+
- `autonomy packages sync --update-packages`
|
|
253
|
+
- `make eject-packages`
|
|
254
|
+
- Then, create a release PR and tag the release.
|
|
255
|
+
|
|
256
|
+
## FAQ
|
|
257
|
+
|
|
258
|
+
<details>
|
|
259
|
+
|
|
260
|
+
<summary><b>On which chains are AI Mechs deployed?</b></summary>
|
|
261
|
+
|
|
262
|
+
The [Mech repository](https://github.com/valory-xyz/mech?tab=readme-ov-file#examples-of-deployed-mechs) contains the latest information on deployed Mechs.
|
|
263
|
+
|
|
264
|
+
</details>
|
|
265
|
+
|
|
266
|
+
<details>
|
|
267
|
+
|
|
268
|
+
<summary><b>Are AI Mechs deployed on testnets?</b></summary>
|
|
269
|
+
|
|
270
|
+
No. AI Mechs are currently deployed only on mainnets.
|
|
271
|
+
|
|
272
|
+
</details>
|
|
273
|
+
|
|
274
|
+
<details>
|
|
275
|
+
|
|
276
|
+
<summary><b>Where can I find the agent ID?</b></summary>
|
|
277
|
+
|
|
278
|
+
You can find the agent IDs for each chain on the [Mech Hub](https://aimechs.autonolas.network/registry) or on the [Mech repository](https://github.com/valory-xyz/mech?tab=readme-ov-file#examples-of-deployed-mechs).
|
|
279
|
+
|
|
280
|
+
</details>
|
|
281
|
+
|
|
282
|
+
<details>
|
|
283
|
+
|
|
284
|
+
<summary><b>How do I access an AI Mech on a different chain?</b></summary>
|
|
285
|
+
|
|
286
|
+
Use the `--chain-config <name>` parameter together with a valid `<agent_id>`, for example:
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
mechx interact "write a short poem" 2 --key ./ethereum_private_key.txt --tool openai-gpt-4 --chain-config celo --confirm on-chain
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
</details>
|
|
293
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
mech_client/__init__.py,sha256=
|
|
1
|
+
mech_client/__init__.py,sha256=UEdYXlGB0zRn_ifncW6eJqmz4ALKRS_Hzb-1QDeDuAg,43
|
|
2
2
|
mech_client/acn.py,sha256=Rj_jLPvJ5loDQfGbu3a_O24cJC4SwIErLceSz_zVYS8,5356
|
|
3
3
|
mech_client/cli.py,sha256=QnC3Z_vth__ZiU12chRl8q5LYDLjyjzaofB41mWlq8c,4608
|
|
4
|
-
mech_client/configs/mechs.json,sha256=
|
|
4
|
+
mech_client/configs/mechs.json,sha256=IABnne1lWi62l84Hzqh3XrP659uPKme2k32yAI0HBrg,4488
|
|
5
5
|
mech_client/helpers/__init__.py,sha256=f13zpwGDaKQUjML-5Iq66rRfzg8IS5UNK5I8gBr7w54,1028
|
|
6
6
|
mech_client/helpers/acn/README.md,sha256=WMXR2Lk0IpWjr3vpZ8cxcTHk4gwsx4wC06UPkwj9dbQ,1641
|
|
7
7
|
mech_client/helpers/acn/__init__.py,sha256=72WrGEDIuYKvlWQnTajFQ9bNrDy2sFfTYDP62he4doI,1141
|
|
@@ -30,14 +30,14 @@ mech_client/helpers/p2p_libp2p_client/README.md,sha256=6x9s6P7TdKkcvAS1wMFHXRz4a
|
|
|
30
30
|
mech_client/helpers/p2p_libp2p_client/__init__.py,sha256=-GOP3D_JnmXTDomrMLCbnRk7vRQmihIqTYvyIPzx-q4,879
|
|
31
31
|
mech_client/helpers/p2p_libp2p_client/connection.py,sha256=pvfHtI-NhgDbay1wLNit6m8InH4c0p00c3hQo0I2jwQ,27887
|
|
32
32
|
mech_client/helpers/p2p_libp2p_client/connection.yaml,sha256=giYV5FwwugD7ha9IqFHJtvs-Oz1jC5og9rpkstrTqoc,1763
|
|
33
|
-
mech_client/interact.py,sha256=
|
|
33
|
+
mech_client/interact.py,sha256=E9AW_gRMkz8fRDeQSl9Dd97X_405GodA8Xylv5ZavzQ,20189
|
|
34
34
|
mech_client/prompt_to_ipfs.py,sha256=XqSIBko15MEkpWOQNT97fRI6jNxMF5EDBDEPOJFdhyk,2533
|
|
35
35
|
mech_client/push_to_ipfs.py,sha256=IfvgaPU79N_ZmCPF9d7sPCYz2uduZH0KjT_HQ2LHXoQ,2059
|
|
36
36
|
mech_client/subgraph.py,sha256=4vY6QFyUVs15gS0SvanJbvAxb3aie07IuxQnfMMnStc,4931
|
|
37
37
|
mech_client/to_png.py,sha256=pjUcFJ63MJj_r73eqnfqCWMtlpsrj6H4ZmgvIEmRcFw,2581
|
|
38
|
-
mech_client/wss.py,sha256=
|
|
39
|
-
mech_client-0.2.
|
|
40
|
-
mech_client-0.2.
|
|
41
|
-
mech_client-0.2.
|
|
42
|
-
mech_client-0.2.
|
|
43
|
-
mech_client-0.2.
|
|
38
|
+
mech_client/wss.py,sha256=hRInQjjsyOrs8dmgBb2VpJvpNt6Tx0aEiY3OhOPQvIs,6600
|
|
39
|
+
mech_client-0.2.14.dist-info/LICENSE,sha256=mdBDB-mWKV5Cz4ejBzBiKqan6Z8zVLAh9xwM64O2FW4,11339
|
|
40
|
+
mech_client-0.2.14.dist-info/METADATA,sha256=6my3h_RVRKV97PAPvCNxrgsE00zkXfAXfhVw1G2ugdg,10572
|
|
41
|
+
mech_client-0.2.14.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
|
42
|
+
mech_client-0.2.14.dist-info/entry_points.txt,sha256=SbRMRsayzD8XfNXhgwPuXEqQsdZ5Bw9XDPnUuaDExyY,45
|
|
43
|
+
mech_client-0.2.14.dist-info/RECORD,,
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: mech-client
|
|
3
|
-
Version: 0.2.12
|
|
4
|
-
Summary: Basic client to interact with a mech
|
|
5
|
-
License: Apache-2.0
|
|
6
|
-
Author: David Minarsch
|
|
7
|
-
Author-email: david.minarsch@googlemail.com
|
|
8
|
-
Requires-Python: >=3.10,<4.0
|
|
9
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Requires-Dist: asn1crypto (>=1.4.0,<1.5.0)
|
|
14
|
-
Requires-Dist: gql (>=3.4.1)
|
|
15
|
-
Requires-Dist: open-aea-cli-ipfs (==1.50.0)
|
|
16
|
-
Requires-Dist: open-aea-ledger-cosmos (==1.50.0)
|
|
17
|
-
Requires-Dist: open-aea-ledger-ethereum (==1.50.0)
|
|
18
|
-
Requires-Dist: open-aea[cli] (==1.50.0)
|
|
19
|
-
Requires-Dist: websocket-client (>=0.32.0,<1)
|
|
20
|
-
Description-Content-Type: text/markdown
|
|
21
|
-
|
|
22
|
-
# mech-client
|
|
23
|
-
Basic client to interact with a mech
|
|
24
|
-
|
|
25
|
-
> **Warning**<br />
|
|
26
|
-
> **This is a hacky alpha version of the client - don't rely on it as production software.**
|
|
27
|
-
|
|
28
|
-
## Installation
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
pip install mech-client
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Note: If you encounter an "Out of gas" error when executing the tool, you will need to increase the gas limit by setting, e.g.,
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
export MECHX_GAS_LIMIT=200000
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## CLI:
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
Usage: mechx [OPTIONS] COMMAND [ARGS]...
|
|
44
|
-
|
|
45
|
-
Command-line tool for interacting with mechs.
|
|
46
|
-
|
|
47
|
-
Options:
|
|
48
|
-
--version Show the version and exit.
|
|
49
|
-
--help Show this message and exit.
|
|
50
|
-
|
|
51
|
-
Commands:
|
|
52
|
-
interact Interact with a mech specifying a prompt and tool.
|
|
53
|
-
prompt-to-ipfs Upload a prompt and tool to IPFS as metadata.
|
|
54
|
-
push-to-ipfs Upload a file to IPFS.
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## CLI Usage:
|
|
58
|
-
|
|
59
|
-
First, create a private key in file `ethereum_private_key.txt` with this command:
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
aea generate-key ethereum
|
|
63
|
-
```
|
|
64
|
-
Ensure the private key carries funds on Gnosis Chain.
|
|
65
|
-
|
|
66
|
-
A keyfile is just a file with your ethereum private key as a hex-string, example:
|
|
67
|
-
```
|
|
68
|
-
0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcd
|
|
69
|
-
```
|
|
70
|
-
In case you add your own, make sure you don't have any extra characters in the file, like newlines or spaces.
|
|
71
|
-
|
|
72
|
-
Second, run the following command to instruct the mech with `<prompt>` and `<agent_id>`:
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
mechx interact <prompt> <agent_id>
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
The command will prompt you with all available tools for the agent and you can select which tool you want to use
|
|
79
|
-
|
|
80
|
-
```
|
|
81
|
-
Select prompting tool
|
|
82
|
-
|--------------------------------------------------|
|
|
83
|
-
| ID | Tool |
|
|
84
|
-
|--------------------------------------------------|
|
|
85
|
-
| 0 | openai-text-davinci-002 |
|
|
86
|
-
| ...| ... |
|
|
87
|
-
|--------------------------------------------------|
|
|
88
|
-
Tool ID >
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
If you are aware about the tools that are provided by an agent you can directly provide tool as a command line argument
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
mechx interact <prompt> <agent_id> --tool <tool>
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
If you already have a funded key file on locally you can provide path the key using `--key` flag.
|
|
98
|
-
|
|
99
|
-
```bash
|
|
100
|
-
mechx interact <prompt> <agent_id> --key <key_file>
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Example output:
|
|
104
|
-
```bash
|
|
105
|
-
mechx interact "write a short poem" 3 --key ~/gnosis_key --tool openai-text-davinci-003
|
|
106
|
-
Chain configuration: gnosis
|
|
107
|
-
Prompt uploaded: https://gateway.autonolas.tech/ipfs/f01701220ad773628911d12e28f005e3f249e990d684e5dba07542259195602f9afed30bf
|
|
108
|
-
Transaction sent: https://gnosisscan.io/tx/0x0d9209e32e965a820b9e80accfcd71ea3b1174b9758dd251c2e627a60ec426a5
|
|
109
|
-
Created on-chain request with ID 111240237160304797537720810617416341148235899500021985333360197012735240803849
|
|
110
|
-
Data arrived: https://gateway.autonolas.tech/ipfs/bafybeifk2h35ncszlze7t64rpblfo45rezc33xzbya3cjiyumtaioyat3e
|
|
111
|
-
Data from agent: {'requestId': 111240237160304797537720810617416341148235899500021985333360197012735240803849, 'result': "\n\nI am brave and I'm strong\nI don't hide away my song\nI am here and I'm proud\nMy voice will be heard loud!"}
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
By default the client will wait for data to arrive from on-chain using the websocket subscription and subgraph, and off-chain using the ACN and show you the result which arrives first. You can specify the type of confirmation you want using `--confirm` flag like this
|
|
115
|
-
|
|
116
|
-
```bash
|
|
117
|
-
mechx interact "write a short poem" 3 --key ~/gnosis_key --tool openai-text-davinci-003 --confirm on-chain
|
|
118
|
-
Chain configuration: gnosis
|
|
119
|
-
Prompt uploaded: https://gateway.autonolas.tech/ipfs/f017012205e37f761221a8ba4005e91c36b94153e9432b8888ff2acae6b101dd5a5de6768
|
|
120
|
-
Transaction sent: https://gnosisscan.io/tx/0xf1ef63f617717bbb8deb09699af99aa39f10155d33796de2fd7eb61c9c1458b6
|
|
121
|
-
Created on-chain request with ID 81653153529124597849081567361606842861262371002932574194580478443414142139857
|
|
122
|
-
Data arrived: https://gateway.autonolas.tech/ipfs/f0170122069b55e077430a00f3cbc3b069347e901396f978ff160eb2b0a947872be1848b7
|
|
123
|
-
Data from agent: {'requestId': 81653153529124597849081567361606842861262371002932574194580478443414142139857, 'result': "\n\nA summer breeze, so sweet,\nA gentle reminder of summer's heat.\nThe sky so blue, no cloud in sight,\nA perfect day, a wondrous sight."}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Chain configuration
|
|
127
|
-
|
|
128
|
-
Configurations for different chains are stored in the file `configs/mechs.json`. By default, `mech interact` will choose the first configuration on the JSON. You can specify which config you want to use using the `--chain-config` flag, for example,
|
|
129
|
-
|
|
130
|
-
```bash
|
|
131
|
-
mechx interact <prompt> <agent_id> --chain-config gnosis
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Additionally, you can override any configuration parameter by exporting any of the following environment variables:
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
MECHX_CHAIN_RPC
|
|
138
|
-
MECHX_WSS_ENDPOINT
|
|
139
|
-
MECHX_GAS_LIMIT
|
|
140
|
-
MECHX_CONTRACT_ABI_URL
|
|
141
|
-
MECHX_SUBGRAPH_URL
|
|
142
|
-
|
|
143
|
-
MECHX_LEDGER_ADDRESS
|
|
144
|
-
MECHX_LEDGER_CHAIN_ID
|
|
145
|
-
MECHX_LEDGER_POA_CHAIN
|
|
146
|
-
MECHX_LEDGER_DEFAULT_GAS_PRICE_STRATEGY
|
|
147
|
-
MECHX_LEDGER_IS_GAS_ESTIMATION_ENABLED
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
## Programmatic Usage:
|
|
151
|
-
|
|
152
|
-
```python
|
|
153
|
-
from mech_client.interact import interact, ConfirmationType
|
|
154
|
-
|
|
155
|
-
prompt_text = 'Will gnosis pay reach 100k cards in 2024?'
|
|
156
|
-
agent_id = 3
|
|
157
|
-
tool_name = "prediction-online"
|
|
158
|
-
|
|
159
|
-
result = interact(
|
|
160
|
-
prompt=prompt_text,
|
|
161
|
-
agent_id=agent_id,
|
|
162
|
-
tool=tool_name,
|
|
163
|
-
confirmation_type=ConfirmationType.ON_CHAIN,
|
|
164
|
-
private_key_path='PATH_HERE'
|
|
165
|
-
)
|
|
166
|
-
print(result)
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
# Developer installation
|
|
170
|
-
To setup the development environment, run the following commands:
|
|
171
|
-
|
|
172
|
-
```bash
|
|
173
|
-
poetry install && poetry shell
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
## Release guide:
|
|
177
|
-
|
|
178
|
-
- Bump versions in `pyproject.toml`, `mech_client/__init__.py` and `SECURITY.md`
|
|
179
|
-
- `poetry lock`
|
|
180
|
-
- `rm -rf dist`
|
|
181
|
-
- `autonomy packages sync --update-packages`
|
|
182
|
-
- `make eject-packages`
|
|
183
|
-
- then create release PR and tag release
|
|
184
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|