opengradient 0.3.21__py3-none-any.whl → 0.3.23__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/__init__.py +94 -7
- opengradient/abi/ModelExecutorHistorical.abi +1 -0
- opengradient/cli.py +0 -1
- opengradient/client.py +207 -14
- opengradient/contracts/templates/ModelExecutorHistorical.bin +1 -0
- opengradient/types.py +64 -3
- {opengradient-0.3.21.dist-info → opengradient-0.3.23.dist-info}/METADATA +1 -1
- {opengradient-0.3.21.dist-info → opengradient-0.3.23.dist-info}/RECORD +12 -10
- {opengradient-0.3.21.dist-info → opengradient-0.3.23.dist-info}/LICENSE +0 -0
- {opengradient-0.3.21.dist-info → opengradient-0.3.23.dist-info}/WHEEL +0 -0
- {opengradient-0.3.21.dist-info → opengradient-0.3.23.dist-info}/entry_points.txt +0 -0
- {opengradient-0.3.21.dist-info → opengradient-0.3.23.dist-info}/top_level.txt +0 -0
opengradient/__init__.py
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"""
|
|
2
2
|
OpenGradient Python SDK for interacting with AI models and infrastructure.
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
|
-
from
|
|
6
|
-
|
|
4
|
+
from typing import Dict, List, Optional, Tuple, Any, Union
|
|
5
|
+
from pathlib import Path
|
|
7
6
|
from .client import Client
|
|
8
7
|
from .defaults import DEFAULT_INFERENCE_CONTRACT_ADDRESS, DEFAULT_RPC_URL
|
|
9
|
-
from .types import InferenceMode, LlmInferenceMode, LLM, TEE_LLM
|
|
10
|
-
|
|
8
|
+
from .types import HistoricalInputQuery, InferenceMode, LlmInferenceMode, LLM, TEE_LLM, SchedulerParams
|
|
11
9
|
from . import llm
|
|
12
10
|
from . import mltools
|
|
13
11
|
|
|
@@ -28,7 +26,15 @@ def init(email: str,
|
|
|
28
26
|
contract_address: Optional inference contract address
|
|
29
27
|
"""
|
|
30
28
|
global _client
|
|
31
|
-
|
|
29
|
+
|
|
30
|
+
_client = Client(
|
|
31
|
+
private_key=private_key,
|
|
32
|
+
rpc_url=rpc_url,
|
|
33
|
+
email=email,
|
|
34
|
+
password=password,
|
|
35
|
+
contract_address=contract_address
|
|
36
|
+
)
|
|
37
|
+
return _client
|
|
32
38
|
|
|
33
39
|
def upload(model_path, model_name, version):
|
|
34
40
|
"""Upload a model file to OpenGradient.
|
|
@@ -239,6 +245,84 @@ def generate_image(model: str, prompt: str, height: Optional[int] = None, width:
|
|
|
239
245
|
raise RuntimeError("OpenGradient client not initialized. Call og.init() first.")
|
|
240
246
|
return _client.generate_image(model, prompt, height=height, width=width)
|
|
241
247
|
|
|
248
|
+
def new_workflow(
|
|
249
|
+
model_cid: str,
|
|
250
|
+
input_query: Union[Dict[str, Any], HistoricalInputQuery],
|
|
251
|
+
input_tensor_name: str,
|
|
252
|
+
scheduler_params: Optional[Union[Dict[str, int], SchedulerParams]] = None
|
|
253
|
+
) -> str:
|
|
254
|
+
"""
|
|
255
|
+
Deploy a new workflow contract with the specified parameters.
|
|
256
|
+
|
|
257
|
+
This function deploys a new workflow contract and optionally registers it with
|
|
258
|
+
the scheduler for automated execution. If scheduler_params is not provided,
|
|
259
|
+
the workflow will be deployed without automated execution scheduling.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
model_cid: IPFS CID of the model
|
|
263
|
+
input_query: Dictionary or HistoricalInputQuery containing query parameters
|
|
264
|
+
input_tensor_name: Name of the input tensor
|
|
265
|
+
scheduler_params: Optional scheduler configuration:
|
|
266
|
+
- Can be a dictionary with:
|
|
267
|
+
- frequency: Execution frequency in seconds (default: 600)
|
|
268
|
+
- duration_hours: How long to run in hours (default: 2)
|
|
269
|
+
- Or a SchedulerParams instance
|
|
270
|
+
If not provided, the workflow will be deployed without scheduling.
|
|
271
|
+
|
|
272
|
+
Returns:
|
|
273
|
+
str: Deployed contract address. If scheduler_params was provided, the workflow
|
|
274
|
+
will be automatically executed according to the specified schedule.
|
|
275
|
+
"""
|
|
276
|
+
if _client is None:
|
|
277
|
+
raise RuntimeError("OpenGradient client not initialized. Call og.init(...) first.")
|
|
278
|
+
|
|
279
|
+
# Convert scheduler_params if it's a dict, otherwise use as is
|
|
280
|
+
scheduler = SchedulerParams.from_dict(scheduler_params) if isinstance(scheduler_params, dict) else scheduler_params
|
|
281
|
+
|
|
282
|
+
return _client.new_workflow(
|
|
283
|
+
model_cid=model_cid,
|
|
284
|
+
input_query=input_query,
|
|
285
|
+
input_tensor_name=input_tensor_name,
|
|
286
|
+
scheduler_params=scheduler
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
def read_workflow_result(contract_address: str) -> Dict[str, Union[str, Dict]]:
|
|
290
|
+
"""
|
|
291
|
+
Reads the latest inference result from a deployed workflow contract.
|
|
292
|
+
|
|
293
|
+
This function retrieves the most recent output from a deployed model executor contract.
|
|
294
|
+
It includes built-in retry logic to handle blockchain state delays.
|
|
295
|
+
|
|
296
|
+
Args:
|
|
297
|
+
contract_address (str): Address of the deployed workflow contract
|
|
298
|
+
|
|
299
|
+
Returns:
|
|
300
|
+
Dict[str, Union[str, Dict]]: A dictionary containing:
|
|
301
|
+
- status: "success" or "error"
|
|
302
|
+
- result: The model output data if successful
|
|
303
|
+
- error: Error message if status is "error"
|
|
304
|
+
|
|
305
|
+
Raises:
|
|
306
|
+
RuntimeError: If OpenGradient client is not initialized
|
|
307
|
+
"""
|
|
308
|
+
if _client is None:
|
|
309
|
+
raise RuntimeError("OpenGradient client not initialized. Call og.init() first.")
|
|
310
|
+
return _client.read_workflow_result(contract_address)
|
|
311
|
+
|
|
312
|
+
def run_workflow(contract_address: str) -> Dict[str, Union[str, Dict]]:
|
|
313
|
+
"""
|
|
314
|
+
Executes the workflow by calling run() on the contract to pull latest data and perform inference.
|
|
315
|
+
|
|
316
|
+
Args:
|
|
317
|
+
contract_address (str): Address of the deployed workflow contract
|
|
318
|
+
|
|
319
|
+
Returns:
|
|
320
|
+
Dict[str, Union[str, Dict]]: Status of the run operation
|
|
321
|
+
"""
|
|
322
|
+
if _client is None:
|
|
323
|
+
raise RuntimeError("OpenGradient client not initialized. Call og.init() first.")
|
|
324
|
+
return _client.run_workflow(contract_address)
|
|
325
|
+
|
|
242
326
|
__all__ = [
|
|
243
327
|
'generate_image',
|
|
244
328
|
'list_files',
|
|
@@ -251,7 +335,10 @@ __all__ = [
|
|
|
251
335
|
'upload',
|
|
252
336
|
'init',
|
|
253
337
|
'LLM',
|
|
254
|
-
'TEE_LLM'
|
|
338
|
+
'TEE_LLM',
|
|
339
|
+
'new_workflow',
|
|
340
|
+
'read_workflow_result',
|
|
341
|
+
'run_workflow'
|
|
255
342
|
]
|
|
256
343
|
|
|
257
344
|
__pdoc__ = {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[{"inputs":[{"internalType":"string","name":"_modelCID","type":"string"},{"components":[{"internalType":"string","name":"currency_pair","type":"string"},{"internalType":"uint32","name":"total_candles","type":"uint32"},{"internalType":"uint32","name":"candle_duration_in_mins","type":"uint32"},{"internalType":"enum CandleOrder","name":"order","type":"uint8"},{"internalType":"enum CandleType[]","name":"candle_types","type":"uint8[]"}],"internalType":"struct HistoricalInputQuery","name":"_inputQuery","type":"tuple"},{"internalType":"address","name":"_historicalContractAddress","type":"address"},{"internalType":"string","name":"_inputTensorName","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"components":[{"components":[{"internalType":"string","name":"name","type":"string"},{"components":[{"internalType":"int128","name":"value","type":"int128"},{"internalType":"int128","name":"decimals","type":"int128"}],"internalType":"struct TensorLib.Number[]","name":"values","type":"tuple[]"},{"internalType":"uint32[]","name":"shape","type":"uint32[]"}],"internalType":"struct TensorLib.MultiDimensionalNumberTensor[]","name":"numbers","type":"tuple[]"},{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string[]","name":"values","type":"string[]"}],"internalType":"struct TensorLib.StringTensor[]","name":"strings","type":"tuple[]"},{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"value","type":"string"}],"internalType":"struct TensorLib.JsonScalar[]","name":"jsons","type":"tuple[]"},{"internalType":"bool","name":"is_simulation_result","type":"bool"}],"indexed":false,"internalType":"struct ModelOutput","name":"result","type":"tuple"}],"name":"InferenceResultEmitted","type":"event"},{"inputs":[],"name":"getInferenceResult","outputs":[{"components":[{"components":[{"internalType":"string","name":"name","type":"string"},{"components":[{"internalType":"int128","name":"value","type":"int128"},{"internalType":"int128","name":"decimals","type":"int128"}],"internalType":"struct TensorLib.Number[]","name":"values","type":"tuple[]"},{"internalType":"uint32[]","name":"shape","type":"uint32[]"}],"internalType":"struct TensorLib.MultiDimensionalNumberTensor[]","name":"numbers","type":"tuple[]"},{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string[]","name":"values","type":"string[]"}],"internalType":"struct TensorLib.StringTensor[]","name":"strings","type":"tuple[]"},{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"value","type":"string"}],"internalType":"struct TensorLib.JsonScalar[]","name":"jsons","type":"tuple[]"},{"internalType":"bool","name":"is_simulation_result","type":"bool"}],"internalType":"struct ModelOutput","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"historicalContract","outputs":[{"internalType":"contract OGHistorical","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"run","outputs":[],"stateMutability":"nonpayable","type":"function"}]
|
opengradient/cli.py
CHANGED
|
@@ -674,7 +674,6 @@ def generate_image(ctx, model: str, prompt: str, output_path: Path, width: int,
|
|
|
674
674
|
except Exception as e:
|
|
675
675
|
click.echo(f"Error generating image: {str(e)}")
|
|
676
676
|
|
|
677
|
-
|
|
678
677
|
if __name__ == '__main__':
|
|
679
678
|
logging.getLogger().setLevel(logging.WARN)
|
|
680
679
|
cli()
|
opengradient/client.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import asyncio
|
|
1
2
|
import json
|
|
2
3
|
import logging
|
|
3
4
|
import os
|
|
4
|
-
import
|
|
5
|
-
from typing import Dict, List, Optional, Tuple, Union
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Dict, List, Optional, Tuple, Union, Any
|
|
6
7
|
|
|
7
8
|
import firebase
|
|
8
9
|
import numpy as np
|
|
@@ -13,7 +14,15 @@ from web3.logs import DISCARD
|
|
|
13
14
|
|
|
14
15
|
from opengradient import utils
|
|
15
16
|
from opengradient.exceptions import OpenGradientError
|
|
16
|
-
from opengradient.types import
|
|
17
|
+
from opengradient.types import (
|
|
18
|
+
HistoricalInputQuery,
|
|
19
|
+
InferenceMode,
|
|
20
|
+
LlmInferenceMode,
|
|
21
|
+
LLM,
|
|
22
|
+
TEE_LLM,
|
|
23
|
+
ModelOutput,
|
|
24
|
+
SchedulerParams
|
|
25
|
+
)
|
|
17
26
|
|
|
18
27
|
import grpc
|
|
19
28
|
import time
|
|
@@ -62,7 +71,6 @@ class Client:
|
|
|
62
71
|
def __init__(self, private_key: str, rpc_url: str, contract_address: str, email: str, password: str):
|
|
63
72
|
"""
|
|
64
73
|
Initialize the Client with private key, RPC URL, and contract address.
|
|
65
|
-
|
|
66
74
|
Args:
|
|
67
75
|
private_key (str): The private key for the wallet.
|
|
68
76
|
rpc_url (str): The RPC URL for the Ethereum node.
|
|
@@ -78,19 +86,23 @@ class Client:
|
|
|
78
86
|
self._w3 = Web3(Web3.HTTPProvider(self.rpc_url))
|
|
79
87
|
self.wallet_account = self._w3.eth.account.from_key(private_key)
|
|
80
88
|
self.wallet_address = self._w3.to_checksum_address(self.wallet_account.address)
|
|
89
|
+
|
|
81
90
|
self.firebase_app = firebase.initialize_app(self.FIREBASE_CONFIG)
|
|
82
91
|
self.auth = self.firebase_app.auth()
|
|
83
92
|
self.user = None
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
|
|
94
|
+
abi_path = Path(__file__).parent / 'abi' / 'inference.abi'
|
|
95
|
+
|
|
96
|
+
try:
|
|
97
|
+
with open(abi_path, 'r') as abi_file:
|
|
98
|
+
inference_abi = json.load(abi_file)
|
|
99
|
+
except FileNotFoundError:
|
|
100
|
+
raise
|
|
101
|
+
except json.JSONDecodeError:
|
|
102
|
+
raise
|
|
103
|
+
except Exception as e:
|
|
104
|
+
raise
|
|
105
|
+
|
|
94
106
|
self.abi = inference_abi
|
|
95
107
|
|
|
96
108
|
if email is not None:
|
|
@@ -787,3 +799,184 @@ class Client:
|
|
|
787
799
|
finally:
|
|
788
800
|
if channel:
|
|
789
801
|
channel.close()
|
|
802
|
+
|
|
803
|
+
def _get_model_executor_abi(self) -> List[Dict]:
|
|
804
|
+
"""
|
|
805
|
+
Returns the ABI for the ModelExecutorHistorical contract.
|
|
806
|
+
"""
|
|
807
|
+
abi_path = Path(__file__).parent / 'abi' / 'ModelExecutorHistorical.abi'
|
|
808
|
+
with open(abi_path, 'r') as f:
|
|
809
|
+
return json.load(f)
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
def new_workflow(
|
|
813
|
+
self,
|
|
814
|
+
model_cid: str,
|
|
815
|
+
input_query: Union[Dict[str, Any], HistoricalInputQuery],
|
|
816
|
+
input_tensor_name: str,
|
|
817
|
+
scheduler_params: Optional[SchedulerParams] = None
|
|
818
|
+
) -> str:
|
|
819
|
+
"""
|
|
820
|
+
Deploy a new workflow contract with the specified parameters.
|
|
821
|
+
"""
|
|
822
|
+
if isinstance(input_query, dict):
|
|
823
|
+
input_query = HistoricalInputQuery.from_dict(input_query)
|
|
824
|
+
|
|
825
|
+
# Get contract ABI and bytecode
|
|
826
|
+
abi = self._get_model_executor_abi()
|
|
827
|
+
bin_path = Path(__file__).parent / 'contracts' / 'templates' / 'ModelExecutorHistorical.bin'
|
|
828
|
+
|
|
829
|
+
with open(bin_path, 'r') as f:
|
|
830
|
+
bytecode = f.read().strip()
|
|
831
|
+
|
|
832
|
+
print("📦 Deploying workflow contract...")
|
|
833
|
+
|
|
834
|
+
# Create contract instance
|
|
835
|
+
contract = self._w3.eth.contract(abi=abi, bytecode=bytecode)
|
|
836
|
+
|
|
837
|
+
# Deploy contract with constructor arguments
|
|
838
|
+
transaction = contract.constructor(
|
|
839
|
+
model_cid,
|
|
840
|
+
input_query.to_abi_format(),
|
|
841
|
+
"0x00000000000000000000000000000000000000F5", # Historical contract address
|
|
842
|
+
input_tensor_name
|
|
843
|
+
).build_transaction({
|
|
844
|
+
'from': self.wallet_address,
|
|
845
|
+
'nonce': self._w3.eth.get_transaction_count(self.wallet_address, 'pending'),
|
|
846
|
+
'gas': 15000000,
|
|
847
|
+
'gasPrice': self._w3.eth.gas_price,
|
|
848
|
+
'chainId': self._w3.eth.chain_id
|
|
849
|
+
})
|
|
850
|
+
|
|
851
|
+
signed_txn = self._w3.eth.account.sign_transaction(transaction, self.private_key)
|
|
852
|
+
tx_hash = self._w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
|
853
|
+
tx_receipt = self._w3.eth.wait_for_transaction_receipt(tx_hash)
|
|
854
|
+
contract_address = tx_receipt.contractAddress
|
|
855
|
+
|
|
856
|
+
print(f"✅ Workflow contract deployed at: {contract_address}")
|
|
857
|
+
|
|
858
|
+
# Register with scheduler if params provided
|
|
859
|
+
if scheduler_params:
|
|
860
|
+
print("\n⏰ Setting up automated execution schedule...")
|
|
861
|
+
print(f" • Frequency: Every {scheduler_params.frequency} seconds")
|
|
862
|
+
print(f" • Duration: {scheduler_params.duration_hours} hours")
|
|
863
|
+
print(f" • End Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(scheduler_params.end_time))}")
|
|
864
|
+
|
|
865
|
+
scheduler_abi = [{
|
|
866
|
+
"inputs": [
|
|
867
|
+
{"internalType": "address", "name": "contractAddress", "type": "address"},
|
|
868
|
+
{"internalType": "uint256", "name": "endTime", "type": "uint256"},
|
|
869
|
+
{"internalType": "uint256", "name": "frequency", "type": "uint256"}
|
|
870
|
+
],
|
|
871
|
+
"name": "registerTask",
|
|
872
|
+
"outputs": [],
|
|
873
|
+
"stateMutability": "nonpayable",
|
|
874
|
+
"type": "function"
|
|
875
|
+
}]
|
|
876
|
+
|
|
877
|
+
scheduler_address = "0xE81a54399CFDf551bB917d0427464fE54537D245"
|
|
878
|
+
scheduler_contract = self._w3.eth.contract(
|
|
879
|
+
address=scheduler_address,
|
|
880
|
+
abi=scheduler_abi
|
|
881
|
+
)
|
|
882
|
+
|
|
883
|
+
try:
|
|
884
|
+
# Register the workflow with the scheduler
|
|
885
|
+
scheduler_tx = scheduler_contract.functions.registerTask(
|
|
886
|
+
contract_address,
|
|
887
|
+
scheduler_params.end_time,
|
|
888
|
+
scheduler_params.frequency
|
|
889
|
+
).build_transaction({
|
|
890
|
+
'from': self.wallet_address,
|
|
891
|
+
'gas': 300000,
|
|
892
|
+
'gasPrice': self._w3.eth.gas_price,
|
|
893
|
+
'nonce': self._w3.eth.get_transaction_count(self.wallet_address, 'pending'),
|
|
894
|
+
'chainId': self._w3.eth.chain_id
|
|
895
|
+
})
|
|
896
|
+
|
|
897
|
+
signed_scheduler_tx = self._w3.eth.account.sign_transaction(scheduler_tx, self.private_key)
|
|
898
|
+
scheduler_tx_hash = self._w3.eth.send_raw_transaction(signed_scheduler_tx.raw_transaction)
|
|
899
|
+
self._w3.eth.wait_for_transaction_receipt(scheduler_tx_hash)
|
|
900
|
+
|
|
901
|
+
print("✅ Automated execution schedule set successfully!")
|
|
902
|
+
print(f" Transaction hash: {scheduler_tx_hash.hex()}")
|
|
903
|
+
|
|
904
|
+
except Exception as e:
|
|
905
|
+
print("❌ Failed to set up automated execution schedule")
|
|
906
|
+
print(f" Error: {str(e)}")
|
|
907
|
+
print(" The workflow contract is still deployed and can be executed manually.")
|
|
908
|
+
|
|
909
|
+
return contract_address
|
|
910
|
+
|
|
911
|
+
def read_workflow_result(self, contract_address: str) -> Any:
|
|
912
|
+
"""
|
|
913
|
+
Reads the latest inference result from a deployed workflow contract.
|
|
914
|
+
|
|
915
|
+
Args:
|
|
916
|
+
contract_address (str): Address of the deployed workflow contract
|
|
917
|
+
|
|
918
|
+
Returns:
|
|
919
|
+
Any: The inference result from the contract
|
|
920
|
+
|
|
921
|
+
Raises:
|
|
922
|
+
ContractLogicError: If the transaction fails
|
|
923
|
+
Web3Error: If there are issues with the web3 connection or contract interaction
|
|
924
|
+
"""
|
|
925
|
+
if not self._w3:
|
|
926
|
+
self._initialize_web3()
|
|
927
|
+
|
|
928
|
+
# Get the contract interface
|
|
929
|
+
contract = self._w3.eth.contract(
|
|
930
|
+
address=Web3.to_checksum_address(contract_address),
|
|
931
|
+
abi=self._get_model_executor_abi()
|
|
932
|
+
)
|
|
933
|
+
|
|
934
|
+
# Get the result
|
|
935
|
+
result = contract.functions.getInferenceResult().call()
|
|
936
|
+
return result
|
|
937
|
+
|
|
938
|
+
def run_workflow(self, contract_address: str) -> ModelOutput:
|
|
939
|
+
"""
|
|
940
|
+
Triggers the run() function on a deployed workflow contract and returns the result.
|
|
941
|
+
|
|
942
|
+
Args:
|
|
943
|
+
contract_address (str): Address of the deployed workflow contract
|
|
944
|
+
|
|
945
|
+
Returns:
|
|
946
|
+
ModelOutput: The inference result from the contract
|
|
947
|
+
|
|
948
|
+
Raises:
|
|
949
|
+
ContractLogicError: If the transaction fails
|
|
950
|
+
Web3Error: If there are issues with the web3 connection or contract interaction
|
|
951
|
+
"""
|
|
952
|
+
if not self._w3:
|
|
953
|
+
self._initialize_web3()
|
|
954
|
+
|
|
955
|
+
# Get the contract interface
|
|
956
|
+
contract = self._w3.eth.contract(
|
|
957
|
+
address=Web3.to_checksum_address(contract_address),
|
|
958
|
+
abi=self._get_model_executor_abi()
|
|
959
|
+
)
|
|
960
|
+
|
|
961
|
+
# Call run() function
|
|
962
|
+
nonce = self._w3.eth.get_transaction_count(self.wallet_address, 'pending')
|
|
963
|
+
|
|
964
|
+
run_function = contract.functions.run()
|
|
965
|
+
transaction = run_function.build_transaction({
|
|
966
|
+
'from': self.wallet_address,
|
|
967
|
+
'nonce': nonce,
|
|
968
|
+
'gas': 30000000,
|
|
969
|
+
'gasPrice': self._w3.eth.gas_price,
|
|
970
|
+
'chainId': self._w3.eth.chain_id
|
|
971
|
+
})
|
|
972
|
+
|
|
973
|
+
signed_txn = self._w3.eth.account.sign_transaction(transaction, self.private_key)
|
|
974
|
+
tx_hash = self._w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
|
975
|
+
tx_receipt = self._w3.eth.wait_for_transaction_receipt(tx_hash)
|
|
976
|
+
|
|
977
|
+
if tx_receipt.status == 0:
|
|
978
|
+
raise ContractLogicError(f"Run transaction failed. Receipt: {tx_receipt}")
|
|
979
|
+
|
|
980
|
+
# Get the inference result from the contract
|
|
981
|
+
result = contract.functions.getInferenceResult().call()
|
|
982
|
+
return result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
6080604052346100335761001d61001461039c565b92919091610a9c565b610025610038565b613964610ad2823961396490f35b61003e565b60405190565b5f80fd5b601f801991011690565b634e487b7160e01b5f52604160045260245ffd5b9061006a90610042565b810190811060018060401b0382111761008257604052565b61004c565b9061009a610093610038565b9283610060565b565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b60018060401b0381116100c8576100c4602091610042565b0190565b61004c565b90825f9392825e0152565b909291926100ed6100e8826100ac565b610087565b9381855260208501908284011161010957610107926100cd565b565b6100a8565b9080601f8301121561012c57816020610129935191016100d8565b90565b6100a4565b5f80fd5b5f80fd5b63ffffffff1690565b61014b81610139565b0361015257565b5f80fd5b9050519061016382610142565b565b6002111561016f57565b5f80fd5b9050519061018082610165565b565b60018060401b0381116101985760208091020190565b61004c565b5f80fd5b600411156101ab57565b5f80fd5b905051906101bc826101a1565b565b909291926101d36101ce82610182565b610087565b938185526020808601920283019281841161021057915b8383106101f75750505050565b6020809161020584866101af565b8152019201916101ea565b61019d565b9080601f8301121561023357816020610230935191016101be565b90565b6100a4565b91909160a0818403126102d45761024f60a0610087565b925f82015160018060401b0381116102cf578161026d91840161010e565b5f85015261027e8160208401610156565b60208501526102908160408401610156565b60408501526102a28160608401610173565b6060850152608082015160018060401b0381116102ca576102c39201610215565b6080830152565b610135565b610135565b610131565b60018060a01b031690565b6102ed906102d9565b90565b6102f9816102e4565b0361030057565b5f80fd5b90505190610311826102f0565b565b90608082820312610397575f82015160018060401b038111610392578161033b91840161010e565b92602083015160018060401b03811161038d578261035a918501610238565b926103688360408301610304565b92606082015160018060401b03811161038857610385920161010e565b90565b6100a0565b6100a0565b6100a0565b61009c565b6103ba614436803803806103af81610087565b928339810190610313565b90919293565b5190565b634e487b7160e01b5f52602260045260245ffd5b90600160028304921680156103f8575b60208310146103f357565b6103c4565b91607f16916103e8565b5f5260205f2090565b601f602091010490565b1b90565b9190600861043491029161042e5f1984610415565b92610415565b9181191691161790565b90565b90565b61045861045361045d9261043e565b610441565b61043e565b90565b90565b919061047961047461048193610444565b610460565b908354610419565b9055565b5f90565b61049b91610495610485565b91610463565b565b5b8181106104a9575050565b806104b65f600193610489565b0161049e565b9190601f81116104cc575b505050565b6104d86104fd93610402565b9060206104e48461040b565b83019310610505575b6104f69061040b565b019061049d565b5f80806104c7565b91506104f6819290506104ed565b1c90565b90610527905f1990600802610513565b191690565b8161053691610517565b906002021790565b90610548816103c0565b9060018060401b0382116106065761056a8261056485546103d8565b856104bc565b602090601f831160011461059e5791809161058d935f92610592575b505061052c565b90555b565b90915001515f80610586565b601f198316916105ad85610402565b925f5b8181106105ee575091600293918560019694106105d4575b50505002019055610590565b6105e4910151601f841690610517565b90555f80806105c8565b919360206001819287870151815501950192016105b0565b61004c565b906106159161053e565b565b5190565b6106259051610139565b90565b5f1b90565b9061063c63ffffffff91610628565b9181191691161790565b61065a61065561065f92610139565b610441565b610139565b90565b90565b9061067a61067561068192610646565b610662565b825461062d565b9055565b60201b90565b9061069e67ffffffff0000000091610685565b9181191691161790565b906106bd6106b86106c492610646565b610662565b825461068b565b9055565b634e487b7160e01b5f52602160045260245ffd5b600211156106e657565b6106c8565b906106f5826106dc565b565b61070190516106eb565b90565b60401b90565b9061071e68ff000000000000000091610704565b9181191691161790565b610731906106eb565b90565b90565b9061074c61074761075392610728565b610734565b825461070a565b9055565b5190565b5490565b60209060018203010490565b5f5260205f2090565b5b818110610780575050565b8061078d5f600193610489565b01610775565b906107a6905f1990602003600802610513565b8154169055565b9190918282106107bd575b505050565b600160206107cd6107f59561075f565b6107df6107d98661075f565b9461076b565b93840193019306025f81116107fd575b50610774565b5f80806107b8565b61080a9060018303610793565b5f6107ef565b90680100000000000000008111610839578161082e6108379361075b565b908281556107ad565b565b61004c565b5190565b6004111561084c57565b6106c8565b9061085b82610842565b565b6108679051610851565b90565b60200190565b9190600861088b91029161088560ff84610415565b92610415565b9181191691161790565b90565b906108a28161083e565b9060018060401b038211610983576108c66108cc916108c18486610810565b61086a565b9261076b565b60208204915f5b83811061093b57506020830290035f81116108ef575b50505050565b925f935f5b8181106109095750505001555f8080806108e9565b909194602061092f6001926109256109208a61085d565b610895565b9085850290610870565b960191019190916108f4565b5f5f5b6020811061095557509060019181850155016108d3565b9590602061097a60019261097061096b8661085d565b610895565b908a850290610870565b9201960161093e565b61004c565b9061099291610898565b565b90610a0a60806002610a10946109b75f82016109b15f8801610617565b9061060b565b6109d0600182016109ca6020880161061b565b90610665565b6109e9600182016109e36040880161061b565b906106a8565b610a02600182016109fc606088016106f7565b90610737565b019201610757565b90610988565b565b90610a1c91610994565b565b610a32610a2d610a37926102d9565b610441565b6102d9565b90565b610a4390610a1e565b90565b610a4f90610a3a565b90565b90610a6360018060a01b0391610628565b9181191691161790565b610a7690610a3a565b90565b90565b90610a91610a8c610a9892610a6d565b610a79565b8254610a52565b9055565b610acf9392610abd610ac893610ab6610ac294600561060b565b6006610a12565b610a46565b5f610a7c565b600961060b565b56fe60806040526004361015610013575b6106a9565b61001d5f3561004c565b80631b9fc70114610047578063c0406226146100425763df958cf60361000e57610674565b61059a565b610560565b60e01c90565b60405190565b5f80fd5b5f80fd5b5f91031261006a57565b61005c565b5190565b60209181520190565b60200190565b5190565b60209181520190565b90825f9392825e0152565b601f801991011690565b6100c36100cc6020936100d1936100ba81610082565b93848093610086565b9586910161008f565b61009a565b0190565b5190565b60209181520190565b60200190565b600f0b90565b6100f7906100e8565b9052565b9060208061011d936101135f8201515f8601906100ee565b01519101906100ee565b565b9061012c816040936100fb565b0190565b60200190565b9061015361014d610146846100d5565b80936100d9565b926100e2565b905f5b8181106101635750505090565b90919261017c610176600192865161011f565b94610130565b9101919091610156565b5190565b60209181520190565b60200190565b63ffffffff1690565b6101ab90610199565b9052565b906101bc816020936101a2565b0190565b60200190565b906101e36101dd6101d684610186565b809361018a565b92610193565b905f5b8181106101f35750505090565b90919261020c61020660019286516101af565b946101c0565b91019190916101e6565b610259916040610248610236606084015f8601518582035f8701526100a4565b60208501518482036020860152610136565b9201519060408184039101526101c6565b90565b9061026691610216565b90565b60200190565b9061028361027c8361006f565b8092610073565b90816102946020830284019461007c565b925f915b8383106102a757505050505090565b909192939460206102c96102c38385600195038752895161025c565b97610269565b9301930191939290610298565b5190565b60209181520190565b60200190565b5190565b60209181520190565b60200190565b90610306916100a4565b90565b60200190565b9061032361031c836102e9565b80926102ed565b9081610334602083028401946102f6565b925f915b83831061034757505050505090565b90919293946020610369610363838560019503875289516102fc565b97610309565b9301930191939290610338565b6103a4916020610393604083015f8501518482035f8601526100a4565b92015190602081840391015261030f565b90565b906103b191610376565b90565b60200190565b906103ce6103c7836102d6565b80926102da565b90816103df602083028401946102e3565b925f915b8383106103f257505050505090565b9091929394602061041461040e838560019503875289516103a7565b976103b4565b93019301919392906103e3565b5190565b60209181520190565b60200190565b610462916020610451604083015f8501518482035f8601526100a4565b9201519060208184039101526100a4565b90565b9061046f91610434565b90565b60200190565b9061048c61048583610421565b8092610425565b908161049d6020830284019461042e565b925f915b8383106104b057505050505090565b909192939460206104d26104cc83856001950387528951610465565b97610472565b93019301919392906104a1565b151590565b6104ed906104df565b9052565b906105459060608061053a610528610516608086015f8901518782035f89015261026f565b602088015186820360208801526103ba565b60408701518582036040870152610478565b9401519101906104e4565b90565b61055d9160208201915f8184039101526104f1565b90565b3461059057610570366004610060565b61058c61057b611114565b610583610052565b91829182610548565b0390f35b610058565b5f0190565b346105c8576105aa366004610060565b6105b261385c565b6105ba610052565b806105c481610595565b0390f35b610058565b1c90565b60018060a01b031690565b6105ec9060086105f193026105cd565b6105d1565b90565b906105ff91546105dc565b90565b61060d5f5f906105f4565b90565b60018060a01b031690565b90565b61063261062d61063792610610565b61061b565b610610565b90565b6106439061061e565b90565b61064f9061063a565b90565b61065b90610646565b9052565b9190610672905f60208501940190610652565b565b346106a457610684366004610060565b6106a061068f610602565b610697610052565b9182918261065f565b0390f35b610058565b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b906106cb9061009a565b810190811067ffffffffffffffff8211176106e557604052565b6106ad565b906106fd6106f6610052565b92836106c1565b565b61070960806106ea565b90565b606090565b606090565b606090565b5f90565b6107276106ff565b9060208080808561073661070c565b815201610741610711565b81520161074c610716565b81520161075761071b565b81525050565b61076561071f565b90565b5490565b67ffffffffffffffff81116107845760208091020190565b6106ad565b9061079b6107968361076c565b6106ea565b918252565b5f5260205f2090565b634e487b7160e01b5f52602260045260245ffd5b90600160028304921680156107dd575b60208310146107d857565b6107a9565b91607f16916107cd565b5f5260205f2090565b905f929180549061080a610803836107bd565b8094610086565b916001811690815f146108615750600114610825575b505050565b61083291929394506107e7565b915f925b81841061084957505001905f8080610820565b60018160209295939554848601520191019290610836565b92949550505060ff19168252151560200201905f8080610820565b90610886916107f0565b90565b906108a96108a292610899610052565b9384809261087c565b03836106c1565b565b52565b5490565b67ffffffffffffffff81116108ca5760208091020190565b6106ad565b906108e16108dc836108b2565b6106ea565b918252565b5f5260205f2090565b5f1c90565b600f0b90565b61090661090b916108ef565b6108f4565b90565b61091890546108fa565b90565b90610925906100e8565b9052565b60801c90565b61093b61094091610929565b6108f4565b90565b61094d905461092f565b90565b61095a60406106ea565b90565b9061099361098a5f61096d610950565b9461098461097c83830161090e565b83880161091b565b01610943565b6020840161091b565b565b61099e9061095d565b90565b906109ab826108ae565b6109b4816108cf565b926109c260208501916108e6565b5f915b8383106109d25750505050565b6001602081926109e185610995565b8152019201920191906109c5565b52565b5490565b5f5260205f2090565b63ffffffff1690565b610a14610a19916108ef565b6109ff565b90565b60201c90565b610a2e610a3391610a1c565b6109ff565b90565b60401c90565b610a48610a4d91610a36565b6109ff565b90565b60601c90565b610a62610a6791610a50565b6109ff565b90565b610a76610a7b91610929565b6109ff565b90565b60a01c90565b610a90610a9591610a7e565b6109ff565b90565b60c01c90565b610aaa610aaf91610a98565b6109ff565b90565b610abe610ac39161004c565b6109ff565b90565b90600190610ae6610ae0610ad9856109f2565b809361018a565b936109f6565b5f92610c50575b6001610afa575b50505090565b5490808310610c2e575b808310610c0c575b808310610bea575b808310610bc8575b808310610ba6575b808310610b84575b808310610b62575b8210610b41575b80610af4565b82610b5960019394610b54602094610ab2565b6101a2565b0191015f610b3b565b9192602081610b7b600193610b7686610a9e565b6101a2565b01930191610b34565b9192602081610b9d600193610b9886610a84565b6101a2565b01930191610b2c565b9192602081610bbf600193610bba86610a6a565b6101a2565b01930191610b24565b9192602081610be1600193610bdc86610a56565b6101a2565b01930191610b1c565b9192602081610c03600193610bfe86610a3c565b6101a2565b01930191610b14565b9192602081610c25600193610c2086610a22565b6101a2565b01930191610b0c565b9192602081610c47600193610c4286610a08565b6101a2565b01930191610b04565b5b81600160080384011015610aed579260016020610d04610d09600894838080808080808f5497610c8981610c848b610a08565b6101a2565b01610c9c81610c978a610a22565b6101a2565b01610caf81610caa89610a3c565b6101a2565b01610cc281610cbd88610a56565b6101a2565b01610cd581610cd087610a6a565b6101a2565b01610ce881610ce386610a84565b6101a2565b01610cfb81610cf685610a9e565b6101a2565b01928391610ab2565b6101a2565b019401920191610c51565b90610d1e91610ac6565b90565b90610d41610d3a92610d31610052565b93848092610d14565b03836106c1565b565b52565b610d5060606106ea565b90565b90610da2610d996002610d64610d46565b94610d7b610d735f8301610889565b5f88016108ab565b610d93610d8a600183016109a1565b602088016109ef565b01610d21565b60408401610d43565b565b610dad90610d53565b90565b90610dba82610768565b610dc381610789565b92610dd160208501916107a0565b5f915b838310610de15750505050565b60036020600192610df185610da4565b815201920192019190610dd4565b52565b5490565b67ffffffffffffffff8111610e1e5760208091020190565b6106ad565b90610e35610e3083610e06565b6106ea565b918252565b5f5260205f2090565b5490565b67ffffffffffffffff8111610e5f5760208091020190565b6106ad565b90610e76610e7183610e47565b6106ea565b918252565b5f5260205f2090565b610e8d90610889565b90565b90610e9a82610e43565b610ea381610e64565b92610eb16020850191610e7b565b5f915b838310610ec15750505050565b600160208192610ed085610e84565b815201920192019190610eb4565b52565b610eeb60406106ea565b90565b90610f25610f1c6001610eff610ee1565b94610f16610f0e5f8301610889565b5f88016108ab565b01610e90565b60208401610ede565b565b610f3090610eee565b90565b90610f3d82610e02565b610f4681610e23565b92610f546020850191610e3a565b5f915b838310610f645750505050565b60026020600192610f7485610f27565b815201920192019190610f57565b52565b5490565b67ffffffffffffffff8111610fa15760208091020190565b6106ad565b90610fb8610fb383610f89565b6106ea565b918252565b5f5260205f2090565b610fd060406106ea565b90565b9061100a6110016001610fe4610fc6565b94610ffb610ff35f8301610889565b5f88016108ab565b01610889565b602084016108ab565b565b61101590610fd3565b90565b9061102282610f85565b61102b81610fa6565b926110396020850191610fbd565b5f915b8383106110495750505050565b600260206001926110598561100c565b81520192019201919061103c565b52565b60ff1690565b61107c611081916108ef565b61106a565b90565b61108e9054611070565b90565b9061109b906104df565b9052565b906111066110fd60036110b06106ff565b946110c76110bf5f8301610db0565b5f8801610dff565b6110df6110d660018301610f33565b60208801610f82565b6110f76110ee60028301611018565b60408801611067565b01611084565b60608401611091565b565b6111119061109f565b90565b61111c61075d565b506111276001611108565b90565b61113661113b916108ef565b6105d1565b90565b611148905461112a565b90565b60e01b90565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f80fd5b67ffffffffffffffff81116111875761118360209161009a565b0190565b6106ad565b909291926111a161119c82611169565b6106ea565b938185526020850190828401116111bd576111bb9261008f565b565b611165565b9080601f830112156111e0578160206111dd9351910161118c565b90565b61115d565b6111ee816100e8565b036111f557565b5f80fd5b90505190611206826111e5565b565b91906040838203126112425761123b9061122260406106ea565b9361122f825f83016111f9565b5f8601526020016111f9565b6020830152565b611155565b9092919261125c611257826108b2565b6106ea565b93818552604060208601920283019281841161129b57915b8383106112815750505050565b60206040916112908486611208565b815201920191611274565b611161565b9080601f830112156112be578160206112bb93519101611247565b90565b61115d565b67ffffffffffffffff81116112db5760208091020190565b6106ad565b6112e981610199565b036112f057565b5f80fd5b90505190611301826112e0565b565b90929192611318611313826112c3565b6106ea565b938185526020808601920283019281841161135557915b83831061133c5750505050565b6020809161134a84866112f4565b81520192019161132f565b611161565b9080601f830112156113785781602061137593519101611303565b90565b61115d565b9190916060818403126114115761139460606106ea565b925f82015167ffffffffffffffff811161140c57816113b49184016111c2565b5f850152602082015167ffffffffffffffff811161140757816113d89184016112a0565b6020850152604082015167ffffffffffffffff8111611402576113fb920161135a565b6040830152565b611159565b611159565b611159565b611155565b92919061142a6114258261076c565b6106ea565b93818552602080860192028101918383116114815781905b838210611450575050505050565b815167ffffffffffffffff811161147c57602091611471878493870161137d565b815201910190611442565b61115d565b611161565b9080601f830112156114a4578160206114a193519101611416565b90565b61115d565b9291906114bd6114b882610e47565b6106ea565b93818552602080860192028101918383116115145781905b8382106114e3575050505050565b815167ffffffffffffffff811161150f5760209161150487849387016111c2565b8152019101906114d5565b61115d565b611161565b9080601f8301121561153757816020611534935191016114a9565b90565b61115d565b9190916040818403126115a65761155360406106ea565b925f82015167ffffffffffffffff81116115a157816115739184016111c2565b5f850152602082015167ffffffffffffffff811161159c576115959201611519565b6020830152565b611159565b611159565b611155565b9291906115bf6115ba82610e06565b6106ea565b93818552602080860192028101918383116116165781905b8382106115e5575050505050565b815167ffffffffffffffff811161161157602091611606878493870161153c565b8152019101906115d7565b61115d565b611161565b9080601f8301121561163957816020611636935191016115ab565b90565b61115d565b9190916040818403126116a85761165560406106ea565b925f82015167ffffffffffffffff81116116a357816116759184016111c2565b5f850152602082015167ffffffffffffffff811161169e5761169792016111c2565b6020830152565b611159565b611159565b611155565b9291906116c16116bc82610f89565b6106ea565b93818552602080860192028101918383116117185781905b8382106116e7575050505050565b815167ffffffffffffffff811161171357602091611708878493870161163e565b8152019101906116d9565b61115d565b611161565b9080601f8301121561173b57816020611738935191016116ad565b90565b61115d565b611749816104df565b0361175057565b5f80fd5b9050519061176182611740565b565b91909160808184031261180a5761177a60806106ea565b925f82015167ffffffffffffffff8111611805578161179a918401611486565b5f850152602082015167ffffffffffffffff811161180057816117be91840161161b565b602085015260408201519167ffffffffffffffff83116117fb576117e7826117f494830161171d565b6040860152606001611754565b6060830152565b611159565b611159565b611159565b611155565b9060208282031261183f575f82015167ffffffffffffffff811161183a576118379201611763565b90565b611151565b61005c565b60209181520190565b905f9291805490611867611860836107bd565b8094611844565b916001811690815f146118be5750600114611882575b505050565b61188f91929394506107e7565b915f925b8184106118a657505001905f808061187d565b60018160209295939554848601520191019290611893565b92949550505060ff19168252151560200201905f808061187d565b60ff1690565b6118eb6118f091610a36565b6118d9565b90565b634e487b7160e01b5f52602160045260245ffd5b6002111561191157565b6118f3565b9061192082611907565b565b61192b90611916565b90565b61193790611922565b9052565b5490565b60209181520190565b5f5260205f2090565b6004111561195b57565b6118f3565b9061196a82611951565b565b61197590611960565b90565b6119819061196c565b9052565b60ff1690565b61199761199c916108ef565b611985565b90565b60081c90565b6119b16119b69161199f565b611985565b90565b60101c90565b6119cb6119d0916119b9565b611985565b90565b60181c90565b6119e56119ea916119d3565b611985565b90565b6119f96119fe91610a1c565b611985565b90565b60281c90565b611a13611a1891611a01565b611985565b90565b60301c90565b611a2d611a3291611a1b565b611985565b90565b60381c90565b611a47611a4c91611a35565b611985565b90565b611a5b611a6091610a36565b611985565b90565b60481c90565b611a75611a7a91611a63565b611985565b90565b60501c90565b611a8f611a9491611a7d565b611985565b90565b60581c90565b611aa9611aae91611a97565b611985565b90565b611abd611ac291610a50565b611985565b90565b60681c90565b611ad7611adc91611ac5565b611985565b90565b60701c90565b611af1611af691611adf565b611985565b90565b60781c90565b611b0b611b1091611af9565b611985565b90565b611b1f611b2491610929565b611985565b90565b60881c90565b611b39611b3e91611b27565b611985565b90565b60901c90565b611b53611b5891611b41565b611985565b90565b60981c90565b611b6d611b7291611b5b565b611985565b90565b611b81611b8691610a7e565b611985565b90565b60a81c90565b611b9b611ba091611b89565b611985565b90565b60b01c90565b611bb5611bba91611ba3565b611985565b90565b60b81c90565b611bcf611bd491611bbd565b611985565b90565b611be3611be891610a98565b611985565b90565b60c81c90565b611bfd611c0291611beb565b611985565b90565b60d01c90565b611c17611c1c91611c05565b611985565b90565b60d81c90565b611c31611c3691611c1f565b611985565b90565b611c45611c4a9161004c565b611985565b90565b60e81c90565b611c5f611c6491611c4d565b611985565b90565b60f01c90565b611c79611c7e91611c67565b611985565b90565b60f81c90565b611c93611c9891611c81565b611985565b90565b90600190611cbb611cb5611cae8561193b565b809361193f565b93611948565b5f92612215575b6001611ccf575b50505090565b54908083106121f3575b8083106121d1575b8083106121af575b80831061218d575b80831061216b575b808310612149575b808310612127575b808310612105575b8083106120e3575b8083106120c1575b80831061209f575b80831061207d575b80831061205b575b808310612039575b808310612017575b808310611ff5575b808310611fd3575b808310611fb1575b808310611f8f575b808310611f6d575b808310611f4b575b808310611f29575b808310611f07575b808310611ee5575b808310611ec3575b808310611ea1575b808310611e7f575b808310611e5d575b808310611e3b575b808310611e19575b808310611df7575b8210611dd6575b80611cc9565b82611dee60019394611de9602094611c87565b611978565b0191015f611dd0565b9192602081611e10600193611e0b86611c6d565b611978565b01930191611dc9565b9192602081611e32600193611e2d86611c53565b611978565b01930191611dc1565b9192602081611e54600193611e4f86611c39565b611978565b01930191611db9565b9192602081611e76600193611e7186611c25565b611978565b01930191611db1565b9192602081611e98600193611e9386611c0b565b611978565b01930191611da9565b9192602081611eba600193611eb586611bf1565b611978565b01930191611da1565b9192602081611edc600193611ed786611bd7565b611978565b01930191611d99565b9192602081611efe600193611ef986611bc3565b611978565b01930191611d91565b9192602081611f20600193611f1b86611ba9565b611978565b01930191611d89565b9192602081611f42600193611f3d86611b8f565b611978565b01930191611d81565b9192602081611f64600193611f5f86611b75565b611978565b01930191611d79565b9192602081611f86600193611f8186611b61565b611978565b01930191611d71565b9192602081611fa8600193611fa386611b47565b611978565b01930191611d69565b9192602081611fca600193611fc586611b2d565b611978565b01930191611d61565b9192602081611fec600193611fe786611b13565b611978565b01930191611d59565b919260208161200e60019361200986611aff565b611978565b01930191611d51565b919260208161203060019361202b86611ae5565b611978565b01930191611d49565b919260208161205260019361204d86611acb565b611978565b01930191611d41565b919260208161207460019361206f86611ab1565b611978565b01930191611d39565b919260208161209660019361209186611a9d565b611978565b01930191611d31565b91926020816120b86001936120b386611a83565b611978565b01930191611d29565b91926020816120da6001936120d586611a69565b611978565b01930191611d21565b91926020816120fc6001936120f786611a4f565b611978565b01930191611d19565b919260208161211e60019361211986611a3b565b611978565b01930191611d11565b919260208161214060019361213b86611a21565b611978565b01930191611d09565b919260208161216260019361215d86611a07565b611978565b01930191611d01565b919260208161218460019361217f866119ed565b611978565b01930191611cf9565b91926020816121a66001936121a1866119d9565b611978565b01930191611cf1565b91926020816121c86001936121c3866119bf565b611978565b01930191611ce9565b91926020816121ea6001936121e5866119a5565b611978565b01930191611ce1565b919260208161220c6001936122078661198b565b611978565b01930191611cd9565b5b81600160200384011015611cc25792835490806122328361198b565b9061223c91611978565b60200180612249836119a5565b9061225391611978565b60200180612260836119bf565b9061226a91611978565b60200180612277836119d9565b9061228191611978565b6020018061228e836119ed565b9061229891611978565b602001806122a583611a07565b906122af91611978565b602001806122bc83611a21565b906122c691611978565b602001806122d383611a3b565b906122dd91611978565b602001806122ea83611a4f565b906122f491611978565b6020018061230183611a69565b9061230b91611978565b6020018061231883611a83565b9061232291611978565b6020018061232f83611a9d565b9061233991611978565b6020018061234683611ab1565b9061235091611978565b6020018061235d83611acb565b9061236791611978565b6020018061237483611ae5565b9061237e91611978565b6020018061238b83611aff565b9061239591611978565b602001806123a283611b13565b906123ac91611978565b602001806123b983611b2d565b906123c391611978565b602001806123d083611b47565b906123da91611978565b602001806123e783611b61565b906123f191611978565b602001806123fe83611b75565b9061240891611978565b6020018061241583611b8f565b9061241f91611978565b6020018061242c83611ba9565b9061243691611978565b6020018061244383611bc3565b9061244d91611978565b6020018061245a83611bd7565b9061246491611978565b6020018061247183611bf1565b9061247b91611978565b6020018061248883611c0b565b9061249291611978565b6020018061249f83611c25565b906124a991611978565b602001806124b683611c39565b906124c091611978565b602001806124cd83611c53565b906124d791611978565b602001806124e483611c6d565b906124ee91611978565b6020016124fb8192611c87565b9061250591611978565b602001926001019160200191612216565b61258891600261253260a083015f85018482035f8601526107f0565b9261257961256f600183015461255461254a82610a08565b60208801906101a2565b61256a61256082610a22565b60408801906101a2565b6118df565b606085019061192e565b01906080818403910152611c9b565b90565b916125b7906125a96125c5959360608601908682035f88015261184d565b90848203602086015261184d565b916040818403910152612516565b90565b6125d0610052565b3d5f823e3d90fd5b634e487b7160e01b5f525f60045260245ffd5b5190565b90565b634e487b7160e01b5f52601160045260245ffd5b61261561261b919392936125ef565b926125ef565b916126278382026125ef565b92818404149015171561263657565b6125f2565b612646906003612606565b90565b9061265c905f19906020036008026105cd565b8154169055565b1b90565b9190600861268291029161267c5f1984612663565b92612663565b9181191691161790565b6126a061269b6126a5926125ef565b61061b565b6125ef565b90565b90565b91906126c16126bc6126c99361268c565b6126a8565b908354612667565b9055565b5f90565b6126e3916126dd6126cd565b916126ab565b565b5b8181106126f1575050565b806126fe5f6001936126d1565b016126e6565b90612714905f19906008026105cd565b191690565b8161272391612704565b906002021790565b905f9161274261273a826107e7565b928354612719565b905555565b601f602091010490565b919290602082105f146127aa57601f841160011461277a57612774929350612719565b90555b5b565b50906127a06127a5936001612797612791856107e7565b92612747565b820191016126e5565b61272b565b612777565b506127e182936127bb6001946107e7565b6127da6127c785612747565b820192601f8616806127ec575b50612747565b01906126e5565b600202179055612778565b6127f890888603612649565b5f6127d4565b92909168010000000000000000821161285e576020115f1461284f57602081105f146128335761282d91612719565b90555b5b565b60019160ff1916612843846107e7565b55600202019055612830565b60019150600202019055612831565b6106ad565b90815461286f816107bd565b90818311612898575b818310612886575b50505050565b61288f93612751565b5f808080612880565b6128a4838383876127fe565b612878565b5f6128b391612863565b565b905f036128c7576128c5906128a9565b565b6125d8565b600190818003010490565b5f80910155565b905f036128f0576128ee906128d7565b565b6125d8565b5b818110612901575050565b8061290e5f6001936128de565b016128f6565b9091828110612923575b505050565b61294161293b61293561294c956128cc565b926128cc565b926108e6565b9182019101906128f5565b5f808061291e565b9068010000000000000000811161297d578161297261297b936108ae565b90828155612914565b565b6106ad565b5f61298c91612954565b565b905f036129a05761299e90612982565b565b6125d8565b60089060018203010490565b5b8181106129bd575050565b806129ca5f6001936126d1565b016129b2565b9190918282106129e0575b505050565b600460086129f0612a18956129a5565b612a026129fc866129a5565b946109f6565b93840193019306025f8111612a20575b506129b1565b5f80806129db565b612a2d9060018303612649565b5f612a12565b90680100000000000000008111612a5c5781612a51612a5a936109f2565b908281556129d0565b565b6106ad565b5f612a6b91612a33565b565b905f03612a7f57612a7d90612a61565b565b6125d8565b5f6002612aaa92612a97838083016128b5565b612aa4836001830161298e565b01612a6d565b565b905f03612abe57612abc90612a84565b565b6125d8565b5b818110612acf575050565b80612adc5f600393612aac565b01612ac4565b9091828110612af1575b505050565b612b0f612b09612b03612b1a9561263b565b9261263b565b926107a0565b918201910190612ac3565b5f8080612aec565b90680100000000000000008111612b4b5781612b40612b4993610768565b90828155612ae2565b565b6106ad565b5190565b5190565b9190601f8111612b68575b505050565b612b74612b99936107e7565b906020612b8084612747565b83019310612ba1575b612b9290612747565b01906126e5565b5f8080612b63565b9150612b9281929050612b89565b90612bb981610082565b9067ffffffffffffffff8211612c7957612bdd82612bd785546107bd565b85612b58565b602090601f8311600114612c1157918091612c00935f92612c05575b5050612719565b90555b565b90915001515f80612bf9565b601f19831691612c20856107e7565b925f5b818110612c6157509160029391856001969410612c47575b50505002019055612c03565b612c57910151601f841690612704565b90555f8080612c3b565b91936020600181928787015181550195019201612c23565b6106ad565b90612c8891612baf565b565b5190565b5190565b612c9c90516100e8565b90565b5f1b90565b90612cbf6fffffffffffffffffffffffffffffffff91612c9f565b9181191691161790565b612cdd612cd8612ce2926100e8565b61061b565b6100e8565b90565b90565b90612cfd612cf8612d0492612cc9565b612ce5565b8254612ca4565b9055565b60801b90565b90612d2a6fffffffffffffffffffffffffffffffff1991612d08565b9181191691161790565b90612d49612d44612d5092612cc9565b612ce5565b8254612d0e565b9055565b90612d7e60205f612d8494612d76828201612d70848801612c92565b90612ce8565b019201612c92565b90612d34565b565b90612d9091612d54565b565b612db7612db1612da1846100d5565b93612dac8585612954565b6100e2565b916108e6565b5f915b838310612dc75750505050565b6001602082612ddf612dd98495612c8e565b86612d86565b01920192019190612dba565b90612df591612d92565b565b5190565b612e059051610199565b90565b91906008612e26910291612e2063ffffffff84612663565b92612663565b9181191691161790565b90565b90612e3d81610186565b9067ffffffffffffffff8211612f2257612e63612e6991612e5e8486612a33565b610193565b926109f6565b60088204915f5b838110612ed957506008830290035f8111612e8c575b50505050565b925f935f5b818110612ea65750505001555f808080612e86565b9091946020612ecd600192612ec2612ebd8a612dfb565b612e30565b908560040290612e08565b96019101919091612e91565b5f5f5b60088110612ef35750906001918185015501612e70565b95906020612f19600192612f0e612f0986612dfb565b612e30565b908a60040290612e08565b92019601612edc565b6106ad565b90612f3191612e33565b565b90612f7760406002612f7d94612f565f8201612f505f8801612b54565b90612c7e565b612f6f60018201612f6960208801612c8a565b90612deb565b019201612df7565b90612f27565b565b90612f8991612f33565b565b612fb0612faa612f9a8461006f565b93612fa58585612b22565b61007c565b916107a0565b5f915b838310612fc05750505050565b6003602082612fd9612fd3600195612b50565b86612f7f565b01920192019190612fb3565b90612fef91612f8b565b565b5190565b613000906002612606565b90565b600190818003010490565b5b81811061301a575050565b806130275f6001936128b5565b0161300f565b909182811061303c575b505050565b61305a61305461304e61306595613003565b92613003565b92610e7b565b91820191019061300e565b5f8080613037565b90680100000000000000008111613096578161308b61309493610e43565b9082815561302d565b565b6106ad565b5f6130a59161306d565b565b905f036130b9576130b79061309b565b565b6125d8565b5f60016130d7926130d1838083016128b5565b016130a7565b565b905f036130eb576130e9906130be565b565b6125d8565b5b8181106130fc575050565b806131095f6002936130d9565b016130f1565b909182811061311e575b505050565b61313c61313661313061314795612ff5565b92612ff5565b92610e3a565b9182019101906130f0565b5f8080613119565b90680100000000000000008111613178578161316d61317693610e02565b9082815561310f565b565b6106ad565b5190565b5190565b6131aa6131a4613194846102e9565b9361319f858561306d565b6102f6565b91610e7b565b5f915b8383106131ba5750505050565b60016020826131d26131cc8495612b54565b86612c7e565b019201920191906131ad565b906131e891613185565b565b906132156020600161321b9461320d5f82016132075f8801612b54565b90612c7e565b019201613181565b906131de565b565b90613227916131ea565b565b61324e613248613238846102d6565b93613243858561314f565b6102e3565b91610e3a565b5f915b83831061325e5750505050565b600260208261327761327160019561317d565b8661321d565b01920192019190613251565b9061328d91613229565b565b5190565b61329e906002612606565b90565b5f60016132ba926132b4838083016128b5565b016128b5565b565b905f036132ce576132cc906132a1565b565b6125d8565b5b8181106132df575050565b806132ec5f6002936132bc565b016132d4565b9091828110613301575b505050565b61331f61331961331361332a95613293565b92613293565b92610fbd565b9182019101906132d3565b5f80806132fc565b9068010000000000000000811161335b578161335061335993610f85565b908281556132f2565b565b6106ad565b5190565b9061338f60206001613395946133875f82016133815f8801612b54565b90612c7e565b019201612b54565b90612c7e565b565b906133a191613364565b565b6133c86133c26133b284610421565b936133bd8585613332565b61042e565b91610fbd565b5f915b8383106133d85750505050565b60026020826133f16133eb600195613360565b86613397565b019201920191906133cb565b90613407916133a3565b565b61341390516104df565b90565b9061342260ff91612c9f565b9181191691161790565b613435906104df565b90565b90565b9061345061344b6134579261342c565b613438565b8254613416565b9055565b906134b8606060036134be9461347e5f82016134785f88016125eb565b90612fe5565b6134976001820161349160208801612ff1565b90613283565b6134b0600282016134aa6040880161328f565b906133fd565b019201613409565b9061343b565b565b906134ca9161345b565b565b6134d59061063a565b90565b9060206134ff5f6135079401546134fa6134f1826108fa565b5f8601906100ee565b61092f565b9101906100ee565b565b90613516816040936134d8565b0190565b60010190565b9061353d613537613530846108ae565b80936100d9565b926108e6565b905f5b81811061354d5750505090565b90919261356561355f60019286613509565b9461351a565b9101919091613540565b6135af91600261359f61358e606084015f86018582035f8701526107f0565b600185018482036020860152613520565b9201906040818403910152610ac6565b90565b906135bc9161356f565b90565b60030190565b906135d96135d283610768565b8092610073565b90816135ea602083028401946107a0565b925f915b8383106135fd57505050505090565b9091929394602061361e6136188385600195038752896135b2565b976135bf565b93019301919392906135ee565b60010190565b9061364561363e83610e43565b80926102ed565b908161365660208302840194610e7b565b925f915b83831061366957505050505090565b9091929394602061368a61368483856001950387528961087c565b9761362b565b930193019193929061365a565b6136c39160016136b3604083015f85018482035f8601526107f0565b9201906020818403910152613631565b90565b906136d091613697565b90565b60020190565b906136ed6136e683610e02565b80926102da565b90816136fe60208302840194610e3a565b925f915b83831061371157505050505090565b9091929394602061373261372c8385600195038752896136c6565b976136d3565b9301930191939290613702565b61376b91600161375b604083015f85018482035f8601526107f0565b92019060208184039101526107f0565b90565b906137789161373f565b90565b60020190565b9061379561378e83610f85565b8092610425565b90816137a660208302840194610fbd565b925f915b8383106137b957505050505090565b909192939460206137da6137d483856001950387528961376e565b9761377b565b93019301919392906137aa565b90613841906060613839600361383161382061380f608087015f8a018882035f8a01526135c5565b6001890187820360208901526136d9565b600288018682036040880152613781565b950154611070565b9101906104e4565b90565b6138599160208201915f8184039101526137e7565b90565b61386d6138685f61113e565b610646565b5f63a28e7f6091600590613897836009956138a2600661388b610052565b9889978896879561114b565b85526004850161258b565b03925af18015613929576138bf915f91613907575b5060016134c0565b336001906139026138f07f5a1ed425a160d1bc929890b991acc0e3d25a6f5db1ac65c07ee4c917708f76d4926134cc565b926138f9610052565b91829182613844565b0390a2565b61392391503d805f833e61391b81836106c1565b81019061180f565b5f6138b7565b6125c856fea26469706673582212208a225bf79dc0821e5142fcebfa5d0bcfd9466b71de12c0acda5c1f199e4cc77064736f6c634300081c0033
|
opengradient/types.py
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
|
-
from typing import List, Tuple, Union
|
|
3
|
-
from enum import Enum
|
|
2
|
+
from typing import List, Tuple, Union, Dict, Optional
|
|
3
|
+
from enum import Enum, IntEnum
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
class CandleOrder(IntEnum):
|
|
7
|
+
ASCENDING = 0
|
|
8
|
+
DESCENDING = 1
|
|
9
|
+
|
|
10
|
+
class CandleType(IntEnum):
|
|
11
|
+
HIGH = 0
|
|
12
|
+
LOW = 1
|
|
13
|
+
OPEN = 2
|
|
14
|
+
CLOSE = 3
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class HistoricalInputQuery:
|
|
18
|
+
currency_pair: str
|
|
19
|
+
total_candles: int
|
|
20
|
+
candle_duration_in_mins: int
|
|
21
|
+
order: CandleOrder
|
|
22
|
+
candle_types: List[CandleType]
|
|
23
|
+
|
|
24
|
+
def to_abi_format(self) -> tuple:
|
|
25
|
+
"""Convert to format expected by contract ABI"""
|
|
26
|
+
return (
|
|
27
|
+
self.currency_pair,
|
|
28
|
+
self.total_candles,
|
|
29
|
+
self.candle_duration_in_mins,
|
|
30
|
+
int(self.order),
|
|
31
|
+
[int(ct) for ct in self.candle_types]
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
@classmethod
|
|
35
|
+
def from_dict(cls, data: dict) -> 'HistoricalInputQuery':
|
|
36
|
+
"""Create HistoricalInputQuery from dictionary format"""
|
|
37
|
+
order = CandleOrder[data['order'].upper()]
|
|
38
|
+
candle_types = [CandleType[ct.upper()] for ct in data['candle_types']]
|
|
39
|
+
|
|
40
|
+
return cls(
|
|
41
|
+
currency_pair=data['currency_pair'],
|
|
42
|
+
total_candles=int(data['total_candles']),
|
|
43
|
+
candle_duration_in_mins=int(data['candle_duration_in_mins']),
|
|
44
|
+
order=order,
|
|
45
|
+
candle_types=candle_types
|
|
46
|
+
)
|
|
4
47
|
|
|
5
48
|
@dataclass
|
|
6
49
|
class Number:
|
|
@@ -90,4 +133,22 @@ class LLM(str, Enum):
|
|
|
90
133
|
class TEE_LLM(str, Enum):
|
|
91
134
|
"""Enum for LLM models available for TEE execution"""
|
|
92
135
|
|
|
93
|
-
META_LLAMA_3_1_70B_INSTRUCT = "meta-llama/Llama-3.1-70B-Instruct"
|
|
136
|
+
META_LLAMA_3_1_70B_INSTRUCT = "meta-llama/Llama-3.1-70B-Instruct"
|
|
137
|
+
|
|
138
|
+
@dataclass
|
|
139
|
+
class SchedulerParams:
|
|
140
|
+
frequency: int
|
|
141
|
+
duration_hours: int
|
|
142
|
+
|
|
143
|
+
@property
|
|
144
|
+
def end_time(self) -> int:
|
|
145
|
+
return int(time.time()) + (self.duration_hours * 60 * 60)
|
|
146
|
+
|
|
147
|
+
@staticmethod
|
|
148
|
+
def from_dict(data: Optional[Dict[str, int]]) -> Optional['SchedulerParams']:
|
|
149
|
+
if data is None:
|
|
150
|
+
return None
|
|
151
|
+
return SchedulerParams(
|
|
152
|
+
frequency=data.get('frequency', 600),
|
|
153
|
+
duration_hours=data.get('duration_hours', 2)
|
|
154
|
+
)
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
opengradient/__init__.py,sha256=
|
|
1
|
+
opengradient/__init__.py,sha256=uU_Onxf-4JMQ9gHMQPbJDbU93kbB8qNayBLrnZnRFzg,12742
|
|
2
2
|
opengradient/account.py,sha256=2B7rtCXQDX-yF4U69h8B9-OUreJU4IqoGXG_1Hn9nWs,1150
|
|
3
|
-
opengradient/cli.py,sha256=
|
|
4
|
-
opengradient/client.py,sha256=
|
|
3
|
+
opengradient/cli.py,sha256=vYE_zr1oKYOkiAEWRyW3cR6jJQr6xKterjI1grhmROg,26399
|
|
4
|
+
opengradient/client.py,sha256=Dybu7g5kP7rJKQq0NbNjamJUVNTYLdSFdEd3ZA6fiaQ,42668
|
|
5
5
|
opengradient/defaults.py,sha256=6tsW9Z84z6YtITCsULTTgnN0KRUZjfSoeWJZqdWkYCo,384
|
|
6
6
|
opengradient/exceptions.py,sha256=v4VmUGTvvtjhCZAhR24Ga42z3q-DzR1Y5zSqP_yn2Xk,3366
|
|
7
|
-
opengradient/types.py,sha256
|
|
7
|
+
opengradient/types.py,sha256=Z8HFmCxNiC4Pr8qVoALF_jYOAqIJuKsiJSgq96q-sxQ,4175
|
|
8
8
|
opengradient/utils.py,sha256=lUDPmyPqLwpZI-owyN6Rm3QvUjOn5pLN5G1QyriVm-E,6994
|
|
9
|
+
opengradient/abi/ModelExecutorHistorical.abi,sha256=Z-2CQRG2BO5R-Ix1OLgQD9GCcHZw8w6-Zth3rzNX0TU,3278
|
|
9
10
|
opengradient/abi/inference.abi,sha256=MR5u9npZ-Yx2EqRW17_M-UnGgFF3mMEMepOwaZ-Bkgc,7040
|
|
11
|
+
opengradient/contracts/templates/ModelExecutorHistorical.bin,sha256=J_bHglQOXEsv44BkBkMvA9uWz7c9c8gdqqSb0KxIzkI,34924
|
|
10
12
|
opengradient/llm/__init__.py,sha256=J1W_AKPntqlDqLeflhn2x7A0i-dkMT-ol3jlEdFgMWU,1135
|
|
11
13
|
opengradient/llm/og_langchain.py,sha256=-QBGFdQJ1cdSCTUUerajHXNvV5Xi9yaVpa3BeAqKZbQ,4541
|
|
12
14
|
opengradient/llm/og_openai.py,sha256=3oaQOQnA7RzQ-LcFw-AQRn2RON8tsprSa9bGtyD88OE,3853
|
|
@@ -16,9 +18,9 @@ opengradient/proto/__init__.py,sha256=AhaSmrqV0TXGzCKaoPV8-XUvqs2fGAJBM2aOmDpkNb
|
|
|
16
18
|
opengradient/proto/infer.proto,sha256=13eaEMcppxkBF8yChptsX9HooWFwJKze7oLZNl-LEb8,1217
|
|
17
19
|
opengradient/proto/infer_pb2.py,sha256=wg2vjLQCNv6HRhYuIqgj9xivi3nO4IPz6E5wh2dhDqY,3446
|
|
18
20
|
opengradient/proto/infer_pb2_grpc.py,sha256=y5GYwD1EdNs892xx58jdfyA0fO5QC7k3uZOtImTHMiE,6891
|
|
19
|
-
opengradient-0.3.
|
|
20
|
-
opengradient-0.3.
|
|
21
|
-
opengradient-0.3.
|
|
22
|
-
opengradient-0.3.
|
|
23
|
-
opengradient-0.3.
|
|
24
|
-
opengradient-0.3.
|
|
21
|
+
opengradient-0.3.23.dist-info/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
|
|
22
|
+
opengradient-0.3.23.dist-info/METADATA,sha256=EhqCC5WEHRypug84TG0flHH-MsMDKKRN9B5D2DydaJY,8754
|
|
23
|
+
opengradient-0.3.23.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
24
|
+
opengradient-0.3.23.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
|
|
25
|
+
opengradient-0.3.23.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
|
|
26
|
+
opengradient-0.3.23.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|