mech-client 0.8.2__py3-none-any.whl → 0.9.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 CHANGED
@@ -1,3 +1,3 @@
1
1
  """Mech client."""
2
2
 
3
- __version__ = "0.8.2"
3
+ __version__ = "0.9.0"
mech_client/cli.py CHANGED
@@ -19,6 +19,7 @@
19
19
 
20
20
  """Mech client CLI module."""
21
21
  import json
22
+ import os
22
23
  from typing import Any, Dict, List, Optional, Tuple
23
24
 
24
25
  import click
@@ -156,6 +157,12 @@ def interact( # pylint: disable=too-many-arguments,too-many-locals
156
157
  use_offchain = use_offchain or False
157
158
  use_prepaid = use_prepaid or use_offchain
158
159
 
160
+ mech_offchain_url = os.getenv("MECHX_MECH_OFFCHAIN_URL")
161
+ if use_offchain and not mech_offchain_url:
162
+ raise Exception(
163
+ "To use offchain requests, please set MECHX_MECH_OFFCHAIN_URL"
164
+ )
165
+
159
166
  if agent_id is None:
160
167
  if len(prompts) != len(tools):
161
168
  raise ClickException(
@@ -167,6 +174,7 @@ def interact( # pylint: disable=too-many-arguments,too-many-locals
167
174
  priority_mech=priority_mech,
168
175
  use_prepaid=use_prepaid,
169
176
  use_offchain=use_offchain,
177
+ mech_offchain_url=mech_offchain_url,
170
178
  private_key_path=key,
171
179
  tools=tools,
172
180
  extra_attributes=extra_attributes_dict,
@@ -74,6 +74,8 @@ class PaymentType(Enum):
74
74
 
75
75
 
76
76
  IPFS_URL_TEMPLATE = "https://gateway.autonolas.tech/ipfs/f01701220{}"
77
+ MECH_OFFCHAIN_REQUEST_ENDPOINT = "send_signed_requests"
78
+ MECH_OFFCHAIN_DELIVER_ENDPOINT = "fetch_offchain_info"
77
79
  ABI_DIR_PATH = Path(__file__).parent / "abis"
78
80
  IMECH_ABI_PATH = ABI_DIR_PATH / "IMech.json"
79
81
  ITOKEN_ABI_PATH = ABI_DIR_PATH / "IToken.json"
@@ -389,6 +391,7 @@ def send_marketplace_request( # pylint: disable=too-many-arguments,too-many-loc
389
391
  def send_offchain_marketplace_request( # pylint: disable=too-many-arguments,too-many-locals
390
392
  crypto: EthereumCrypto,
391
393
  marketplace_contract: Web3Contract,
394
+ mech_offchain_url: str,
392
395
  prompt: str,
393
396
  tool: str,
394
397
  method_args_data: MechMarketplaceRequestConfig,
@@ -405,6 +408,8 @@ def send_offchain_marketplace_request( # pylint: disable=too-many-arguments,too
405
408
  :type crypto: EthereumCrypto
406
409
  :param marketplace_contract: The mech marketplace contract instance.
407
410
  :type marketplace_contract: Web3Contract
411
+ :param mech_offchain_url: mech url to connect to.
412
+ :type mech_offchain_url: str
408
413
  :param prompt: The request prompt.
409
414
  :type prompt: str
410
415
  :param tool: The requested tool.
@@ -469,9 +474,9 @@ def send_offchain_marketplace_request( # pylint: disable=too-many-arguments,too
469
474
  "nonce": nonce,
470
475
  "ipfs_data": ipfs_data,
471
476
  }
472
- # @todo changed hardcoded url
477
+ url = mech_offchain_url + MECH_OFFCHAIN_REQUEST_ENDPOINT
473
478
  response = requests.post(
474
- "http://localhost:8000/send_signed_requests",
479
+ url=url,
475
480
  data=payload,
476
481
  headers={"Content-Type": "application/json"},
477
482
  ).json()
@@ -562,10 +567,12 @@ def wait_for_marketplace_data_url( # pylint: disable=too-many-arguments, unused
562
567
  return result
563
568
 
564
569
 
565
- def wait_for_offchain_marketplace_data(request_id: str) -> Any:
570
+ def wait_for_offchain_marketplace_data(mech_offchain_url: str, request_id: str) -> Any:
566
571
  """
567
572
  Watches for data off-chain on mech.
568
573
 
574
+ :param mech_offchain_url: mech url to connect to.
575
+ :type mech_offchain_url: str
569
576
  :param request_id: The ID of the request.
570
577
  :type request_id: str
571
578
  :return: The data returned by the mech.
@@ -573,15 +580,15 @@ def wait_for_offchain_marketplace_data(request_id: str) -> Any:
573
580
  """
574
581
  while True:
575
582
  try:
576
- # @todo change hardcoded url
583
+ url = mech_offchain_url + MECH_OFFCHAIN_DELIVER_ENDPOINT
577
584
  response = requests.get(
578
- "http://localhost:8000/fetch_offchain_info",
585
+ url=url,
579
586
  data={"request_id": request_id},
580
587
  ).json()
581
588
  if response:
582
589
  return response
583
590
  except Exception: # pylint: disable=broad-except
584
- time.sleep(1)
591
+ time.sleep(WAIT_SLEEP)
585
592
 
586
593
 
587
594
  def check_prepaid_balances(
@@ -638,6 +645,7 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
638
645
  priority_mech: str,
639
646
  use_prepaid: bool = False,
640
647
  use_offchain: bool = False,
648
+ mech_offchain_url: str = "",
641
649
  tools: tuple = (),
642
650
  extra_attributes: Optional[Dict[str, Any]] = None,
643
651
  private_key_path: Optional[str] = None,
@@ -658,6 +666,8 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
658
666
  :type use_prepaid: bool
659
667
  :param use_offchain: Whether to use offchain model or not.
660
668
  :type use_offchain: bool
669
+ :param mech_offchain_url: mech url to connect to.
670
+ :type mech_offchain_url: str
661
671
  :param tools: The tools to interact with (optional).
662
672
  :type tools: tuple
663
673
  :param extra_attributes: Extra attributes to be included in the request metadata (optional).
@@ -882,6 +892,7 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
882
892
  response = send_offchain_marketplace_request(
883
893
  crypto=crypto,
884
894
  marketplace_contract=mech_marketplace_contract,
895
+ mech_offchain_url=mech_offchain_url,
885
896
  prompt=prompts[0],
886
897
  tool=tools[0],
887
898
  method_args_data=mech_marketplace_request_config,
@@ -910,6 +921,7 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
910
921
 
911
922
  for request_id in request_ids:
912
923
  data = wait_for_offchain_marketplace_data(
924
+ mech_offchain_url=mech_offchain_url,
913
925
  request_id=request_id,
914
926
  )
915
927
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mech-client
3
- Version: 0.8.2
3
+ Version: 0.9.0
4
4
  Summary: Basic client to interact with a mech
5
5
  License: Apache-2.0
6
6
  Author: David Minarsch
@@ -237,6 +237,16 @@ Additionally to other options which are the same as for legacy Mechs, this usage
237
237
 
238
238
  `--use-prepaid <bool>`: use the prepaid method to send requests to a Mech via the Mech Marketplace. Defaults to False. <br>
239
239
  `--use-offchain <bool>`: use the off-chain method to send requests to a Mech via the Mech Marketplace. Defaults to False.
240
+ > To use offchain requests using `--use-offchain` flag, export the `MECHX_MECH_OFFCHAIN_URL` env variable before sending requests. For example if you want to connect to a mech running locally, you can do the following
241
+ ```bash
242
+ export MECHX_MECH_OFFCHAIN_URL="http://localhost:8000/"
243
+ ```
244
+ If you want to use a Valory mech for offchain requests, below is the list of mechs and their address and offchain urls.
245
+
246
+ | Service ID | Priority Mech Address | Offchain URL |
247
+ | :---: | :---: | :---: |
248
+ | 2182 | 0xB3C6319962484602b00d5587e965946890b82101 | https://d19715222af5b940.agent.propel.autonolas.tech/ |
249
+
240
250
 
241
251
  The Mech Client can also be used to send batch requests. There are couple of different ways to achieve this:
242
252
 
@@ -1,4 +1,4 @@
1
- mech_client/__init__.py,sha256=Pkp7D9ID9xxFUuGrdGofoB2cTeMVMTpQeST3H0GcIps,42
1
+ mech_client/__init__.py,sha256=Ed2swOIv8MmttDlcU_lXntd4MDQZ75GbLzEVhuhi_3o,42
2
2
  mech_client/abis/AgentMech.json,sha256=IEbs_xBGunBu5h-uT5DvIty8Zw412QoPI46S_DUMYNw,18082
3
3
  mech_client/abis/AgentRegistry.json,sha256=2qmXeFINZWz9pyOma6Bq67kMDSUI1lD7WvgHLwuETD8,24723
4
4
  mech_client/abis/AgreementStoreManager.base.json,sha256=_ljdIZcfFGmFzBHUTfhA4X0382ZHHpkdr_CziTwUETo,34360
@@ -30,7 +30,7 @@ mech_client/abis/SubscriptionToken.base.json,sha256=5StPEyfRvDMTqtQPO-KakXXZqobX
30
30
  mech_client/abis/TransferNFTCondition.base.json,sha256=71O_3itHBz9qPtoTLev8_a7KxlcQfIZSfxK2562lkqw,42540
31
31
  mech_client/abis/TransferNFTCondition.gnosis.json,sha256=-huhxV54eoNY8mR9WtQdmSgQDgaKiUi0PULJ4HEshWw,42540
32
32
  mech_client/acn.py,sha256=Rj_jLPvJ5loDQfGbu3a_O24cJC4SwIErLceSz_zVYS8,5356
33
- mech_client/cli.py,sha256=XezX27Y0VdnUq8HmHF6HxyhPmsC91YuLSuqAoi41UrE,17655
33
+ mech_client/cli.py,sha256=CgpembCl3JTubCgUYw7-one6cuge8YlUTHfoIkhbZu4,17957
34
34
  mech_client/configs/mechs.json,sha256=Zv8JrY6yvNsSxTP7RchvR1yz2k3yjYUZkuSILnPbWzg,5445
35
35
  mech_client/fetch_ipfs_hash.py,sha256=tg_hYVf4deXl89x3SOBrGFUthaSeN_Vg_OHDtfjdbp4,2752
36
36
  mech_client/helpers/__init__.py,sha256=nmQig1EqBQ9EMOpgdykP3a6_2NWcoVH3-lnyHP5n0ws,1196
@@ -62,7 +62,7 @@ mech_client/helpers/p2p_libp2p_client/__init__.py,sha256=-GOP3D_JnmXTDomrMLCbnRk
62
62
  mech_client/helpers/p2p_libp2p_client/connection.py,sha256=b5jfcUeSoNrUw8DOSTCbK4DTi-N8bf2_pdogUOz0ep0,28606
63
63
  mech_client/helpers/p2p_libp2p_client/connection.yaml,sha256=nMiHnU_dv9EFjVNqZ-0SAnoATfadJSad-JsbDvk97Mk,1790
64
64
  mech_client/interact.py,sha256=52UW5NysSTIC--APLpJde8VvrruWeYFCFzO02uRQpwc,21288
65
- mech_client/marketplace_interact.py,sha256=rRIHYLzuaXYW7vh4fvNh9KBbUY4tgoavmMxFaPg0Rkw,33045
65
+ mech_client/marketplace_interact.py,sha256=7K-xb4Bg9UrWs3U_xXIRibnfBjCaRG4XZyeAi-nO6BU,33591
66
66
  mech_client/mech_marketplace_tool_management.py,sha256=q_cXyJGI1rLXKB_Ds21eQLCzUhTYE9BHN48wqIw0w6g,7341
67
67
  mech_client/mech_tool_management.py,sha256=NQFmVzzGZsIkeHokDPWXGHwa8u-pyQIMPR1Q5H81bKw,7806
68
68
  mech_client/prompt_to_ipfs.py,sha256=XqSIBko15MEkpWOQNT97fRI6jNxMF5EDBDEPOJFdhyk,2533
@@ -92,8 +92,8 @@ scripts/nvm_subscription/manager.py,sha256=y0Qh0aVAmOPB4Ytt93alIarSvhrQpC-lRYNAY
92
92
  scripts/nvm_subscription/resources/networks.json,sha256=xH0P3YkgkMTkQdahVKO0kI9m6ybJ67iwHApstUlfRmw,2359
93
93
  scripts/utils.py,sha256=lXjY3s1HvNHT2fXm2fBpZtVvlQaqW288Y2S-s3rpSDM,3248
94
94
  scripts/whitelist.py,sha256=-TF4fcojBmF6a7fXleBk96DvJ-xWkNGoN0s_8r8J20Q,289
95
- mech_client-0.8.2.dist-info/LICENSE,sha256=mdBDB-mWKV5Cz4ejBzBiKqan6Z8zVLAh9xwM64O2FW4,11339
96
- mech_client-0.8.2.dist-info/METADATA,sha256=SUPx34q_S9D-15xJ8rGTgwPTBiZ7VL5VvBCkWKayBPA,25165
97
- mech_client-0.8.2.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
98
- mech_client-0.8.2.dist-info/entry_points.txt,sha256=SbRMRsayzD8XfNXhgwPuXEqQsdZ5Bw9XDPnUuaDExyY,45
99
- mech_client-0.8.2.dist-info/RECORD,,
95
+ mech_client-0.9.0.dist-info/LICENSE,sha256=mdBDB-mWKV5Cz4ejBzBiKqan6Z8zVLAh9xwM64O2FW4,11339
96
+ mech_client-0.9.0.dist-info/METADATA,sha256=S5aSBEHrmFl-Az-VGwdqRQEtp2OQ2DN8jPPOXvYsYfM,25935
97
+ mech_client-0.9.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
98
+ mech_client-0.9.0.dist-info/entry_points.txt,sha256=SbRMRsayzD8XfNXhgwPuXEqQsdZ5Bw9XDPnUuaDExyY,45
99
+ mech_client-0.9.0.dist-info/RECORD,,