opengradient 0.2.4__tar.gz → 0.2.6__tar.gz
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-0.2.4/src/opengradient.egg-info → opengradient-0.2.6}/PKG-INFO +1 -1
- {opengradient-0.2.4 → opengradient-0.2.6}/pyproject.toml +1 -1
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient/__init__.py +8 -4
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient/cli.py +13 -8
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient/client.py +23 -21
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient/types.py +2 -2
- {opengradient-0.2.4 → opengradient-0.2.6/src/opengradient.egg-info}/PKG-INFO +1 -1
- {opengradient-0.2.4 → opengradient-0.2.6}/LICENSE +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/README.md +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/setup.cfg +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient/abi/inference.abi +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient/exceptions.py +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient/utils.py +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient.egg-info/SOURCES.txt +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient.egg-info/dependency_links.txt +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient.egg-info/entry_points.txt +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient.egg-info/requires.txt +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/src/opengradient.egg-info/top_level.txt +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/tests/test_api.py +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/tests/test_exceptions.py +0 -0
- {opengradient-0.2.4 → opengradient-0.2.6}/tests/test_integration.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "opengradient"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.6"
|
|
8
8
|
description = "A Python SDK for OpenGradient inference services"
|
|
9
9
|
authors = [{name = "OpenGradient", email = "oliver@opengradient.ai"}]
|
|
10
10
|
license = {file = "LICENSE"}
|
|
@@ -2,11 +2,15 @@ from .client import Client
|
|
|
2
2
|
from .exceptions import OpenGradientError, FileNotFoundError, UploadError, InferenceError, ResultRetrievalError
|
|
3
3
|
from .types import ModelInput, InferenceMode, Number, NumberTensor, StringTensor, ModelOutput
|
|
4
4
|
|
|
5
|
-
__version__ = "0.2.
|
|
5
|
+
__version__ = "0.2.6"
|
|
6
6
|
|
|
7
7
|
_client = None
|
|
8
8
|
|
|
9
|
-
def init(private_key
|
|
9
|
+
def init(private_key="cd09980ef6e280afc3900d2d6801f9e9c5d858a5deaeeab74a65643f5ff1a4c1",
|
|
10
|
+
rpc_url="http://18.218.115.248:8545",
|
|
11
|
+
contract_address="0x350E0A430b2B1563481833a99523Cfd17a530e4e",
|
|
12
|
+
email="test@test.com",
|
|
13
|
+
password="Test-123"):
|
|
10
14
|
global _client
|
|
11
15
|
_client = Client(private_key=private_key, rpc_url=rpc_url, contract_address=contract_address, email=email, password=password)
|
|
12
16
|
|
|
@@ -30,7 +34,7 @@ def infer(model_cid, inference_mode, model_input):
|
|
|
30
34
|
raise RuntimeError("OpenGradient client not initialized. Call og.init() first.")
|
|
31
35
|
return _client.infer(model_cid, inference_mode, model_input)
|
|
32
36
|
|
|
33
|
-
def
|
|
37
|
+
def login(email: str, password: str):
|
|
34
38
|
if _client is None:
|
|
35
39
|
raise RuntimeError("OpenGradient client not initialized. Call og.init() first.")
|
|
36
|
-
return _client.
|
|
40
|
+
return _client.login(email, password)
|
|
@@ -40,8 +40,8 @@ Dict = DictParamType()
|
|
|
40
40
|
# Support inference modes
|
|
41
41
|
InferenceModes = {
|
|
42
42
|
"VANILLA": opengradient.InferenceMode.VANILLA,
|
|
43
|
-
"ZKML": opengradient.InferenceMode.
|
|
44
|
-
"TEE": opengradient.InferenceMode.
|
|
43
|
+
"ZKML": opengradient.InferenceMode.ZKML,
|
|
44
|
+
"TEE": opengradient.InferenceMode.TEE,
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
# TODO (Kyle): Once we're farther into development, we should remove the defaults for these options
|
|
@@ -89,9 +89,14 @@ def cli(ctx, api_key, rpc_url, contract_address, email, password):
|
|
|
89
89
|
click.echo(f"Failed to create OpenGradient client: {str(e)}")
|
|
90
90
|
|
|
91
91
|
@cli.command()
|
|
92
|
-
@click.
|
|
93
|
-
def client_settings(
|
|
92
|
+
@click.pass_context
|
|
93
|
+
def client_settings(ctx):
|
|
94
94
|
"""Display OpenGradient client settings"""
|
|
95
|
+
client = ctx.obj
|
|
96
|
+
if not client:
|
|
97
|
+
click.echo("Client not initialized")
|
|
98
|
+
ctx.exit(1)
|
|
99
|
+
|
|
95
100
|
click.echo("Settings for OpenGradient client:")
|
|
96
101
|
click.echo(f"\tAPI key ({API_KEY_ENV}): {client.private_key}")
|
|
97
102
|
click.echo(f"\tRPC URL ({RPC_URL_ENV}): {client.rpc_url}")
|
|
@@ -140,14 +145,14 @@ def create_version(client, model_id, notes, is_major):
|
|
|
140
145
|
click.echo(f"Error creating version: {str(e)}")
|
|
141
146
|
|
|
142
147
|
@cli.command()
|
|
143
|
-
@click.argument('
|
|
148
|
+
@click.argument('model_cid', type=str)
|
|
144
149
|
@click.argument('inference_mode', type=click.Choice(InferenceModes.keys()), default="VANILLA")
|
|
145
150
|
@click.argument('input_data', type=Dict, required=False)
|
|
146
151
|
@click.option('--input_file',
|
|
147
152
|
type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True, path_type=Path),
|
|
148
153
|
help="Optional file input for model inference -- must be JSON")
|
|
149
154
|
@click.pass_context
|
|
150
|
-
def infer(ctx,
|
|
155
|
+
def infer(ctx, model_cid, inference_mode, input_data, input_file):
|
|
151
156
|
"""Run inference on a model"""
|
|
152
157
|
client = ctx.obj
|
|
153
158
|
try:
|
|
@@ -169,8 +174,8 @@ def infer(ctx, model_id, inference_mode, input_data, input_file):
|
|
|
169
174
|
model_input = json.load(file)
|
|
170
175
|
|
|
171
176
|
# Parse input data from string to dict
|
|
172
|
-
click.echo(f"Running {inference_mode} inference for {
|
|
173
|
-
tx_hash, model_output = client.infer(model_cid=
|
|
177
|
+
click.echo(f"Running {inference_mode} inference for {model_cid}...")
|
|
178
|
+
tx_hash, model_output = client.infer(model_cid=model_cid, inference_mode=InferenceModes[inference_mode], model_input=model_input)
|
|
174
179
|
click.secho("Success!", fg="green")
|
|
175
180
|
click.echo(f"\nTransaction Hash: \n{tx_hash}")
|
|
176
181
|
click.echo(f"\nInference result: \n{model_output}")
|
|
@@ -49,7 +49,7 @@ class Client:
|
|
|
49
49
|
inference_abi = json.load(abi_file)
|
|
50
50
|
self.abi = inference_abi
|
|
51
51
|
|
|
52
|
-
self.
|
|
52
|
+
self.login(email, password)
|
|
53
53
|
|
|
54
54
|
def _initialize_web3(self):
|
|
55
55
|
"""
|
|
@@ -104,20 +104,20 @@ class Client:
|
|
|
104
104
|
response.raise_for_status()
|
|
105
105
|
|
|
106
106
|
json_response = response.json()
|
|
107
|
-
|
|
108
|
-
if not
|
|
109
|
-
raise Exception(f"Model creation response missing '
|
|
110
|
-
logging.info(f"Model creation successful. Model
|
|
107
|
+
model_id = json_response.get('id')
|
|
108
|
+
if not model_id:
|
|
109
|
+
raise Exception(f"Model creation response missing 'id'. Full response: {json_response}")
|
|
110
|
+
logging.info(f"Model creation successful. Model ID: {model_id}")
|
|
111
111
|
|
|
112
112
|
# Create the specified version for the newly created model
|
|
113
113
|
try:
|
|
114
|
-
version_response = self.create_version(
|
|
115
|
-
logging.info(f"Version creation successful. Version
|
|
114
|
+
version_response = self.create_version(model_id, version)
|
|
115
|
+
logging.info(f"Version creation successful. Version ID: {version_response['versionString']}")
|
|
116
116
|
except Exception as ve:
|
|
117
117
|
logging.error(f"Version creation failed, but model was created. Error: {str(ve)}")
|
|
118
|
-
return {"id":
|
|
118
|
+
return {"id": model_id, "versionString": None, "version_error": str(ve)}
|
|
119
119
|
|
|
120
|
-
return {"
|
|
120
|
+
return {"id": model_id, "versionString": version_response["versionString"]}
|
|
121
121
|
|
|
122
122
|
except requests.RequestException as e:
|
|
123
123
|
logging.error(f"Model creation failed: {str(e)}")
|
|
@@ -174,12 +174,12 @@ class Client:
|
|
|
174
174
|
logging.info(f"Server returned an empty list. Assuming version was created successfully.")
|
|
175
175
|
return {"versionString": "Unknown", "note": "Created based on empty response"}
|
|
176
176
|
elif isinstance(json_response, dict):
|
|
177
|
-
|
|
178
|
-
if not
|
|
177
|
+
versionString = json_response.get('versionString')
|
|
178
|
+
if not versionString:
|
|
179
179
|
logging.warning(f"'versionString' not found in response. Response: {json_response}")
|
|
180
|
-
return {"versionString": "Unknown", "note": "Version
|
|
181
|
-
logging.info(f"Version creation successful. Version
|
|
182
|
-
return {"versionString":
|
|
180
|
+
return {"versionString": "Unknown", "note": "Version ID not provided in response"}
|
|
181
|
+
logging.info(f"Version creation successful. Version ID: {versionString}")
|
|
182
|
+
return {"versionString": versionString}
|
|
183
183
|
else:
|
|
184
184
|
logging.error(f"Unexpected response type: {type(json_response)}. Content: {json_response}")
|
|
185
185
|
raise Exception(f"Unexpected response type: {type(json_response)}")
|
|
@@ -205,7 +205,7 @@ class Client:
|
|
|
205
205
|
version (str): The version identifier for the model.
|
|
206
206
|
|
|
207
207
|
Returns:
|
|
208
|
-
dict: The
|
|
208
|
+
dict: The processed result.
|
|
209
209
|
|
|
210
210
|
Raises:
|
|
211
211
|
OpenGradientError: If the upload fails.
|
|
@@ -247,17 +247,17 @@ class Client:
|
|
|
247
247
|
response = requests.post(url, data=monitor, headers=headers, timeout=3600) # 1 hour timeout
|
|
248
248
|
|
|
249
249
|
logging.info(f"Response received. Status code: {response.status_code}")
|
|
250
|
-
logging.
|
|
251
|
-
logging.debug(f"Response content: {response.text[:1000]}...") # Log first 1000 characters
|
|
250
|
+
logging.info(f"Full response content: {response.text}") # Log the full response content
|
|
252
251
|
|
|
253
252
|
if response.status_code == 201:
|
|
254
253
|
if response.content and response.content != b'null':
|
|
255
254
|
json_response = response.json()
|
|
256
|
-
logging.info(f"
|
|
257
|
-
|
|
255
|
+
logging.info(f"JSON response: {json_response}") # Log the parsed JSON response
|
|
256
|
+
logging.info(f"Upload successful. CID: {json_response.get('ipfsCid', 'N/A')}")
|
|
257
|
+
result = {"model_cid": json_response.get("ipfsCid"), "size": json_response.get("size")}
|
|
258
258
|
else:
|
|
259
259
|
logging.warning("Empty or null response content received. Assuming upload was successful.")
|
|
260
|
-
|
|
260
|
+
result = {"model_cid": None, "size": None}
|
|
261
261
|
elif response.status_code == 500:
|
|
262
262
|
error_message = "Internal server error occurred. Please try again later or contact support."
|
|
263
263
|
logging.error(error_message)
|
|
@@ -267,6 +267,8 @@ class Client:
|
|
|
267
267
|
logging.error(f"Upload failed with status code {response.status_code}: {error_message}")
|
|
268
268
|
raise OpenGradientError(f"Upload failed: {error_message}", status_code=response.status_code)
|
|
269
269
|
|
|
270
|
+
return result
|
|
271
|
+
|
|
270
272
|
except requests.RequestException as e:
|
|
271
273
|
logging.error(f"Request exception during upload: {str(e)}")
|
|
272
274
|
if hasattr(e, 'response') and e.response is not None:
|
|
@@ -394,7 +396,7 @@ class Client:
|
|
|
394
396
|
logging.error(f"Error in infer method: {str(e)}", exc_info=True)
|
|
395
397
|
raise OpenGradientError(f"Inference failed: {str(e)}")
|
|
396
398
|
|
|
397
|
-
def
|
|
399
|
+
def login(self, email, password):
|
|
398
400
|
try:
|
|
399
401
|
self.user = self.auth.sign_in_with_email_and_password(email, password)
|
|
400
402
|
return self.user
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|