opengradient 0.4.11__py3-none-any.whl → 0.4.12b1__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.
opengradient/client.py CHANGED
@@ -298,26 +298,7 @@ class Client:
298
298
 
299
299
  run_function = contract.functions.run(model_cid, inference_mode_uint8, converted_model_input)
300
300
 
301
- nonce = self._blockchain.eth.get_transaction_count(self._wallet_account.address, "pending")
302
- estimated_gas = run_function.estimate_gas({"from": self._wallet_account.address})
303
- gas_limit = int(estimated_gas * 3)
304
-
305
- transaction = run_function.build_transaction(
306
- {
307
- "from": self._wallet_account.address,
308
- "nonce": nonce,
309
- "gas": gas_limit,
310
- "gasPrice": self._blockchain.eth.gas_price,
311
- }
312
- )
313
-
314
- signed_tx = self._wallet_account.sign_transaction(transaction)
315
- tx_hash = self._blockchain.eth.send_raw_transaction(signed_tx.raw_transaction)
316
- tx_receipt = self._blockchain.eth.wait_for_transaction_receipt(tx_hash, timeout=INFERENCE_TX_TIMEOUT)
317
-
318
- if tx_receipt["status"] == 0:
319
- raise ContractLogicError(f"Transaction failed. Receipt: {tx_receipt}")
320
-
301
+ tx_hash, tx_receipt = self._send_tx_with_revert_handling(run_function)
321
302
  parsed_logs = contract.events.InferenceResult().process_receipt(tx_receipt, errors=DISCARD)
322
303
  if len(parsed_logs) < 1:
323
304
  raise OpenGradientError("InferenceResult event not found in transaction logs")
@@ -382,27 +363,7 @@ class Client:
382
363
 
383
364
  run_function = contract.functions.runLLMCompletion(llm_request)
384
365
 
385
- nonce = self._blockchain.eth.get_transaction_count(self._wallet_account.address, "pending")
386
- estimated_gas = run_function.estimate_gas({"from": self._wallet_account.address})
387
- # Artificially increase required gas for safety
388
- gas_limit = int(estimated_gas * 1.5)
389
-
390
- transaction = run_function.build_transaction(
391
- {
392
- "from": self._wallet_account.address,
393
- "nonce": nonce,
394
- "gas": gas_limit,
395
- "gasPrice": self._blockchain.eth.gas_price,
396
- }
397
- )
398
-
399
- signed_tx = self._wallet_account.sign_transaction(transaction)
400
- tx_hash = self._blockchain.eth.send_raw_transaction(signed_tx.raw_transaction)
401
- tx_receipt = self._blockchain.eth.wait_for_transaction_receipt(tx_hash, timeout=LLM_TX_TIMEOUT)
402
-
403
- if tx_receipt["status"] == 0:
404
- raise ContractLogicError(f"Transaction failed. Receipt: {tx_receipt}")
405
-
366
+ tx_hash, tx_receipt = self._send_tx_with_revert_handling(run_function)
406
367
  parsed_logs = contract.events.LLMCompletionResult().process_receipt(tx_receipt, errors=DISCARD)
407
368
  if len(parsed_logs) < 1:
408
369
  raise OpenGradientError("LLM completion result event not found in transaction logs")
@@ -534,27 +495,7 @@ class Client:
534
495
 
535
496
  run_function = contract.functions.runLLMChat(llm_request)
536
497
 
537
- nonce = self._blockchain.eth.get_transaction_count(self._wallet_account.address, "pending")
538
- estimated_gas = run_function.estimate_gas({"from": self._wallet_account.address})
539
- # Artificially increase required gas for safety
540
- gas_limit = int(estimated_gas * 1.5)
541
-
542
- transaction = run_function.build_transaction(
543
- {
544
- "from": self._wallet_account.address,
545
- "nonce": nonce,
546
- "gas": gas_limit,
547
- "gasPrice": self._blockchain.eth.gas_price,
548
- }
549
- )
550
-
551
- signed_tx = self._wallet_account.sign_transaction(transaction)
552
- tx_hash = self._blockchain.eth.send_raw_transaction(signed_tx.raw_transaction)
553
- tx_receipt = self._blockchain.eth.wait_for_transaction_receipt(tx_hash, timeout=LLM_TX_TIMEOUT)
554
-
555
- if tx_receipt["status"] == 0:
556
- raise ContractLogicError(f"Transaction failed. Receipt: {tx_receipt}")
557
-
498
+ tx_hash, tx_receipt = self._send_tx_with_revert_handling(run_function)
558
499
  parsed_logs = contract.events.LLMChatResult().process_receipt(tx_receipt, errors=DISCARD)
559
500
  if len(parsed_logs) < 1:
560
501
  raise OpenGradientError("LLM chat result event not found in transaction logs")
@@ -752,6 +693,58 @@ class Client:
752
693
  bytecode = "0x" + bytecode
753
694
  return bytecode
754
695
 
