opengradient 0.2.4__tar.gz → 0.2.5__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.5}/PKG-INFO +1 -1
- {opengradient-0.2.4 → opengradient-0.2.5}/pyproject.toml +1 -1
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient/__init__.py +8 -4
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient/cli.py +13 -8
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient/client.py +17 -17
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient/types.py +2 -2
- {opengradient-0.2.4 → opengradient-0.2.5/src/opengradient.egg-info}/PKG-INFO +1 -1
- {opengradient-0.2.4 → opengradient-0.2.5}/LICENSE +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/README.md +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/setup.cfg +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient/abi/inference.abi +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient/exceptions.py +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient/utils.py +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient.egg-info/SOURCES.txt +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient.egg-info/dependency_links.txt +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient.egg-info/entry_points.txt +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient.egg-info/requires.txt +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/src/opengradient.egg-info/top_level.txt +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/tests/test_api.py +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/tests/test_exceptions.py +0 -0
- {opengradient-0.2.4 → opengradient-0.2.5}/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.5"
|
|
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.5"
|
|
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['version_id']}")
|
|
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, "version_id": None, "version_error": str(ve)}
|
|
119
119
|
|
|
120
|
-
return {"
|
|
120
|
+
return {"id": model_id, "version_id": version_response["version_id"]}
|
|
121
121
|
|
|
122
122
|
except requests.RequestException as e:
|
|
123
123
|
logging.error(f"Model creation failed: {str(e)}")
|
|
@@ -172,14 +172,14 @@ class Client:
|
|
|
172
172
|
|
|
173
173
|
if isinstance(json_response, list) and not json_response:
|
|
174
174
|
logging.info(f"Server returned an empty list. Assuming version was created successfully.")
|
|
175
|
-
return {"
|
|
175
|
+
return {"version_id": "Unknown", "note": "Created based on empty response"}
|
|
176
176
|
elif isinstance(json_response, dict):
|
|
177
|
-
|
|
178
|
-
if not
|
|
179
|
-
logging.warning(f"'
|
|
180
|
-
return {"
|
|
181
|
-
logging.info(f"Version creation successful. Version
|
|
182
|
-
return {"
|
|
177
|
+
version_id = json_response.get('version_id') or json_response.get('id')
|
|
178
|
+
if not version_id:
|
|
179
|
+
logging.warning(f"'version_id' not found in response. Response: {json_response}")
|
|
180
|
+
return {"version_id": "Unknown", "note": "Version ID not provided in response"}
|
|
181
|
+
logging.info(f"Version creation successful. Version ID: {version_id}")
|
|
182
|
+
return {"version_id": version_id}
|
|
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)}")
|
|
@@ -394,7 +394,7 @@ class Client:
|
|
|
394
394
|
logging.error(f"Error in infer method: {str(e)}", exc_info=True)
|
|
395
395
|
raise OpenGradientError(f"Inference failed: {str(e)}")
|
|
396
396
|
|
|
397
|
-
def
|
|
397
|
+
def login(self, email, password):
|
|
398
398
|
try:
|
|
399
399
|
self.user = self.auth.sign_in_with_email_and_password(email, password)
|
|
400
400
|
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
|