mech-client 0.2.21__py3-none-any.whl → 0.4.0__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/abis/BalanceTrackerFixedPriceNative.json +503 -0
- mech_client/abis/BalanceTrackerFixedPriceToken.json +502 -0
- mech_client/abis/BalanceTrackerNvmSubscriptionNative.json +672 -0
- mech_client/abis/BalanceTrackerNvmSubscriptionToken.json +660 -0
- mech_client/abis/IERC1155.json +295 -0
- mech_client/abis/IMech.json +165 -0
- mech_client/abis/IToken.json +880 -0
- mech_client/abis/MechMarketplace.json +1281 -0
- mech_client/cli.py +74 -19
- mech_client/configs/mechs.json +18 -6
- mech_client/fetch_ipfs_hash.py +88 -0
- mech_client/helpers/__init__.py +13 -3
- mech_client/interact.py +24 -2
- mech_client/marketplace_interact.py +883 -0
- mech_client/wss.py +89 -0
- {mech_client-0.2.21.dist-info → mech_client-0.4.0.dist-info}/METADATA +48 -5
- {mech_client-0.2.21.dist-info → mech_client-0.4.0.dist-info}/RECORD +21 -11
- {mech_client-0.2.21.dist-info → mech_client-0.4.0.dist-info}/LICENSE +0 -0
- {mech_client-0.2.21.dist-info → mech_client-0.4.0.dist-info}/WHEEL +0 -0
- {mech_client-0.2.21.dist-info → mech_client-0.4.0.dist-info}/entry_points.txt +0 -0
mech_client/cli.py
CHANGED
|
@@ -27,6 +27,9 @@ from tabulate import tabulate # type: ignore
|
|
|
27
27
|
from mech_client import __version__
|
|
28
28
|
from mech_client.interact import ConfirmationType
|
|
29
29
|
from mech_client.interact import interact as interact_
|
|
30
|
+
from mech_client.marketplace_interact import (
|
|
31
|
+
marketplace_interact as marketplace_interact_,
|
|
32
|
+
)
|
|
30
33
|
from mech_client.mech_tool_management import (
|
|
31
34
|
get_tool_description,
|
|
32
35
|
get_tool_io_schema,
|
|
@@ -45,7 +48,22 @@ def cli() -> None:
|
|
|
45
48
|
|
|
46
49
|
@click.command()
|
|
47
50
|
@click.argument("prompt")
|
|
48
|
-
@click.
|
|
51
|
+
@click.option("--agent_id", type=int, help="Id of the agent to be used")
|
|
52
|
+
@click.option(
|
|
53
|
+
"--priority-mech",
|
|
54
|
+
type=str,
|
|
55
|
+
help="Priority Mech to be used for Marketplace Requests",
|
|
56
|
+
)
|
|
57
|
+
@click.option(
|
|
58
|
+
"--use-prepaid",
|
|
59
|
+
type=bool,
|
|
60
|
+
help="Uses the prepaid model for marketplace requests",
|
|
61
|
+
)
|
|
62
|
+
@click.option(
|
|
63
|
+
"--use-offchain",
|
|
64
|
+
type=bool,
|
|
65
|
+
help="Uses the offchain model for marketplace requests",
|
|
66
|
+
)
|
|
49
67
|
@click.option(
|
|
50
68
|
"--key",
|
|
51
69
|
type=click.Path(exists=True, file_okay=True, dir_okay=False),
|
|
@@ -90,9 +108,12 @@ def cli() -> None:
|
|
|
90
108
|
type=str,
|
|
91
109
|
help="Id of the mech's chain configuration (stored configs/mechs.json)",
|
|
92
110
|
)
|
|
93
|
-
def interact( # pylint: disable=too-many-arguments
|
|
111
|
+
def interact( # pylint: disable=too-many-arguments,too-many-locals
|
|
94
112
|
prompt: str,
|
|
95
113
|
agent_id: int,
|
|
114
|
+
priority_mech: str,
|
|
115
|
+
use_prepaid: bool,
|
|
116
|
+
use_offchain: bool,
|
|
96
117
|
key: Optional[str],
|
|
97
118
|
tool: Optional[str],
|
|
98
119
|
extra_attribute: Optional[List[str]] = None,
|
|
@@ -110,23 +131,57 @@ def interact( # pylint: disable=too-many-arguments
|
|
|
110
131
|
k, v = pair.split("=")
|
|
111
132
|
extra_attributes_dict[k] = v
|
|
112
133
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
use_offchain = use_offchain or False
|
|
135
|
+
use_prepaid = use_prepaid or use_offchain
|
|
136
|
+
|
|
137
|
+
if agent_id is None:
|
|
138
|
+
marketplace_interact_(
|
|
139
|
+
prompt=prompt,
|
|
140
|
+
priority_mech=priority_mech,
|
|
141
|
+
use_prepaid=use_prepaid,
|
|
142
|
+
use_offchain=use_offchain,
|
|
143
|
+
private_key_path=key,
|
|
144
|
+
tool=tool,
|
|
145
|
+
extra_attributes=extra_attributes_dict,
|
|
146
|
+
confirmation_type=(
|
|
147
|
+
ConfirmationType(confirm)
|
|
148
|
+
if confirm is not None
|
|
149
|
+
else ConfirmationType.WAIT_FOR_BOTH
|
|
150
|
+
),
|
|
151
|
+
retries=retries,
|
|
152
|
+
timeout=timeout,
|
|
153
|
+
sleep=sleep,
|
|
154
|
+
chain_config=chain_config,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
else:
|
|
158
|
+
if use_prepaid:
|
|
159
|
+
raise Exception(
|
|
160
|
+
"Prepaid model can only be used for marketplace requests"
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
if use_offchain:
|
|
164
|
+
raise Exception(
|
|
165
|
+
"Offchain model can only be used for marketplace requests"
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
interact_(
|
|
169
|
+
prompt=prompt,
|
|
170
|
+
agent_id=agent_id,
|
|
171
|
+
private_key_path=key,
|
|
172
|
+
tool=tool,
|
|
173
|
+
extra_attributes=extra_attributes_dict,
|
|
174
|
+
confirmation_type=(
|
|
175
|
+
ConfirmationType(confirm)
|
|
176
|
+
if confirm is not None
|
|
177
|
+
else ConfirmationType.WAIT_FOR_BOTH
|
|
178
|
+
),
|
|
179
|
+
retries=retries,
|
|
180
|
+
timeout=timeout,
|
|
181
|
+
sleep=sleep,
|
|
182
|
+
chain_config=chain_config,
|
|
183
|
+
)
|
|
184
|
+
except (ValueError, FileNotFoundError, Exception) as e:
|
|
130
185
|
raise click.ClickException(str(e)) from e
|
|
131
186
|
|
|
132
187
|
|
mech_client/configs/mechs.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"gnosis": {
|
|
3
3
|
"agent_registry_contract": "0xE49CB081e8d96920C38aA7AB90cb0294ab4Bc8EA",
|
|
4
|
+
"service_registry_contract": "0x9338b5153AE39BB89f50468E608eD9d764B755fD",
|
|
5
|
+
"mech_marketplace_contract": "0x735FAAb1c4Ec41128c367AFb5c3baC73509f70bB",
|
|
4
6
|
"rpc_url": "https://rpc.eu-central-2.gateway.fm/v4/gnosis/non-archival/mainnet",
|
|
5
|
-
"wss_endpoint": "wss://rpc.
|
|
7
|
+
"wss_endpoint": "wss://rpc.gnosischain.com/wss",
|
|
6
8
|
"ledger_config": {
|
|
7
9
|
"address": "https://rpc.eu-central-2.gateway.fm/v4/gnosis/non-archival/mainnet",
|
|
8
10
|
"chain_id": 100,
|
|
@@ -10,14 +12,16 @@
|
|
|
10
12
|
"default_gas_price_strategy": "eip1559",
|
|
11
13
|
"is_gas_estimation_enabled": false
|
|
12
14
|
},
|
|
13
|
-
"gas_limit":
|
|
15
|
+
"gas_limit": 500000,
|
|
14
16
|
"price": 10000000000000000,
|
|
15
|
-
"contract_abi_url": "https://
|
|
17
|
+
"contract_abi_url": "https://api.gnosisscan.io/api?module=contract&action=getabi&address={contract_address}&apikey={api_key}",
|
|
16
18
|
"transaction_url": "https://gnosisscan.io/tx/{transaction_digest}",
|
|
17
19
|
"subgraph_url": "https://api.studio.thegraph.com/query/57238/mech/version/latest"
|
|
18
20
|
},
|
|
19
21
|
"arbitrum": {
|
|
20
22
|
"agent_registry_contract": "0xa4799B083E0068732456EF45ff9fe5c683658327",
|
|
23
|
+
"service_registry_contract": "0xE3607b00E75f6405248323A9417ff6b39B244b50",
|
|
24
|
+
"mech_marketplace_contract": "0x0000000000000000000000000000000000000000",
|
|
21
25
|
"rpc_url": "https://arbitrum.llamarpc.com",
|
|
22
26
|
"wss_endpoint": "wss://arbitrum.gateway.tenderly.co",
|
|
23
27
|
"ledger_config": {
|
|
@@ -35,6 +39,8 @@
|
|
|
35
39
|
},
|
|
36
40
|
"polygon": {
|
|
37
41
|
"agent_registry_contract": "0x984cf72FDe8B5aA910e9e508aC5e007ae5BDcC9C",
|
|
42
|
+
"service_registry_contract": "0xE3607b00E75f6405248323A9417ff6b39B244b50",
|
|
43
|
+
"mech_marketplace_contract": "0x0000000000000000000000000000000000000000",
|
|
38
44
|
"rpc_url": "https://polygon-bor-rpc.publicnode.com",
|
|
39
45
|
"wss_endpoint": "wss://polygon.gateway.tenderly.co",
|
|
40
46
|
"ledger_config": {
|
|
@@ -52,6 +58,8 @@
|
|
|
52
58
|
},
|
|
53
59
|
"base": {
|
|
54
60
|
"agent_registry_contract": "0x88DE734655184a09B70700aE4F72364d1ad23728",
|
|
61
|
+
"service_registry_contract": "0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE",
|
|
62
|
+
"mech_marketplace_contract": "0xf24eE42edA0fc9b33B7D41B06Ee8ccD2Ef7C5020",
|
|
55
63
|
"rpc_url": "https://base.llamarpc.com",
|
|
56
64
|
"wss_endpoint": "wss://base.gateway.tenderly.co",
|
|
57
65
|
"ledger_config": {
|
|
@@ -61,7 +69,7 @@
|
|
|
61
69
|
"default_gas_price_strategy": "eip1559",
|
|
62
70
|
"is_gas_estimation_enabled": false
|
|
63
71
|
},
|
|
64
|
-
"gas_limit":
|
|
72
|
+
"gas_limit": 500000,
|
|
65
73
|
"price": 3000000000000,
|
|
66
74
|
"contract_abi_url": "https://api.basescan.org/api?module=contract&action=getabi&address={contract_address}&apikey={api_key}",
|
|
67
75
|
"transaction_url": "https://basescan.org/tx/{transaction_digest}",
|
|
@@ -69,6 +77,8 @@
|
|
|
69
77
|
},
|
|
70
78
|
"celo": {
|
|
71
79
|
"agent_registry_contract": "0xE49CB081e8d96920C38aA7AB90cb0294ab4Bc8EA",
|
|
80
|
+
"service_registry_contract": "0xE3607b00E75f6405248323A9417ff6b39B244b50",
|
|
81
|
+
"mech_marketplace_contract": "0x0000000000000000000000000000000000000000",
|
|
72
82
|
"rpc_url": "https://forno.celo.org",
|
|
73
83
|
"wss_endpoint": "wss://forno.celo.org/ws",
|
|
74
84
|
"ledger_config": {
|
|
@@ -80,12 +90,14 @@
|
|
|
80
90
|
},
|
|
81
91
|
"gas_limit": 250000,
|
|
82
92
|
"price": 10000000000000000,
|
|
83
|
-
"contract_abi_url": "https://api.celoscan.io/api?module=contract&action=getabi&address={contract_address}
|
|
93
|
+
"contract_abi_url": "https://api.celoscan.io/api?module=contract&action=getabi&address={contract_address}",
|
|
84
94
|
"transaction_url": "https://celoscan.io/tx/{transaction_digest}",
|
|
85
95
|
"subgraph_url": ""
|
|
86
96
|
},
|
|
87
97
|
"optimism": {
|
|
88
98
|
"agent_registry_contract": "0x75D529FAe220bC8db714F0202193726b46881B76",
|
|
99
|
+
"service_registry_contract": "0x3d77596beb0f130a4415df3D2D8232B3d3D31e44",
|
|
100
|
+
"mech_marketplace_contract": "0x0000000000000000000000000000000000000000",
|
|
89
101
|
"rpc_url": "https://mainnet.optimism.io",
|
|
90
102
|
"wss_endpoint": "wss://optimism.gateway.tenderly.co",
|
|
91
103
|
"ledger_config": {
|
|
@@ -101,4 +113,4 @@
|
|
|
101
113
|
"transaction_url": "https://optimistic.etherscan.io/tx/{transaction_digest}",
|
|
102
114
|
"subgraph_url": ""
|
|
103
115
|
}
|
|
104
|
-
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# ------------------------------------------------------------------------------
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2023 Valory AG
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
# ------------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
"""
|
|
21
|
+
This script allows fetching ipfs hash of data without uploading to IPFS.
|
|
22
|
+
|
|
23
|
+
Usage:
|
|
24
|
+
|
|
25
|
+
python fetch_ipfs_hash.py <data>
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
import json
|
|
29
|
+
import shutil
|
|
30
|
+
import tempfile
|
|
31
|
+
import uuid
|
|
32
|
+
from typing import Any, Dict, Optional, Tuple
|
|
33
|
+
|
|
34
|
+
from aea.helpers.ipfs.base import IPFSHashOnly
|
|
35
|
+
from multibase import multibase
|
|
36
|
+
from multicodec import multicodec
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def fetch_ipfs_hash(
|
|
40
|
+
prompt: str, tool: str, extra_attributes: Optional[Dict[str, Any]] = None
|
|
41
|
+
) -> Tuple[Any, Any, bytes]:
|
|
42
|
+
"""
|
|
43
|
+
Fetches IPFS hash of the data.
|
|
44
|
+
|
|
45
|
+
:param prompt: Prompt string.
|
|
46
|
+
:type prompt: str
|
|
47
|
+
:param tool: Tool string.
|
|
48
|
+
:type tool: str
|
|
49
|
+
:param extra_attributes: Extra attributes to be included in the request metadata.
|
|
50
|
+
:type extra_attributes: Optional[Dict[str,Any]]
|
|
51
|
+
:return: Tuple containing the IPFS hash, truncated IPFS hash and the metadata for which the hash was calculated.
|
|
52
|
+
:rtype: Tuple[str, str, bytes]
|
|
53
|
+
"""
|
|
54
|
+
metadata = {"prompt": prompt, "tool": tool, "nonce": str(uuid.uuid4())}
|
|
55
|
+
if extra_attributes:
|
|
56
|
+
metadata.update(extra_attributes)
|
|
57
|
+
|
|
58
|
+
dirpath = tempfile.mkdtemp()
|
|
59
|
+
file_name = "metadata.json"
|
|
60
|
+
with open(file_name, "w", encoding="utf-8") as f:
|
|
61
|
+
json.dump(metadata, f, separators=(",", ":"))
|
|
62
|
+
|
|
63
|
+
v1_file_hash = IPFSHashOnly.get(file_name, wrap=True)
|
|
64
|
+
|
|
65
|
+
with open(file_name, "rb") as f:
|
|
66
|
+
ipfs_data = f.read()
|
|
67
|
+
|
|
68
|
+
shutil.rmtree(dirpath)
|
|
69
|
+
|
|
70
|
+
cid_bytes = multibase.decode(v1_file_hash)
|
|
71
|
+
multihash_bytes = multicodec.remove_prefix(cid_bytes)
|
|
72
|
+
v1_file_hash_hex = "f01" + multihash_bytes.hex()
|
|
73
|
+
|
|
74
|
+
return "0x" + v1_file_hash_hex[9:], v1_file_hash_hex, ipfs_data
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def main(prompt: str, tool: str) -> None:
|
|
78
|
+
"""
|
|
79
|
+
Prints the IPFS hash and truncated IPFS hash for the metadata object.
|
|
80
|
+
|
|
81
|
+
:param prompt: Prompt string.
|
|
82
|
+
:type prompt: str
|
|
83
|
+
:param tool: Tool string.
|
|
84
|
+
:type tool: str
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
v1_file_hash, _, _ = fetch_ipfs_hash(prompt, tool)
|
|
88
|
+
print("IPFS file hash v1: {}".format(v1_file_hash))
|
mech_client/helpers/__init__.py
CHANGED
|
@@ -22,6 +22,16 @@
|
|
|
22
22
|
from pathlib import Path
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
ACN_PROTOCOL_PACKAGE =
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
ACN_PROTOCOL_PACKAGE = (
|
|
26
|
+
Path(__file__).parents[2] / "packages" / "valory" / "protocols" / "acn"
|
|
27
|
+
)
|
|
28
|
+
P2P_CLIENT_PACKAGE = (
|
|
29
|
+
Path(__file__).parents[2]
|
|
30
|
+
/ "packages"
|
|
31
|
+
/ "valory"
|
|
32
|
+
/ "connections"
|
|
33
|
+
/ "p2p_libp2p_client"
|
|
34
|
+
)
|
|
35
|
+
ACN_DATA_SHARE_PROTOCOL_PACKAGE = (
|
|
36
|
+
Path(__file__).parents[2] / "packages" / "valory" / "protocols" / "acn_data_share"
|
|
37
|
+
)
|
mech_client/interact.py
CHANGED
|
@@ -31,7 +31,7 @@ import os
|
|
|
31
31
|
import sys
|
|
32
32
|
import time
|
|
33
33
|
import warnings
|
|
34
|
-
from dataclasses import asdict, dataclass
|
|
34
|
+
from dataclasses import asdict, dataclass, field
|
|
35
35
|
from datetime import datetime
|
|
36
36
|
from enum import Enum
|
|
37
37
|
from pathlib import Path
|
|
@@ -100,11 +100,24 @@ class LedgerConfig:
|
|
|
100
100
|
self.is_gas_estimation_enabled = bool(is_gas_estimation_enabled)
|
|
101
101
|
|
|
102
102
|
|
|
103
|
+
@dataclass
|
|
104
|
+
class MechMarketplaceRequestConfig:
|
|
105
|
+
"""Mech Marketplace Request Config"""
|
|
106
|
+
|
|
107
|
+
mech_marketplace_contract: Optional[str] = field(default=None)
|
|
108
|
+
priority_mech_address: Optional[str] = field(default=None)
|
|
109
|
+
delivery_rate: Optional[int] = field(default=None)
|
|
110
|
+
payment_type: Optional[str] = field(default=None)
|
|
111
|
+
response_timeout: Optional[int] = field(default=None)
|
|
112
|
+
payment_data: Optional[str] = field(default=None)
|
|
113
|
+
|
|
114
|
+
|
|
103
115
|
@dataclass
|
|
104
116
|
class MechConfig: # pylint: disable=too-many-instance-attributes
|
|
105
117
|
"""Mech configuration"""
|
|
106
118
|
|
|
107
119
|
agent_registry_contract: str
|
|
120
|
+
service_registry_contract: str
|
|
108
121
|
rpc_url: str
|
|
109
122
|
wss_endpoint: str
|
|
110
123
|
ledger_config: LedgerConfig
|
|
@@ -113,6 +126,8 @@ class MechConfig: # pylint: disable=too-many-instance-attributes
|
|
|
113
126
|
transaction_url: str
|
|
114
127
|
subgraph_url: str
|
|
115
128
|
price: int
|
|
129
|
+
mech_marketplace_contract: str
|
|
130
|
+
priority_mech_address: Optional[str] = field(default=None)
|
|
116
131
|
|
|
117
132
|
def __post_init__(self) -> None:
|
|
118
133
|
"""Post initialization to override with environment variables."""
|
|
@@ -120,6 +135,10 @@ class MechConfig: # pylint: disable=too-many-instance-attributes
|
|
|
120
135
|
if agent_registry_contract:
|
|
121
136
|
self.agent_registry_contract = agent_registry_contract
|
|
122
137
|
|
|
138
|
+
service_registry_contract = os.getenv("MECHX_SERVICE_REGISTRY_CONTRACT")
|
|
139
|
+
if service_registry_contract:
|
|
140
|
+
self.service_registry_contract = service_registry_contract
|
|
141
|
+
|
|
123
142
|
rpc_url = os.getenv("MECHX_CHAIN_RPC")
|
|
124
143
|
if rpc_url:
|
|
125
144
|
self.rpc_url = rpc_url
|
|
@@ -170,8 +189,11 @@ def get_mech_config(chain_config: Optional[str] = None) -> MechConfig:
|
|
|
170
189
|
|
|
171
190
|
entry = data[chain_config].copy()
|
|
172
191
|
ledger_config = LedgerConfig(**entry.pop("ledger_config"))
|
|
173
|
-
mech_config = MechConfig(**entry, ledger_config=ledger_config)
|
|
174
192
|
|
|
193
|
+
mech_config = MechConfig(
|
|
194
|
+
**entry,
|
|
195
|
+
ledger_config=ledger_config,
|
|
196
|
+
)
|
|
175
197
|
return mech_config
|
|
176
198
|
|
|
177
199
|
|