696
+ def _send_tx_with_revert_handling(self, run_function):
697
+ """
698
+ Execute a blockchain transaction with revert error.
699
+
700
+ Args:
701
+ run_function: Function that executes the transaction
702
+
703
+ Returns:
704
+ tx_hash: Transaction hash
705
+ tx_receipt: Transaction receipt
706
+
707
+ Raises:
708
+ Exception: If transaction fails or gas estimation fails
709
+ """
710
+ nonce = self._blockchain.eth.get_transaction_count(self._wallet_account.address, "pending")
711
+ try:
712
+ estimated_gas = run_function.estimate_gas({"from": self._wallet_account.address})
713
+ except ContractLogicError as e:
714
+ try:
715
+ run_function.call({"from": self._wallet_account.address})
716
+
717
+ except ContractLogicError as call_err:
718
+ raise ContractLogicError(f"simulation failed with revert reason: {call_err.args[0]}")
719
+
720
+ raise ContractLogicError(f"simulation failed with no revert reason. Reason: {e}")
721
+
722
+ gas_limit = int(estimated_gas * 3)
723
+
724
+ transaction = run_function.build_transaction(
725
+ {
726
+ "from": self._wallet_account.address,
727
+ "nonce": nonce,
728
+ "gas": gas_limit,
729
+ "gasPrice": self._blockchain.eth.gas_price,
730
+ }
731
+ )
732
+
733
+ signed_tx = self._wallet_account.sign_transaction(transaction)
734
+ tx_hash = self._blockchain.eth.send_raw_transaction(signed_tx.raw_transaction)
735
+ tx_receipt = self._blockchain.eth.wait_for_transaction_receipt(tx_hash, timeout=INFERENCE_TX_TIMEOUT)
736
+
737
+ if tx_receipt["status"] == 0:
738
+ try:
739
+ run_function.call({"from": self._wallet_account.address})
740
+
741
+ except ContractLogicError as call_err:
742
+ raise ContractLogicError(f"Transaction failed with revert reason: {call_err.args[0]}")
743
+
744
+ raise ContractLogicError(f"Transaction failed with no revert reason. Receipt: {tx_receipt}")
745
+
746
+ return tx_hash, tx_receipt
747
+
755
748
  def new_workflow(
756
749
  self,
757
750
  model_cid: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opengradient
3
- Version: 0.4.11
3
+ Version: 0.4.12b1
4
4
  Summary: Python SDK for OpenGradient decentralized model management & inference services
5
5
  Author-email: OpenGradient <oliver@opengradient.ai>
6
6
  License: MIT License
@@ -35,8 +35,10 @@ Classifier: Programming Language :: Python :: 3.12
35
35
  Requires-Python: >=3.10
36
36
  Description-Content-Type: text/markdown
37
37
  License-File: LICENSE
38
- Requires-Dist: eth-account>=0.13.4
39
- Requires-Dist: web3>=7.3.0
38
+ Requires-Dist: eth-utils==2.2.2
39
+ Requires-Dist: eth-account>=0.13.0
40
+ Requires-Dist: web3>=6.11
41
+ Requires-Dist: websockets>=14.1
40
42
  Requires-Dist: click>=8.1.7
41
43
  Requires-Dist: firebase-rest-api>=1.11.0
42
44
  Requires-Dist: grpcio>=1.66.2
@@ -1,7 +1,7 @@
1
1
  opengradient/__init__.py,sha256=jNQwQmGa3r8BaPZP01mNwmhOU-16ggqUR4D2U4VrRZw,12422
2
2
  opengradient/account.py,sha256=5wrYpws_1lozjOFjLCTHtxgoxK-LmObDAaVy9eDcJY4,1145
3
3
  opengradient/cli.py,sha256=12fezJJvuceUaPSllsMqrBFoSpd2sTJjMpZ1_Dhzskg,25426
4
- opengradient/client.py,sha256=eXgWtYlocXh89XwbtxSZlCqffgN-ll_dszwdZxsH634,43991
4
+ opengradient/client.py,sha256=fK7gEckQxjkK8T6-xaNp8Z4wJXbMgkfSJV39mUGaGMw,43315
5
5
  opengradient/defaults.py,sha256=ecGPGh2l-33ef2CTDDD_tvSSe_Qf8zYdIOjowjBqZCo,498
6
6
  opengradient/exceptions.py,sha256=88tfegboGtlehQcwhxsl6ZzhLJWZWlkf_bkHTiCtXpo,3391
7
7
  opengradient/types.py,sha256=JH8hjpcq4H7gQki74cuJpH4PcyQpwivLiqn9iq0evrI,5715
@@ -26,9 +26,9 @@ opengradient/workflow_models/constants.py,sha256=viIkb_LGcfVprqQNaA80gBTj6cfYam0
26
26
  opengradient/workflow_models/types.py,sha256=Z22hF6c8Y4D2GlzVEIBODGwsqSjSrQvUcpZ7R-mIJdI,409
27
27
  opengradient/workflow_models/utils.py,sha256=ySfpuiOBqLTlfto6ZxZf2vc7K6RGIja0l4eaVm5AOzY,1503
28
28
  opengradient/workflow_models/workflow_models.py,sha256=d4C_gs39DAfy4cdY9Ee6GMXpPfzwvKFpmxzK1A7LNgU,3900
29
- opengradient-0.4.11.dist-info/licenses/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
30
- opengradient-0.4.11.dist-info/METADATA,sha256=o6x7HxutNOT72WWcuCwBiaEzuYElReEerNinjsVCGSk,5237
31
- opengradient-0.4.11.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
32
- opengradient-0.4.11.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
33
- opengradient-0.4.11.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
34
- opengradient-0.4.11.dist-info/RECORD,,
29
+ opengradient-0.4.12b1.dist-info/licenses/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
30
+ opengradient-0.4.12b1.dist-info/METADATA,sha256=E1xc6YqpEn9eSlIpwbAyUHyShz1JMX4paeBYsbOcHqQ,5302
31
+ opengradient-0.4.12b1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
32
+ opengradient-0.4.12b1.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
33
+ opengradient-0.4.12b1.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
34
+ opengradient-0.4.12b1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.3)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5