opengradient 0.3.22__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 +28 -7
- opengradient/client.py +62 -12
- opengradient/types.py +21 -2
- {opengradient-0.3.22.dist-info → opengradient-0.3.23.dist-info}/METADATA +1 -1
- {opengradient-0.3.22.dist-info → opengradient-0.3.23.dist-info}/RECORD +9 -9
- {opengradient-0.3.22.dist-info → opengradient-0.3.23.dist-info}/LICENSE +0 -0
- {opengradient-0.3.22.dist-info → opengradient-0.3.23.dist-info}/WHEEL +0 -0
- {opengradient-0.3.22.dist-info → opengradient-0.3.23.dist-info}/entry_points.txt +0 -0
- {opengradient-0.3.22.dist-info → opengradient-0.3.23.dist-info}/top_level.txt +0 -0
opengradient/__init__.py
CHANGED
|
@@ -5,7 +5,7 @@ from typing import Dict, List, Optional, Tuple, Any, Union
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from .client import Client
|
|
7
7
|
from .defaults import DEFAULT_INFERENCE_CONTRACT_ADDRESS, DEFAULT_RPC_URL
|
|
8
|
-
from .types import InferenceMode, LlmInferenceMode, LLM, TEE_LLM
|
|
8
|
+
from .types import HistoricalInputQuery, InferenceMode, LlmInferenceMode, LLM, TEE_LLM, SchedulerParams
|
|
9
9
|
from . import llm
|
|
10
10
|
from . import mltools
|
|
11
11
|
|
|
@@ -247,23 +247,44 @@ def generate_image(model: str, prompt: str, height: Optional[int] = None, width:
|
|
|
247
247
|
|
|
248
248
|
def new_workflow(
|
|
249
249
|
model_cid: str,
|
|
250
|
-
input_query: Dict[str, Any],
|
|
251
|
-
input_tensor_name: str
|
|
250
|
+
input_query: Union[Dict[str, Any], HistoricalInputQuery],
|
|
251
|
+
input_tensor_name: str,
|
|
252
|
+
scheduler_params: Optional[Union[Dict[str, int], SchedulerParams]] = None
|
|
252
253
|
) -> str:
|
|
253
254
|
"""
|
|
254
255
|
Deploy a new workflow contract with the specified parameters.
|
|
255
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
|
+
|
|
256
261
|
Args:
|
|
257
262
|
model_cid: IPFS CID of the model
|
|
258
|
-
input_query: Dictionary containing query parameters
|
|
263
|
+
input_query: Dictionary or HistoricalInputQuery containing query parameters
|
|
259
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.
|
|
260
271
|
|
|
261
272
|
Returns:
|
|
262
|
-
str: Deployed contract address
|
|
273
|
+
str: Deployed contract address. If scheduler_params was provided, the workflow
|
|
274
|
+
will be automatically executed according to the specified schedule.
|
|
263
275
|
"""
|
|
264
276
|
if _client is None:
|
|
265
277
|
raise RuntimeError("OpenGradient client not initialized. Call og.init(...) first.")
|
|
266
|
-
|
|
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
|
+
)
|
|
267
288
|
|
|
268
289
|
def read_workflow_result(contract_address: str) -> Dict[str, Union[str, Dict]]:
|
|
269
290
|
"""
|
|
@@ -314,7 +335,7 @@ __all__ = [
|
|
|
314
335
|
'upload',
|
|
315
336
|
'init',
|
|
316
337
|
'LLM',
|
|
317
|
-
'TEE_LLM'
|
|
338
|
+
'TEE_LLM',
|
|
318
339
|
'new_workflow',
|
|
319
340
|
'read_workflow_result',
|
|
320
341
|
'run_workflow'
|
opengradient/client.py
CHANGED
|
@@ -20,7 +20,8 @@ from opengradient.types import (
|
|
|
20
20
|
LlmInferenceMode,
|
|
21
21
|
LLM,
|
|
22
22
|
TEE_LLM,
|
|
23
|
-
ModelOutput
|
|
23
|
+
ModelOutput,
|
|
24
|
+
SchedulerParams
|
|
24
25
|
)
|
|
25
26
|
|
|
26
27
|
import grpc
|
|
@@ -812,18 +813,11 @@ class Client:
|
|
|
812
813
|
self,
|
|
813
814
|
model_cid: str,
|
|
814
815
|
input_query: Union[Dict[str, Any], HistoricalInputQuery],
|
|
815
|
-
input_tensor_name: str
|
|
816
|
+
input_tensor_name: str,
|
|
817
|
+
scheduler_params: Optional[SchedulerParams] = None
|
|
816
818
|
) -> str:
|
|
817
819
|
"""
|
|
818
820
|
Deploy a new workflow contract with the specified parameters.
|
|
819
|
-
|
|
820
|
-
Args:
|
|
821
|
-
model_cid: IPFS CID of the model
|
|
822
|
-
input_query: Either a HistoricalInputQuery object or dictionary containing query parameters
|
|
823
|
-
input_tensor_name: Name of the input tensor
|
|
824
|
-
|
|
825
|
-
Returns:
|
|
826
|
-
str: Deployed contract address
|
|
827
821
|
"""
|
|
828
822
|
if isinstance(input_query, dict):
|
|
829
823
|
input_query = HistoricalInputQuery.from_dict(input_query)
|
|
@@ -835,6 +829,8 @@ class Client:
|
|
|
835
829
|
with open(bin_path, 'r') as f:
|
|
836
830
|
bytecode = f.read().strip()
|
|
837
831
|
|
|
832
|
+
print("📦 Deploying workflow contract...")
|
|
833
|
+
|
|
838
834
|
# Create contract instance
|
|
839
835
|
contract = self._w3.eth.contract(abi=abi, bytecode=bytecode)
|
|
840
836
|
|
|
@@ -851,12 +847,66 @@ class Client:
|
|
|
851
847
|
'gasPrice': self._w3.eth.gas_price,
|
|
852
848
|
'chainId': self._w3.eth.chain_id
|
|
853
849
|
})
|
|
854
|
-
|
|
850
|
+
|
|
855
851
|
signed_txn = self._w3.eth.account.sign_transaction(transaction, self.private_key)
|
|
856
852
|
tx_hash = self._w3.eth.send_raw_transaction(signed_txn.raw_transaction)
|
|
857
853
|
tx_receipt = self._w3.eth.wait_for_transaction_receipt(tx_hash)
|
|
854
|
+
contract_address = tx_receipt.contractAddress
|
|
858
855
|
|
|
859
|
-
|
|
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
|
|
860
910
|
|
|
861
911
|
def read_workflow_result(self, contract_address: str) -> Any:
|
|
862
912
|
"""
|
opengradient/types.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
|
-
from typing import List, Tuple, Union
|
|
2
|
+
from typing import List, Tuple, Union, Dict, Optional
|
|
3
3
|
from enum import Enum, IntEnum
|
|
4
|
+
import time
|
|
4
5
|
|
|
5
6
|
class CandleOrder(IntEnum):
|
|
6
7
|
ASCENDING = 0
|
|
@@ -132,4 +133,22 @@ class LLM(str, Enum):
|
|
|
132
133
|
class TEE_LLM(str, Enum):
|
|
133
134
|
"""Enum for LLM models available for TEE execution"""
|
|
134
135
|
|
|
135
|
-
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,10 +1,10 @@
|
|
|
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
3
|
opengradient/cli.py,sha256=vYE_zr1oKYOkiAEWRyW3cR6jJQr6xKterjI1grhmROg,26399
|
|
4
|
-
opengradient/client.py,sha256=
|
|
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
9
|
opengradient/abi/ModelExecutorHistorical.abi,sha256=Z-2CQRG2BO5R-Ix1OLgQD9GCcHZw8w6-Zth3rzNX0TU,3278
|
|
10
10
|
opengradient/abi/inference.abi,sha256=MR5u9npZ-Yx2EqRW17_M-UnGgFF3mMEMepOwaZ-Bkgc,7040
|
|
@@ -18,9 +18,9 @@ opengradient/proto/__init__.py,sha256=AhaSmrqV0TXGzCKaoPV8-XUvqs2fGAJBM2aOmDpkNb
|
|
|
18
18
|
opengradient/proto/infer.proto,sha256=13eaEMcppxkBF8yChptsX9HooWFwJKze7oLZNl-LEb8,1217
|
|
19
19
|
opengradient/proto/infer_pb2.py,sha256=wg2vjLQCNv6HRhYuIqgj9xivi3nO4IPz6E5wh2dhDqY,3446
|
|
20
20
|
opengradient/proto/infer_pb2_grpc.py,sha256=y5GYwD1EdNs892xx58jdfyA0fO5QC7k3uZOtImTHMiE,6891
|
|
21
|
-
opengradient-0.3.
|
|
22
|
-
opengradient-0.3.
|
|
23
|
-
opengradient-0.3.
|
|
24
|
-
opengradient-0.3.
|
|
25
|
-
opengradient-0.3.
|
|
26
|
-
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
|