mech-client 0.4.0__py3-none-any.whl → 0.6.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/AgentMech.json +718 -0
- mech_client/abis/AgentRegistry.json +1037 -0
- mech_client/abis/AgreementStoreManager.base.json +766 -0
- mech_client/abis/AgreementStoreManager.gnosis.json +766 -0
- mech_client/abis/DIDRegistry.base.json +2476 -0
- mech_client/abis/DIDRegistry.gnosis.json +2476 -0
- mech_client/abis/EscrowPaymentCondition.base.json +717 -0
- mech_client/abis/EscrowPaymentCondition.gnosis.json +717 -0
- mech_client/abis/LockPaymentCondition.base.json +874 -0
- mech_client/abis/LockPaymentCondition.gnosis.json +874 -0
- mech_client/abis/NFTSalesTemplate.base.json +698 -0
- mech_client/abis/NFTSalesTemplate.gnosis.json +698 -0
- mech_client/abis/NeverminedConfig.base.json +587 -0
- mech_client/abis/NeverminedConfig.gnosis.json +587 -0
- mech_client/abis/SubscriptionNFT.base.json +300 -0
- mech_client/abis/SubscriptionNFT.gnosis.json +300 -0
- mech_client/abis/SubscriptionToken.base.json +1393 -0
- mech_client/abis/TransferNFTCondition.base.json +1062 -0
- mech_client/abis/TransferNFTCondition.gnosis.json +1062 -0
- mech_client/cli.py +99 -10
- mech_client/configs/mechs.json +1 -7
- mech_client/interact.py +14 -39
- mech_client/marketplace_interact.py +130 -90
- mech_client/mech_tool_management.py +11 -5
- mech_client/subgraph.py +21 -35
- mech_client/wss.py +7 -6
- {mech_client-0.4.0.dist-info → mech_client-0.6.0.dist-info}/METADATA +45 -13
- {mech_client-0.4.0.dist-info → mech_client-0.6.0.dist-info}/RECORD +32 -13
- {mech_client-0.4.0.dist-info → mech_client-0.6.0.dist-info}/LICENSE +0 -0
- {mech_client-0.4.0.dist-info → mech_client-0.6.0.dist-info}/WHEEL +0 -0
- {mech_client-0.4.0.dist-info → mech_client-0.6.0.dist-info}/entry_points.txt +0 -0
|
@@ -55,7 +55,7 @@ from mech_client.wss import (
|
|
|
55
55
|
register_event_handlers,
|
|
56
56
|
wait_for_receipt,
|
|
57
57
|
watch_for_marketplace_data_url_from_wss,
|
|
58
|
-
|
|
58
|
+
watch_for_marketplace_request_ids,
|
|
59
59
|
)
|
|
60
60
|
|
|
61
61
|
|
|
@@ -73,6 +73,7 @@ class PaymentType(Enum):
|
|
|
73
73
|
)
|
|
74
74
|
|
|
75
75
|
|
|
76
|
+
IPFS_URL_TEMPLATE = "https://gateway.autonolas.tech/ipfs/f01701220{}"
|
|
76
77
|
ABI_DIR_PATH = Path(__file__).parent / "abis"
|
|
77
78
|
IMECH_ABI_PATH = ABI_DIR_PATH / "IMech.json"
|
|
78
79
|
ITOKEN_ABI_PATH = ABI_DIR_PATH / "IToken.json"
|
|
@@ -96,26 +97,22 @@ PAYMENT_TYPE_TO_ABI_PATH: Dict[str, Path] = {
|
|
|
96
97
|
PaymentType.TOKEN_NVM.value: BALANCE_TRACKER_NVM_TOKEN_ABI_PATH,
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
1: "
|
|
101
|
-
10: "
|
|
102
|
-
100: "
|
|
103
|
-
137: "
|
|
104
|
-
8453: "
|
|
105
|
-
42220: "
|
|
100
|
+
CHAIN_TO_PRICE_TOKEN = {
|
|
101
|
+
1: "0x0001A500A6B18995B03f44bb040A5fFc28E45CB0",
|
|
102
|
+
10: "0xFC2E6e6BCbd49ccf3A5f029c79984372DcBFE527",
|
|
103
|
+
100: "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f",
|
|
104
|
+
137: "0xFEF5d947472e72Efbb2E388c730B7428406F2F95",
|
|
105
|
+
8453: "0x54330d28ca3357F294334BDC454a032e7f353416",
|
|
106
|
+
42220: "0xFEF5d947472e72Efbb2E388c730B7428406F2F95",
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
|
|
109
110
|
CHAIN_TO_DEFAULT_MECH_MARKETPLACE_REQUEST_CONFIG = {
|
|
110
111
|
100: {
|
|
111
|
-
"mech_marketplace_contract": "0x735FAAb1c4Ec41128c367AFb5c3baC73509f70bB",
|
|
112
|
-
"priority_mech_address": "0x478ad20eD958dCC5AD4ABa6F4E4cc51e07a840E4",
|
|
113
112
|
"response_timeout": 300,
|
|
114
113
|
"payment_data": "0x",
|
|
115
114
|
},
|
|
116
115
|
8453: {
|
|
117
|
-
"mech_marketplace_contract": "0xf24eE42edA0fc9b33B7D41B06Ee8ccD2Ef7C5020",
|
|
118
|
-
"priority_mech_address": "0xE183610A420dBD8825fed49C589Fe2d5BFd5b17a",
|
|
119
116
|
"response_timeout": 300,
|
|
120
117
|
"payment_data": "0x",
|
|
121
118
|
},
|
|
@@ -280,8 +277,8 @@ def send_marketplace_request( # pylint: disable=too-many-arguments,too-many-loc
|
|
|
280
277
|
ledger_api: EthereumApi,
|
|
281
278
|
marketplace_contract: Web3Contract,
|
|
282
279
|
gas_limit: int,
|
|
283
|
-
|
|
284
|
-
|
|
280
|
+
prompts: tuple,
|
|
281
|
+
tools: tuple,
|
|
285
282
|
method_args_data: MechMarketplaceRequestConfig,
|
|
286
283
|
extra_attributes: Optional[Dict[str, Any]] = None,
|
|
287
284
|
price: int = 10_000_000_000_000_000,
|
|
@@ -300,10 +297,10 @@ def send_marketplace_request( # pylint: disable=too-many-arguments,too-many-loc
|
|
|
300
297
|
:type marketplace_contract: Web3Contract
|
|
301
298
|
:param gas_limit: Gas limit.
|
|
302
299
|
:type gas_limit: int
|
|
303
|
-
:param
|
|
304
|
-
:type
|
|
305
|
-
:param
|
|
306
|
-
:type
|
|
300
|
+
:param prompts: The request prompts.
|
|
301
|
+
:type prompts: tuple
|
|
302
|
+
:param tools: The requested tools.
|
|
303
|
+
:type tools: tuple
|
|
307
304
|
:param method_args_data: Method data to use to call the marketplace contract request
|
|
308
305
|
:type method_args_data: MechMarketplaceRequestConfig
|
|
309
306
|
:param extra_attributes: Extra attributes to be included in the request metadata.
|
|
@@ -319,21 +316,40 @@ def send_marketplace_request( # pylint: disable=too-many-arguments,too-many-loc
|
|
|
319
316
|
:return: The transaction hash.
|
|
320
317
|
:rtype: Optional[str]
|
|
321
318
|
"""
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
)
|
|
325
|
-
print(
|
|
326
|
-
f" - Prompt uploaded: https://gateway.autonolas.tech/ipfs/{v1_file_hash_hex}"
|
|
327
|
-
)
|
|
328
|
-
method_name = "request"
|
|
319
|
+
num_requests = len(prompts)
|
|
320
|
+
|
|
329
321
|
method_args = {
|
|
330
|
-
"requestData": v1_file_hash_hex_truncated,
|
|
331
322
|
"maxDeliveryRate": method_args_data.delivery_rate,
|
|
332
323
|
"paymentType": "0x" + cast(str, method_args_data.payment_type),
|
|
333
324
|
"priorityMech": to_checksum_address(method_args_data.priority_mech_address),
|
|
334
325
|
"responseTimeout": method_args_data.response_timeout,
|
|
335
326
|
"paymentData": method_args_data.payment_data,
|
|
336
327
|
}
|
|
328
|
+
|
|
329
|
+
if num_requests == 1:
|
|
330
|
+
v1_file_hash_hex_truncated, v1_file_hash_hex = push_metadata_to_ipfs(
|
|
331
|
+
prompts[0], tools[0], extra_attributes
|
|
332
|
+
)
|
|
333
|
+
print(
|
|
334
|
+
f" - Prompt uploaded: https://gateway.autonolas.tech/ipfs/{v1_file_hash_hex}"
|
|
335
|
+
)
|
|
336
|
+
method_name = "request"
|
|
337
|
+
method_args["requestData"] = v1_file_hash_hex_truncated
|
|
338
|
+
|
|
339
|
+
else:
|
|
340
|
+
request_datas = []
|
|
341
|
+
for prompt, tool in zip(prompts, tools):
|
|
342
|
+
v1_file_hash_hex_truncated, v1_file_hash_hex = push_metadata_to_ipfs(
|
|
343
|
+
prompt, tool, extra_attributes
|
|
344
|
+
)
|
|
345
|
+
print(
|
|
346
|
+
f" - Prompt uploaded: https://gateway.autonolas.tech/ipfs/{v1_file_hash_hex}"
|
|
347
|
+
)
|
|
348
|
+
request_datas.append(v1_file_hash_hex_truncated)
|
|
349
|
+
|
|
350
|
+
method_name = "requestBatch"
|
|
351
|
+
method_args["requestDatas"] = request_datas
|
|
352
|
+
|
|
337
353
|
tx_args = {
|
|
338
354
|
"sender_address": crypto.address,
|
|
339
355
|
"value": price,
|
|
@@ -376,6 +392,7 @@ def send_offchain_marketplace_request( # pylint: disable=too-many-arguments,too
|
|
|
376
392
|
prompt: str,
|
|
377
393
|
tool: str,
|
|
378
394
|
method_args_data: MechMarketplaceRequestConfig,
|
|
395
|
+
nonce: int,
|
|
379
396
|
extra_attributes: Optional[Dict[str, Any]] = None,
|
|
380
397
|
retries: Optional[int] = None,
|
|
381
398
|
timeout: Optional[float] = None,
|
|
@@ -394,6 +411,8 @@ def send_offchain_marketplace_request( # pylint: disable=too-many-arguments,too
|
|
|
394
411
|
:type tool: str
|
|
395
412
|
:param method_args_data: Method data to use to call the marketplace contract request
|
|
396
413
|
:type method_args_data: MechMarketplaceRequestConfig
|
|
414
|
+
:param nonce: Nonce to use to order offchain tasks
|
|
415
|
+
:type nonce: int
|
|
397
416
|
:param extra_attributes: Extra attributes to be included in the request metadata.
|
|
398
417
|
:type extra_attributes: Optional[Dict[str,Any]]
|
|
399
418
|
:param retries: Number of retries for sending a transaction
|
|
@@ -429,7 +448,6 @@ def send_offchain_marketplace_request( # pylint: disable=too-many-arguments,too
|
|
|
429
448
|
while tries < retries and datetime.now().timestamp() < deadline:
|
|
430
449
|
tries += 1
|
|
431
450
|
try:
|
|
432
|
-
nonce = marketplace_contract.functions.mapNonces(crypto.address).call()
|
|
433
451
|
delivery_rate = method_args["maxDeliveryRate"]
|
|
434
452
|
request_id = marketplace_contract.functions.getRequestId(
|
|
435
453
|
method_args["priorityMech"],
|
|
@@ -616,11 +634,11 @@ def check_prepaid_balances(
|
|
|
616
634
|
|
|
617
635
|
|
|
618
636
|
def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals, too-many-statements, too-many-return-statements
|
|
619
|
-
|
|
637
|
+
prompts: tuple,
|
|
620
638
|
priority_mech: str,
|
|
621
639
|
use_prepaid: bool = False,
|
|
622
640
|
use_offchain: bool = False,
|
|
623
|
-
|
|
641
|
+
tools: tuple = (),
|
|
624
642
|
extra_attributes: Optional[Dict[str, Any]] = None,
|
|
625
643
|
private_key_path: Optional[str] = None,
|
|
626
644
|
confirmation_type: ConfirmationType = ConfirmationType.WAIT_FOR_BOTH,
|
|
@@ -632,16 +650,16 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
|
|
|
632
650
|
"""
|
|
633
651
|
Interact with mech marketplace contract.
|
|
634
652
|
|
|
635
|
-
:param
|
|
636
|
-
:type
|
|
653
|
+
:param prompts: The interaction prompts.
|
|
654
|
+
:type prompts: tuple
|
|
637
655
|
:param priority_mech: Priority mech address to use (Optional)
|
|
638
656
|
:type priority_mech: str
|
|
639
657
|
:param use_prepaid: Whether to use prepaid model or not.
|
|
640
658
|
:type use_prepaid: bool
|
|
641
659
|
:param use_offchain: Whether to use offchain model or not.
|
|
642
660
|
:type use_offchain: bool
|
|
643
|
-
:param
|
|
644
|
-
:type
|
|
661
|
+
:param tools: The tools to interact with (optional).
|
|
662
|
+
:type tools: tuple
|
|
645
663
|
:param extra_attributes: Extra attributes to be included in the request metadata (optional).
|
|
646
664
|
:type extra_attributes: Optional[Dict[str, Any]]
|
|
647
665
|
:param private_key_path: The path to the private key file (optional).
|
|
@@ -665,21 +683,23 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
|
|
|
665
683
|
priority_mech_address = priority_mech
|
|
666
684
|
mech_marketplace_contract = mech_config.mech_marketplace_contract
|
|
667
685
|
chain_id = ledger_config.chain_id
|
|
686
|
+
num_requests = len(prompts)
|
|
668
687
|
|
|
669
688
|
if mech_marketplace_contract == ADDRESS_ZERO:
|
|
670
689
|
print(f"Mech Marketplace not yet supported on {chain_config}")
|
|
671
690
|
return None
|
|
672
691
|
|
|
673
692
|
config_values = CHAIN_TO_DEFAULT_MECH_MARKETPLACE_REQUEST_CONFIG[chain_id].copy()
|
|
674
|
-
if priority_mech_address is
|
|
675
|
-
print("
|
|
676
|
-
|
|
677
|
-
{
|
|
678
|
-
"priority_mech_address": priority_mech_address,
|
|
679
|
-
"mech_marketplace_contract": mech_marketplace_contract,
|
|
680
|
-
}
|
|
681
|
-
)
|
|
693
|
+
if priority_mech_address is None:
|
|
694
|
+
print("Priority Mech Address not provided")
|
|
695
|
+
return None
|
|
682
696
|
|
|
697
|
+
config_values.update(
|
|
698
|
+
{
|
|
699
|
+
"priority_mech_address": priority_mech_address,
|
|
700
|
+
"mech_marketplace_contract": mech_marketplace_contract,
|
|
701
|
+
}
|
|
702
|
+
)
|
|
683
703
|
mech_marketplace_request_config: MechMarketplaceRequestConfig = make_dataclass(
|
|
684
704
|
"MechMarketplaceRequestConfig",
|
|
685
705
|
((k, type(v)) for k, v in config_values.items()),
|
|
@@ -740,12 +760,12 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
|
|
|
740
760
|
)
|
|
741
761
|
|
|
742
762
|
if not use_prepaid:
|
|
743
|
-
price = max_delivery_rate
|
|
763
|
+
price = max_delivery_rate * num_requests
|
|
744
764
|
if payment_type == PaymentType.TOKEN.value:
|
|
745
765
|
print("Token Mech detected, approving wrapped token for price payment...")
|
|
746
|
-
|
|
766
|
+
price_token = CHAIN_TO_PRICE_TOKEN[chain_id]
|
|
747
767
|
approve_tx = approve_price_tokens(
|
|
748
|
-
crypto, ledger_api,
|
|
768
|
+
crypto, ledger_api, price_token, mech_payment_balance_tracker, price
|
|
749
769
|
)
|
|
750
770
|
if not approve_tx:
|
|
751
771
|
print("Unable to approve allowance")
|
|
@@ -799,8 +819,8 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
|
|
|
799
819
|
marketplace_contract=mech_marketplace_contract,
|
|
800
820
|
gas_limit=mech_config.gas_limit,
|
|
801
821
|
price=price,
|
|
802
|
-
|
|
803
|
-
|
|
822
|
+
prompts=prompts,
|
|
823
|
+
tools=tools,
|
|
804
824
|
method_args_data=mech_marketplace_request_config,
|
|
805
825
|
extra_attributes=extra_attributes,
|
|
806
826
|
retries=retries,
|
|
@@ -818,66 +838,86 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
|
|
|
818
838
|
print(f" - Transaction sent: {transaction_url_formatted}")
|
|
819
839
|
print(" - Waiting for transaction receipt...")
|
|
820
840
|
|
|
821
|
-
|
|
841
|
+
request_ids = watch_for_marketplace_request_ids(
|
|
822
842
|
marketplace_contract=mech_marketplace_contract,
|
|
823
843
|
ledger_api=ledger_api,
|
|
824
844
|
tx_hash=transaction_digest,
|
|
825
845
|
)
|
|
826
|
-
|
|
827
|
-
|
|
846
|
+
request_id_ints = [
|
|
847
|
+
int.from_bytes(bytes.fromhex(request_id), byteorder="big")
|
|
848
|
+
for request_id in request_ids
|
|
849
|
+
]
|
|
850
|
+
if len(request_id_ints) == 1:
|
|
851
|
+
print(f" - Created on-chain request with ID {request_id_ints[0]}")
|
|
852
|
+
else:
|
|
853
|
+
print(
|
|
854
|
+
f" - Created on-chain requests with IDs: {', '.join(str(rid) for rid in request_id_ints)}"
|
|
855
|
+
)
|
|
828
856
|
print("")
|
|
829
857
|
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
858
|
+
for request_id, request_id_int in zip(request_ids, request_id_ints):
|
|
859
|
+
data_url = wait_for_marketplace_data_url(
|
|
860
|
+
request_id=request_id,
|
|
861
|
+
wss=wss,
|
|
862
|
+
mech_contract=mech_contract,
|
|
863
|
+
subgraph_url=mech_config.subgraph_url,
|
|
864
|
+
deliver_signature=marketplace_deliver_event_signature,
|
|
865
|
+
ledger_api=ledger_api,
|
|
866
|
+
crypto=crypto,
|
|
867
|
+
confirmation_type=confirmation_type,
|
|
868
|
+
)
|
|
840
869
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
return data
|
|
870
|
+
if data_url:
|
|
871
|
+
print(f" - Data arrived: {data_url}")
|
|
872
|
+
data = requests.get(f"{data_url}/{request_id_int}", timeout=30).json()
|
|
873
|
+
print(" - Data from agent:")
|
|
874
|
+
print(json.dumps(data, indent=2))
|
|
847
875
|
return None
|
|
848
876
|
|
|
849
877
|
print("Sending Offchain Mech Marketplace request...")
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
878
|
+
curr_nonce = mech_marketplace_contract.functions.mapNonces(crypto.address).call() # type: ignore
|
|
879
|
+
responses = []
|
|
880
|
+
|
|
881
|
+
for i in range(num_requests):
|
|
882
|
+
response = send_offchain_marketplace_request(
|
|
883
|
+
crypto=crypto,
|
|
884
|
+
marketplace_contract=mech_marketplace_contract,
|
|
885
|
+
prompt=prompts[0],
|
|
886
|
+
tool=tools[0],
|
|
887
|
+
method_args_data=mech_marketplace_request_config,
|
|
888
|
+
nonce=curr_nonce + i,
|
|
889
|
+
extra_attributes=extra_attributes,
|
|
890
|
+
retries=retries,
|
|
891
|
+
timeout=timeout,
|
|
892
|
+
sleep=sleep,
|
|
893
|
+
)
|
|
894
|
+
responses.append(response)
|
|
861
895
|
|
|
862
|
-
if not
|
|
896
|
+
if not responses and len(responses) != num_requests:
|
|
863
897
|
return None
|
|
864
898
|
|
|
865
|
-
|
|
866
|
-
|
|
899
|
+
request_ids = [resp["request_id"] for resp in responses if resp is not None]
|
|
900
|
+
if len(request_ids) == 1:
|
|
901
|
+
print(f" - Created off-chain request with ID {request_ids[0]}")
|
|
902
|
+
else:
|
|
903
|
+
print(
|
|
904
|
+
f" - Created off-chain requests with IDs: {', '.join(str(rid) for rid in request_ids)}"
|
|
905
|
+
)
|
|
867
906
|
print("")
|
|
868
907
|
|
|
869
908
|
# @note as we are directly querying data from done task list, we get the full data instead of the ipfs hash
|
|
870
909
|
print("Waiting for Offchain Mech Marketplace deliver...")
|
|
871
|
-
data = wait_for_offchain_marketplace_data(
|
|
872
|
-
request_id=request_id,
|
|
873
|
-
)
|
|
874
910
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
911
|
+
for request_id in request_ids:
|
|
912
|
+
data = wait_for_offchain_marketplace_data(
|
|
913
|
+
request_id=request_id,
|
|
914
|
+
)
|
|
915
|
+
|
|
916
|
+
if data:
|
|
917
|
+
task_result = data["task_result"]
|
|
918
|
+
data_url = IPFS_URL_TEMPLATE.format(task_result)
|
|
919
|
+
print(f" - Data arrived: {data_url}")
|
|
920
|
+
data = requests.get(f"{data_url}/{request_id}", timeout=30).json()
|
|
921
|
+
print(" - Data from agent:")
|
|
922
|
+
print(json.dumps(data, indent=2))
|
|
883
923
|
return None
|
|
@@ -7,7 +7,13 @@ from typing import Any, Dict, List, Optional, Tuple, Union
|
|
|
7
7
|
import requests
|
|
8
8
|
from aea_ledger_ethereum import EthereumApi
|
|
9
9
|
|
|
10
|
-
from mech_client.interact import
|
|
10
|
+
from mech_client.interact import (
|
|
11
|
+
AGENT_REGISTRY_ABI_PATH,
|
|
12
|
+
fetch_tools,
|
|
13
|
+
get_abi,
|
|
14
|
+
get_contract,
|
|
15
|
+
get_mech_config,
|
|
16
|
+
)
|
|
11
17
|
|
|
12
18
|
|
|
13
19
|
def get_total_supply(chain_config: str = "gnosis") -> int:
|
|
@@ -27,7 +33,7 @@ def get_total_supply(chain_config: str = "gnosis") -> int:
|
|
|
27
33
|
ledger_api = EthereumApi(**asdict(ledger_config))
|
|
28
34
|
|
|
29
35
|
# Fetch ABI and create contract instance
|
|
30
|
-
abi = get_abi(
|
|
36
|
+
abi = get_abi(AGENT_REGISTRY_ABI_PATH)
|
|
31
37
|
contract = get_contract(mech_config.agent_registry_contract, abi, ledger_api)
|
|
32
38
|
|
|
33
39
|
# Call the totalSupply function
|
|
@@ -58,7 +64,7 @@ def get_agent_tools(
|
|
|
58
64
|
agent_id=agent_id,
|
|
59
65
|
ledger_api=ledger_api,
|
|
60
66
|
agent_registry_contract=mech_config.agent_registry_contract,
|
|
61
|
-
|
|
67
|
+
contract_abi_path=AGENT_REGISTRY_ABI_PATH,
|
|
62
68
|
include_metadata=include_metadata,
|
|
63
69
|
)
|
|
64
70
|
except (requests.exceptions.RequestException, json.JSONDecodeError, KeyError) as e:
|
|
@@ -155,7 +161,7 @@ def get_tool_description(unique_identifier: str, chain_config: str = "gnosis") -
|
|
|
155
161
|
agent_id=agent_id,
|
|
156
162
|
ledger_api=ledger_api,
|
|
157
163
|
agent_registry_contract=mech_config.agent_registry_contract,
|
|
158
|
-
|
|
164
|
+
contract_abi_path=AGENT_REGISTRY_ABI_PATH,
|
|
159
165
|
include_metadata=True,
|
|
160
166
|
)
|
|
161
167
|
if isinstance(tools_result, tuple) and len(tools_result) == 2:
|
|
@@ -188,7 +194,7 @@ def get_tool_io_schema(
|
|
|
188
194
|
agent_id=agent_id,
|
|
189
195
|
ledger_api=ledger_api,
|
|
190
196
|
agent_registry_contract=mech_config.agent_registry_contract,
|
|
191
|
-
|
|
197
|
+
contract_abi_path=AGENT_REGISTRY_ABI_PATH,
|
|
192
198
|
include_metadata=True,
|
|
193
199
|
)
|
|
194
200
|
if isinstance(tools_result, tuple) and len(tools_result) == 2:
|
mech_client/subgraph.py
CHANGED
|
@@ -48,12 +48,28 @@ DELIVER_QUERY_TEMPLATE = Template(
|
|
|
48
48
|
"""
|
|
49
49
|
)
|
|
50
50
|
DEFAULT_TIMEOUT = 600.0
|
|
51
|
+
CHAIN_TO_ADDRESSES = {
|
|
52
|
+
"gnosis": {
|
|
53
|
+
3: "0xFf82123dFB52ab75C417195c5fDB87630145ae81",
|
|
54
|
+
6: "0x77af31De935740567Cf4fF1986D04B2c964A786a",
|
|
55
|
+
9: "0x552cea7bc33cbbeb9f1d90c1d11d2c6daeffd053",
|
|
56
|
+
11: "0x9aDe7A78A39B39a44b7a084923E93AA0B19Fd690",
|
|
57
|
+
19: "0x45b73d649c7b982548d5a6dd3d35e1c5c48997d0",
|
|
58
|
+
},
|
|
59
|
+
"base": {
|
|
60
|
+
1: "0x37C484cc34408d0F827DB4d7B6e54b8837Bf8BDA",
|
|
61
|
+
2: "0x111D7DB1B752AB4D2cC0286983D9bd73a49bac6c",
|
|
62
|
+
3: "0x111D7DB1B752AB4D2cC0286983D9bd73a49bac6c",
|
|
63
|
+
},
|
|
64
|
+
"arbitrum": {2: "0x1FDAD3a5af5E96e5a64Fc0662B1814458F114597"},
|
|
65
|
+
"polygon": {2: "0xbF92568718982bf65ee4af4F7020205dE2331a8a"},
|
|
66
|
+
"celo": {2: "0x230eD015735c0D01EA0AaD2786Ed6Bd3C6e75912"},
|
|
67
|
+
"optimism": {2: "0xDd40E7D93c37eFD860Bd53Ab90b2b0a8D05cf71a"},
|
|
68
|
+
}
|
|
51
69
|
|
|
52
70
|
|
|
53
71
|
def query_agent_address( # pylint: disable=too-many-return-statements
|
|
54
72
|
agent_id: int,
|
|
55
|
-
url: str,
|
|
56
|
-
timeout: Optional[float] = None,
|
|
57
73
|
chain_config: Optional[str] = None,
|
|
58
74
|
) -> Optional[str]:
|
|
59
75
|
"""
|
|
@@ -61,44 +77,14 @@ def query_agent_address( # pylint: disable=too-many-return-statements
|
|
|
61
77
|
|
|
62
78
|
:param agent_id: The ID of the agent.
|
|
63
79
|
:type agent_id: int
|
|
64
|
-
:param url: Subgraph URL.
|
|
65
|
-
:type url: str
|
|
66
|
-
:param timeout: Timeout for the request.
|
|
67
|
-
:type timeout: Optional[float]
|
|
68
80
|
:type chain_config: Optional[str]:
|
|
69
81
|
:return: The agent address if found, None otherwise.
|
|
70
82
|
:rtype: Optional[str]
|
|
71
83
|
"""
|
|
72
84
|
# temporary hard coded until subgraph present
|
|
73
|
-
if chain_config
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return "0x111D7DB1B752AB4D2cC0286983D9bd73a49bac6c"
|
|
77
|
-
if chain_config == "base" and agent_id == 3:
|
|
78
|
-
return "0x111D7DB1B752AB4D2cC0286983D9bd73a49bac6c"
|
|
79
|
-
if chain_config == "arbitrum" and agent_id == 2:
|
|
80
|
-
return "0x1FDAD3a5af5E96e5a64Fc0662B1814458F114597"
|
|
81
|
-
if chain_config == "polygon" and agent_id == 2:
|
|
82
|
-
return "0xbF92568718982bf65ee4af4F7020205dE2331a8a"
|
|
83
|
-
if chain_config == "celo" and agent_id == 2:
|
|
84
|
-
return "0x230eD015735c0D01EA0AaD2786Ed6Bd3C6e75912"
|
|
85
|
-
if chain_config == "optimism" and agent_id == 2:
|
|
86
|
-
return "0xDd40E7D93c37eFD860Bd53Ab90b2b0a8D05cf71a"
|
|
87
|
-
client = Client(
|
|
88
|
-
transport=AIOHTTPTransport(url=url),
|
|
89
|
-
execute_timeout=timeout or 30.0,
|
|
90
|
-
)
|
|
91
|
-
response = client.execute(
|
|
92
|
-
document=gql(
|
|
93
|
-
request_string=AGENT_QUERY_TEMPLATE.substitute({"agent_id": agent_id})
|
|
94
|
-
)
|
|
95
|
-
)
|
|
96
|
-
mechs = response["createMeches"] # pylint: disable=unsubscriptable-object
|
|
97
|
-
if len(mechs) == 0:
|
|
98
|
-
return None
|
|
99
|
-
|
|
100
|
-
(record,) = mechs
|
|
101
|
-
return record["mech"]
|
|
85
|
+
if not chain_config:
|
|
86
|
+
raise ValueError("Chain config not specified")
|
|
87
|
+
return CHAIN_TO_ADDRESSES.get(chain_config, {}).get(agent_id, None)
|
|
102
88
|
|
|
103
89
|
|
|
104
90
|
async def query_deliver_hash(
|
mech_client/wss.py
CHANGED
|
@@ -23,7 +23,7 @@ import asyncio
|
|
|
23
23
|
import json
|
|
24
24
|
import time
|
|
25
25
|
from concurrent.futures import ThreadPoolExecutor
|
|
26
|
-
from typing import Any, Dict, cast
|
|
26
|
+
from typing import Any, Dict, List, cast
|
|
27
27
|
|
|
28
28
|
import websocket
|
|
29
29
|
from aea.crypto.base import Crypto
|
|
@@ -143,11 +143,11 @@ def watch_for_request_id( # pylint: disable=too-many-arguments
|
|
|
143
143
|
return request_id
|
|
144
144
|
|
|
145
145
|
|
|
146
|
-
def
|
|
146
|
+
def watch_for_marketplace_request_ids( # pylint: disable=too-many-arguments, unused-argument
|
|
147
147
|
marketplace_contract: Web3Contract,
|
|
148
148
|
ledger_api: EthereumApi,
|
|
149
149
|
tx_hash: str,
|
|
150
|
-
) -> str:
|
|
150
|
+
) -> List[str]:
|
|
151
151
|
"""
|
|
152
152
|
Watches for events on mech.
|
|
153
153
|
|
|
@@ -167,10 +167,11 @@ def watch_for_marketplace_request_id( # pylint: disable=too-many-arguments, unu
|
|
|
167
167
|
tx_receipt
|
|
168
168
|
)
|
|
169
169
|
if len(rich_logs) == 0:
|
|
170
|
-
return "Empty Logs"
|
|
170
|
+
return ["Empty Logs"]
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
request_ids = rich_logs[0]["args"]["requestIds"]
|
|
173
|
+
request_ids_hex = [request_id.hex() for request_id in request_ids]
|
|
174
|
+
return request_ids_hex
|
|
174
175
|
|
|
175
176
|
|
|
176
177
|
async def watch_for_data_url_from_wss( # pylint: disable=too-many-arguments
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mech-client
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Basic client to interact with a mech
|
|
5
5
|
License: Apache-2.0
|
|
6
6
|
Author: David Minarsch
|
|
@@ -16,6 +16,7 @@ Requires-Dist: open-aea-cli-ipfs (>=1.53.0,<2.0.0)
|
|
|
16
16
|
Requires-Dist: open-aea-ledger-cosmos (>=1.53.0,<2.0.0)
|
|
17
17
|
Requires-Dist: open-aea-ledger-ethereum (>=1.53.0,<2.0.0)
|
|
18
18
|
Requires-Dist: open-aea[cli] (>=1.53.0,<2.0.0)
|
|
19
|
+
Requires-Dist: setuptools (>=77.0.3,<78.0.0)
|
|
19
20
|
Requires-Dist: tabulate (>=0.9.0,<0.10.0)
|
|
20
21
|
Requires-Dist: websocket-client (>=0.32.0,<1)
|
|
21
22
|
Description-Content-Type: text/markdown
|
|
@@ -143,15 +144,17 @@ export MECHX_API_KEY=<your api key>
|
|
|
143
144
|
The basic usage of the Mech Client is as follows:
|
|
144
145
|
|
|
145
146
|
```bash
|
|
146
|
-
mechx interact <prompt> --agent_id <agent_id>
|
|
147
|
+
mechx interact --prompts <prompt> --tools <tool> --agent_id <agent_id>
|
|
147
148
|
```
|
|
148
149
|
|
|
149
|
-
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).
|
|
150
|
+
where agent with `<agent_id>` will process `<prompt>` with the `<tool>` and 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).
|
|
151
|
+
|
|
152
|
+
⚠️ Batch requests and tools are not supported for legacy mechs
|
|
150
153
|
|
|
151
154
|
Some useful options:
|
|
152
155
|
|
|
153
156
|
- `--key <private_key_path>`: Specifies the path of the private key. The default value is `./ethereum_private_key.txt`.
|
|
154
|
-
- `--
|
|
157
|
+
- `--tools <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:
|
|
155
158
|
|
|
156
159
|
```text
|
|
157
160
|
Select prompting tool
|
|
@@ -177,12 +180,12 @@ Some useful options:
|
|
|
177
180
|
- `on-chain`: Wait for the result using the Subgraph and the Websocket subscription (whichever arrives first).
|
|
178
181
|
- `wait-for-both` (Default): Wait for the result using both `off-chain` and `on-chain` (whichever arrives first).
|
|
179
182
|
|
|
180
|
-
|
|
183
|
+
##### Example
|
|
181
184
|
|
|
182
185
|
Example of a request specifying a key file and tool:
|
|
183
186
|
|
|
184
187
|
```bash
|
|
185
|
-
mechx interact "write a short poem" --agent_id 6 --key ~/ethereum_private_key.txt --
|
|
188
|
+
mechx interact --prompts "write a short poem" --agent_id 6 --key ~/ethereum_private_key.txt --tools openai-gpt-3.5-turbo --chain-config gnosis --confirm on-chain
|
|
186
189
|
```
|
|
187
190
|
|
|
188
191
|
You will see an output like this:
|
|
@@ -199,23 +202,53 @@ Data from agent: {'requestId': 1004074058566339663950817114309409628095686850319
|
|
|
199
202
|
|
|
200
203
|
#### With the Mech Marketplace
|
|
201
204
|
|
|
202
|
-
With the Mech Marketplace,
|
|
205
|
+
With the Mech Marketplace, in order to pay for the Mech fees, you can make a deposit before sending requests. The deposit depends on the
|
|
206
|
+
payment model of the Mech. For a fixed price Mech receiving payments in native token, use the following:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
mechx deposit-native --chain-config <chain_config> <amount>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
For a fixed price Mech receiving payments in OLAS, use the following (the amount is in ether):
|
|
203
213
|
|
|
204
214
|
```bash
|
|
205
|
-
mechx
|
|
215
|
+
mechx deposit-token --chain-config <chain_config> <amount>
|
|
206
216
|
```
|
|
207
217
|
|
|
208
|
-
|
|
218
|
+
For a Mech using Nevermined subscriptions, to make requests, it is necessary to buy a subscription. To do that you can use the following command:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
mechx purchase-nvm-subscription --chain-config <chain_config>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
:warning: If you face issues with base RPC, please consider updating to a new one [here](https://github.com/valory-xyz/mech-client/blob/feat/nvm_sub_integration/scripts/nvm_subscription/resources/networks.json#L10).
|
|
225
|
+
|
|
226
|
+
You can use the option `--key <private_key_file_path>` in order to customize the path to the private key file.
|
|
227
|
+
|
|
228
|
+
The basic usage of the Mech Client is then as follows.
|
|
209
229
|
|
|
210
230
|
```bash
|
|
211
|
-
mechx interact <prompt> --priority-mech <priority mech address> --
|
|
231
|
+
mechx interact --prompts <prompt> --priority-mech <priority mech address> --tools openai-gpt-3.5-turbo --chain-config <chain_config>
|
|
212
232
|
```
|
|
213
233
|
|
|
214
234
|
Additionally to other options which are the same as for legacy Mechs, this usage has the following option:
|
|
215
235
|
|
|
216
|
-
`--use-prepaid <bool>`: use the prepaid method to send requests to a Mech via the Mech Marketplace. Defaults to False.
|
|
236
|
+
`--use-prepaid <bool>`: use the prepaid method to send requests to a Mech via the Mech Marketplace. Defaults to False. <br>
|
|
217
237
|
`--use-offchain <bool>`: use the off-chain method to send requests to a Mech via the Mech Marketplace. Defaults to False.
|
|
218
238
|
|
|
239
|
+
The Mech Client can also be used to send batch requests. There are couple of different ways to achieve this:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
mechx interact --prompts={<prompt-1>,<prompt-2>} --priority-mech <priority mech address> --tools={<tool-1>,<tool-2>} --chain-config <chain_config>
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
or <br>
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
mechx interact --prompts <prompt-1> --prompts <prompt-2> --priority-mech <priority mech address> --tools <tool-1> --tools <tool-2> --chain-config <chain_config>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
|
|
219
252
|
### List tools available for agents
|
|
220
253
|
|
|
221
254
|
To list the tools available for a specific agent or for all agents, use the `tools-for-agents` command. You can specify an agent ID to get tools for a specific agent, or omit it to list tools for all agents.
|
|
@@ -336,7 +369,6 @@ Additionally, you can override any configuration parameter by exporting any of t
|
|
|
336
369
|
MECHX_CHAIN_RPC
|
|
337
370
|
MECHX_WSS_ENDPOINT
|
|
338
371
|
MECHX_GAS_LIMIT
|
|
339
|
-
MECHX_CONTRACT_ABI_URL
|
|
340
372
|
MECHX_TRANSACTION_URL
|
|
341
373
|
MECHX_SUBGRAPH_URL
|
|
342
374
|
|
|
@@ -476,7 +508,7 @@ You can find the agent IDs for each chain on the [Mech Hub](https://aimechs.auto
|
|
|
476
508
|
Use the `--chain-config <name>` parameter together with a valid `<agent_id>`, for example:
|
|
477
509
|
|
|
478
510
|
```bash
|
|
479
|
-
mechx interact "write a short poem" 2 --key ./ethereum_private_key.txt --
|
|
511
|
+
mechx interact --prompts "write a short poem" --agent_id 2 --key ./ethereum_private_key.txt --tools openai-gpt-4 --chain-config celo --confirm on-chain
|
|
480
512
|
```
|
|
481
513
|
|
|
482
514
|
</details>
|