mech-client 0.2.21__py3-none-any.whl → 0.3.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/wss.py CHANGED
@@ -143,6 +143,36 @@ def watch_for_request_id( # pylint: disable=too-many-arguments
143
143
  return request_id
144
144
 
145
145
 
146
+ def watch_for_marketplace_request_id( # pylint: disable=too-many-arguments, unused-argument
147
+ marketplace_contract: Web3Contract,
148
+ ledger_api: EthereumApi,
149
+ tx_hash: str,
150
+ ) -> str:
151
+ """
152
+ Watches for events on mech.
153
+
154
+ :param marketplace_contract: The marketplace contract instance.
155
+ :type marketplace_contract: Web3Contract
156
+ :param ledger_api: The Ethereum API used for interacting with the ledger.
157
+ :type ledger_api: EthereumApi
158
+ :param tx_hash: Tx hash to wait for
159
+ :type tx_hash: str
160
+ :return: The requested ID.
161
+ :rtype: str
162
+ """
163
+ while True:
164
+ tx_receipt = wait_for_receipt(tx_hash=tx_hash, ledger_api=ledger_api)
165
+
166
+ rich_logs = marketplace_contract.events.MarketplaceRequest().process_receipt(
167
+ tx_receipt
168
+ )
169
+ if len(rich_logs) == 0:
170
+ return "Empty Logs"
171
+
172
+ request_id = rich_logs[0]["args"]["requestIds"][0]
173
+ return request_id.hex()
174
+
175
+
146
176
  async def watch_for_data_url_from_wss( # pylint: disable=too-many-arguments
147
177
  request_id: str,
148
178
  wss: websocket.WebSocket,
@@ -193,3 +223,62 @@ async def watch_for_data_url_from_wss( # pylint: disable=too-many-arguments
193
223
  "Error: The WSS connection was likely closed by the remote party. Please, try using another WSS provider."
194
224
  )
195
225
  return None
226
+
227
+
228
+ async def watch_for_marketplace_data_url_from_wss( # pylint: disable=too-many-arguments, unused-argument
229
+ request_id: str,
230
+ wss: websocket.WebSocket,
231
+ mech_contract: Web3Contract,
232
+ deliver_signature: str,
233
+ ledger_api: EthereumApi,
234
+ loop: asyncio.AbstractEventLoop,
235
+ ) -> Any:
236
+ """
237
+ Watches for data on-chain.
238
+
239
+ :param request_id: The ID of the request.
240
+ :type request_id: str
241
+ :param wss: The WebSocket connection object.
242
+ :type wss: websocket.WebSocket
243
+ :param mech_contract: The mech contract instance.
244
+ :type mech_contract: Web3Contract
245
+ :param deliver_signature: Topic signature for Deliver event
246
+ :type deliver_signature: str
247
+ :param ledger_api: The Ethereum API used for interacting with the ledger.
248
+ :type ledger_api: EthereumApi
249
+ :param loop: The event loop used for asynchronous operations.
250
+ :type loop: asyncio.AbstractEventLoop
251
+ :return: The data received from on-chain.
252
+ :rtype: Any
253
+ """
254
+ with ThreadPoolExecutor() as executor:
255
+ try:
256
+ while True:
257
+ msg = await loop.run_in_executor(executor=executor, func=wss.recv)
258
+ data = json.loads(msg)
259
+ tx_hash = data["params"]["result"]["transactionHash"]
260
+ tx_receipt = await loop.run_in_executor(
261
+ executor, wait_for_receipt, tx_hash, ledger_api
262
+ )
263
+
264
+ rich_logs = mech_contract.events.Deliver().process_receipt(tx_receipt)
265
+ if len(rich_logs) == 0:
266
+ print("Empty logs")
267
+ return None
268
+
269
+ data = rich_logs[0]["args"]
270
+ tx_request_id = data["requestId"]
271
+ deliver_data = data["data"]
272
+
273
+ if request_id != tx_request_id.hex():
274
+ continue
275
+
276
+ return (
277
+ f"https://gateway.autonolas.tech/ipfs/f01701220{deliver_data.hex()}"
278
+ )
279
+ except websocket.WebSocketConnectionClosedException as e:
280
+ print(f"WebSocketConnectionClosedException {repr(e)}")
281
+ print(
282
+ "Error: The WSS connection was likely closed by the remote party. Please, try using another WSS provider."
283
+ )
284
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mech-client
3
- Version: 0.2.21
3
+ Version: 0.3.0
4
4
  Summary: Basic client to interact with a mech
5
5
  License: Apache-2.0
6
6
  Author: David Minarsch
@@ -16,7 +16,6 @@ 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 (>=75.8.0,<76.0.0)
20
19
  Requires-Dist: tabulate (>=0.9.0,<0.10.0)
21
20
  Requires-Dist: websocket-client (>=0.32.0,<1)
22
21
  Description-Content-Type: text/markdown
@@ -118,14 +117,33 @@ The EOA you use must have enough funds to pay for the Mech requests, or alternat
118
117
 
119
118
  ### Select the mech you are going to send requests to
120
119
 
121
- 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).
120
+ Mechs can receive requests via the [Mech Marketplace](https://github.com/valory-xyz/ai-registry-mech/) or directly. We call the last ones _Legacy Mechs_.
121
+ Mechs are deployed on several networks. Find the list of supported networks and corresponding mech addresses [here](https://github.com/valory-xyz/mech?tab=readme-ov-file#examples-of-deployed-mechs). Additionally, on Gnosis you can find more available Mechs [here](https://mech.olas.network/) (click on the tab "Legacy Mech" in order to see Legacy Mech and "Mech Marketplace" for the ones which receive requests via the Mech Marketplace).
122
+
123
+
124
+ ### API Keys
125
+
126
+ In order to fetch on-chain data for Gnosis and Base, mech client requires an API key from a blockchain data provider. You can find them here for [GnosisScan](https://gnosisscan.io/) and [BaseScan](https://basescan.org/). Follow these steps to generate your API key if you are planning to use mech client for gnosis and base:
127
+
128
+ 1. Sign up or log in
129
+ 2. Go to API Dashboard on the left menu
130
+ 3. Add a new API key
131
+ 4. Once generated copy your API key
132
+
133
+ Once you have your API key, you'll need to configure it in your environment. Use the following command to set it for your environment.
134
+
135
+ ```bash
136
+ export MECHX_API_KEY=<your api key>
137
+ ```
122
138
 
123
139
  ### Generate Mech requests
124
140
 
141
+ #### Legacy Mechs
142
+
125
143
  The basic usage of the Mech Client is as follows:
126
144
 
127
145
  ```bash
128
- mechx interact <prompt> <agent_id>
146
+ mechx interact <prompt> --agent_id <agent_id>
129
147
  ```
130
148
 
131
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).
@@ -164,7 +182,7 @@ Some useful options:
164
182
  Example of a request specifying a key file and tool:
165
183
 
166
184
  ```bash
167
- mechx interact "write a short poem" 6 --key ~/ethereum_private_key.txt --tool openai-gpt-3.5-turbo --chain-config gnosis --confirm on-chain
185
+ mechx interact "write a short poem" --agent_id 6 --key ~/ethereum_private_key.txt --tool openai-gpt-3.5-turbo --chain-config gnosis --confirm on-chain
168
186
  ```
169
187
 
170
188
  You will see an output like this:
@@ -179,6 +197,24 @@ Data arrived: https://gateway.autonolas.tech/ipfs/f01701220a462120d5bb03f406fa5e
179
197
  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'}}
180
198
  ```
181
199
 
200
+ #### With the Mech Marketplace
201
+
202
+ With the Mech Marketplace, the basic usage of the Mech Client is as follows.
203
+
204
+ ```bash
205
+ mechx interact <prompt> --tool openai-gpt-3.5-turbo --chain-config <chain_config>
206
+ ```
207
+
208
+ To use a custom mech to send requests to, use the `priority-mech` flag while sending the requests
209
+
210
+ ```bash
211
+ mechx interact <prompt> --priority-mech <priority mech address> --tool openai-gpt-3.5-turbo --chain-config <chain_config>
212
+ ```
213
+
214
+ Additionally to other options which are the same as for legacy Mechs, this usage has the following option:
215
+
216
+ `--use-prepaid <bool>`: use the prepaid method to send requests to a Mech via the Mech Marketplace. Defaults to False.
217
+ `--use-offchain <bool>`: use the off-chain method to send requests to a Mech via the Mech Marketplace. Defaults to False.
182
218
 
183
219
  ### List tools available for agents
184
220
 
@@ -290,6 +326,8 @@ Output Schema:
290
326
 
291
327
  ### Chain configuration
292
328
 
329
+ #### For legacy Mechs
330
+
293
331
  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.
294
332
 
295
333
  Additionally, you can override any configuration parameter by exporting any of the following environment variables:
@@ -382,6 +420,11 @@ This script will:
382
420
  - Retrieve and display the description of a specific tool using its unique identifier.
383
421
  - Retrieve and display the input and output schema of a specific tool using its unique identifier.
384
422
 
423
+ #### For Mechs receiving requests via the Mech Marketplace
424
+
425
+ In this case, the script is the same, except for the function result. When this function has no argument agent_id,
426
+ the request is sent to the Mech Marketplace. The target Mech to which the request is relayed should be in the chain_config file (key `priority_mech_address`).
427
+
385
428
  ## Developer installation
386
429
 
387
430
  To setup the development environment for this project, clone the repository and run the following commands:
@@ -1,8 +1,16 @@
1
- mech_client/__init__.py,sha256=XYldmBbSu5oGgmBiVbWa2eQ1MXbFxzTpbi9zVl9wt5c,43
1
+ mech_client/__init__.py,sha256=Fv_rB4SSlUfKkC4yVa0VynPADc604qwxEG5c-jAgNic,42
2
+ mech_client/abis/BalanceTrackerFixedPriceNative.json,sha256=MF5jDqSMoZztvMV4oc5ij-Qn1DAZ1Nyz9EOFRb9wSQ0,12478
3
+ mech_client/abis/BalanceTrackerFixedPriceToken.json,sha256=kaXgResUkAb6u9bVTS3T_SNRPRP76hi-jTAhMiYwq4U,12408
4
+ mech_client/abis/BalanceTrackerNvmSubscriptionNative.json,sha256=D23ibyhDsn4vjozFvzcKw-7wJpGM-R5GiqlcmyBIpcY,16536
5
+ mech_client/abis/IERC1155.json,sha256=2xOx44MrKRk5oDEZ8PhCUgW7A4puK-GQizPKff-Fn1E,7459
6
+ mech_client/abis/IMech.json,sha256=km0NMRyqBYh3jBQwPJCispsRfPwqNJ67kkZwYjuJci4,3989
7
+ mech_client/abis/IToken.json,sha256=VrzR6Rr1DmrUzy5DygN1rKm6df4ir2KGdWsunZnuRKo,19637
8
+ mech_client/abis/MechMarketplace.json,sha256=auKTxPTi07yD98Gz2RuwH1Gq5qRCyy8-C7QBNj3uto8,32104
2
9
  mech_client/acn.py,sha256=Rj_jLPvJ5loDQfGbu3a_O24cJC4SwIErLceSz_zVYS8,5356
3
- mech_client/cli.py,sha256=cJ3QAP29QsbsyITVZbCVxZ7378ql2VPaEjar9Iotj0U,9555
4
- mech_client/configs/mechs.json,sha256=PssCmIWetrZaC5v1hD0ynSqc53VG2kIXxLLMOQjWeNE,4727
5
- mech_client/helpers/__init__.py,sha256=f13zpwGDaKQUjML-5Iq66rRfzg8IS5UNK5I8gBr7w54,1028
10
+ mech_client/cli.py,sha256=PWkUBwirP8DMxNG-lYmh-QAJhNPX_k6yCtfjTh7iXs8,11322
11
+ mech_client/configs/mechs.json,sha256=ihF23WakBh1Jbnb45OJvPjDzZ572eud3s0Gx4qNGWwQ,5699
12
+ mech_client/fetch_ipfs_hash.py,sha256=tg_hYVf4deXl89x3SOBrGFUthaSeN_Vg_OHDtfjdbp4,2752
13
+ mech_client/helpers/__init__.py,sha256=nmQig1EqBQ9EMOpgdykP3a6_2NWcoVH3-lnyHP5n0ws,1196
6
14
  mech_client/helpers/acn/README.md,sha256=WMXR2Lk0IpWjr3vpZ8cxcTHk4gwsx4wC06UPkwj9dbQ,1641
7
15
  mech_client/helpers/acn/__init__.py,sha256=3Yd1hUTcrtp0Kb1VmnOTC3_r-_69ozhzMqLlkNC6MkU,1141
8
16
  mech_client/helpers/acn/acn.proto,sha256=Ev0f8tQJjnTaK-mdpNLItVRgJ7VibtCeGBTcKz8nfX4,1543
@@ -30,15 +38,16 @@ mech_client/helpers/p2p_libp2p_client/README.md,sha256=6x9s6P7TdKkcvAS1wMFHXRz4a
30
38
  mech_client/helpers/p2p_libp2p_client/__init__.py,sha256=-GOP3D_JnmXTDomrMLCbnRk7vRQmihIqTYvyIPzx-q4,879
31
39
  mech_client/helpers/p2p_libp2p_client/connection.py,sha256=b5jfcUeSoNrUw8DOSTCbK4DTi-N8bf2_pdogUOz0ep0,28606
32
40
  mech_client/helpers/p2p_libp2p_client/connection.yaml,sha256=nMiHnU_dv9EFjVNqZ-0SAnoATfadJSad-JsbDvk97Mk,1790
33
- mech_client/interact.py,sha256=Paf8kne8sQbvEiCsiN9qC6sZWNqZqD1npVaOfT9vR6k,21219
41
+ mech_client/interact.py,sha256=zQ7UhlnZOfM4hnZBaRQ5efkfw6Rl-s7Kh6lciyoZL70,22028
42
+ mech_client/marketplace_interact.py,sha256=DgDU1xY2zJO3MfxkWNFtJ8iZkjGBfP8MYL4vAEDRKWE,31418
34
43
  mech_client/mech_tool_management.py,sha256=XWQDcFStTK66-3ZzOwKtMo5c66KDjvbeDsIXHIP4SuU,7810
35
44
  mech_client/prompt_to_ipfs.py,sha256=XqSIBko15MEkpWOQNT97fRI6jNxMF5EDBDEPOJFdhyk,2533
36
45
  mech_client/push_to_ipfs.py,sha256=IfvgaPU79N_ZmCPF9d7sPCYz2uduZH0KjT_HQ2LHXoQ,2059
37
46
  mech_client/subgraph.py,sha256=6hkF8l0qxWRJ0UcdxfML6JnjYBu5BuBA6EHsHJ2nHVI,5149
38
47
  mech_client/to_png.py,sha256=pjUcFJ63MJj_r73eqnfqCWMtlpsrj6H4ZmgvIEmRcFw,2581
39
- mech_client/wss.py,sha256=hRInQjjsyOrs8dmgBb2VpJvpNt6Tx0aEiY3OhOPQvIs,6600
40
- mech_client-0.2.21.dist-info/LICENSE,sha256=mdBDB-mWKV5Cz4ejBzBiKqan6Z8zVLAh9xwM64O2FW4,11339
41
- mech_client-0.2.21.dist-info/METADATA,sha256=cPQGseRA8LKUQVnkmtHx5Fifs1YijfTMK7AJ3GMW76k,17727
42
- mech_client-0.2.21.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
43
- mech_client-0.2.21.dist-info/entry_points.txt,sha256=SbRMRsayzD8XfNXhgwPuXEqQsdZ5Bw9XDPnUuaDExyY,45
44
- mech_client-0.2.21.dist-info/RECORD,,
48
+ mech_client/wss.py,sha256=toD_9-gNsQAoK13Zh5mQCKbmkT2Gcqz5XaNiUGyb5Js,9801
49
+ mech_client-0.3.0.dist-info/LICENSE,sha256=mdBDB-mWKV5Cz4ejBzBiKqan6Z8zVLAh9xwM64O2FW4,11339
50
+ mech_client-0.3.0.dist-info/METADATA,sha256=2YFbNhpBXix_HZBGf-CSW7wspGdH53EQjqWjUK6PBLc,19911
51
+ mech_client-0.3.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
52
+ mech_client-0.3.0.dist-info/entry_points.txt,sha256=SbRMRsayzD8XfNXhgwPuXEqQsdZ5Bw9XDPnUuaDExyY,45
53
+ mech_client-0.3.0.dist-info/RECORD,,