opengradient 0.4.12__tar.gz → 0.4.13__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.
Files changed (40) hide show
  1. {opengradient-0.4.12/src/opengradient.egg-info → opengradient-0.4.13}/PKG-INFO +1 -1
  2. {opengradient-0.4.12 → opengradient-0.4.13}/pyproject.toml +1 -1
  3. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/client.py +53 -5
  4. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/utils.py +5 -14
  5. {opengradient-0.4.12 → opengradient-0.4.13/src/opengradient.egg-info}/PKG-INFO +1 -1
  6. {opengradient-0.4.12 → opengradient-0.4.13}/LICENSE +0 -0
  7. {opengradient-0.4.12 → opengradient-0.4.13}/README.md +0 -0
  8. {opengradient-0.4.12 → opengradient-0.4.13}/setup.cfg +0 -0
  9. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/__init__.py +0 -0
  10. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/abi/InferencePrecompile.abi +0 -0
  11. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/abi/PriceHistoryInference.abi +0 -0
  12. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/abi/WorkflowScheduler.abi +0 -0
  13. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/abi/inference.abi +0 -0
  14. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/account.py +0 -0
  15. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/alphasense/__init__.py +0 -0
  16. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/alphasense/read_workflow_tool.py +0 -0
  17. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/alphasense/run_model_tool.py +0 -0
  18. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/alphasense/types.py +0 -0
  19. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/bin/PriceHistoryInference.bin +0 -0
  20. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/cli.py +0 -0
  21. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/defaults.py +0 -0
  22. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/exceptions.py +0 -0
  23. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/llm/__init__.py +0 -0
  24. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/llm/og_langchain.py +0 -0
  25. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/llm/og_openai.py +0 -0
  26. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/proto/__init__.py +0 -0
  27. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/proto/infer.proto +0 -0
  28. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/proto/infer_pb2.py +0 -0
  29. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/proto/infer_pb2_grpc.py +0 -0
  30. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/types.py +0 -0
  31. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/workflow_models/__init__.py +0 -0
  32. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/workflow_models/constants.py +0 -0
  33. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/workflow_models/types.py +0 -0
  34. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/workflow_models/utils.py +0 -0
  35. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient/workflow_models/workflow_models.py +0 -0
  36. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient.egg-info/SOURCES.txt +0 -0
  37. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient.egg-info/dependency_links.txt +0 -0
  38. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient.egg-info/entry_points.txt +0 -0
  39. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient.egg-info/requires.txt +0 -0
  40. {opengradient-0.4.12 → opengradient-0.4.13}/src/opengradient.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opengradient
3
- Version: 0.4.12
3
+ Version: 0.4.13
4
4
  Summary: Python SDK for OpenGradient decentralized model management & inference services
5
5
  Author-email: OpenGradient <oliver@opengradient.ai>
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "opengradient"
7
- version = "0.4.12"
7
+ version = "0.4.13"
8
8
  description = "Python SDK for OpenGradient decentralized model management & inference services"
9
9
  authors = [{name = "OpenGradient", email = "oliver@opengradient.ai"}]
10
10
  license = {file = "LICENSE"}
@@ -2,6 +2,7 @@ import json
2
2
  import logging
3
3
  import os
4
4
  import time
5
+ import base64
5
6
  from pathlib import Path
6
7
  from typing import Any, Dict, List, Optional, Union, Callable
7
8
 
@@ -318,8 +319,8 @@ class Client:
318
319
  # check inference directly from node
319
320
  parsed_logs = precompile_contract.events.ModelInferenceEvent().process_receipt(tx_receipt, errors=DISCARD)
320
321
  inference_id = parsed_logs[0]["args"]["inferenceID"]
321
- inference_result = self.get_inference_result_from_node(inference_id)
322
- model_output = inference_result
322
+ inference_result = self._get_inference_result_from_node(inference_id, inference_mode)
323
+ model_output = convert_to_model_output(inference_result)
323
324
 
324
325
  return InferenceResult(tx_hash.hex(), model_output)
325
326
 
@@ -971,7 +972,7 @@ class Client:
971
972
  return [convert_array_to_model_output(result) for result in results]
972
973
 
973
974
 
974
- def get_inference_result_from_node(self, inference_id: str) -> str:
975
+ def _get_inference_result_from_node(self, inference_id: str, inference_mode: InferenceMode) -> Dict:
975
976
  """
976
977
  Get the inference result from node.
977
978
 
@@ -979,7 +980,7 @@ class Client:
979
980
  inference_id (str): Inference id for a inference request
980
981
 
981
982
  Returns:
982
- str: The inference result as returned by the node
983
+ Dict: The inference result as returned by the node
983
984
 
984
985
  Raises:
985
986
  OpenGradientError: If the request fails or returns an error
@@ -990,7 +991,54 @@ class Client:
990
991
 
991
992
  response = requests.get(url)
992
993
  if response.status_code == 200:
993
- return response.json()
994
+ resp = response.json()
995
+ inference_result = resp.get("inference_results", {})
996
+ if inference_result:
997
+ decoded_bytes = base64.b64decode(inference_result[0])
998
+ decoded_string = decoded_bytes.decode('utf-8')
999
+ output = json.loads(decoded_string).get("InferenceResult",{})
1000
+ if output is None:
1001
+ raise OpenGradientError("Missing InferenceResult in inference output")
1002
+
1003
+ match inference_mode:
1004
+ case InferenceMode.VANILLA:
1005
+ if "VanillaResult" not in output:
1006
+ raise OpenGradientError("Missing VanillaResult in inference output")
1007
+ if "model_output" not in output["VanillaResult"]:
1008
+ raise OpenGradientError("Missing model_output in VanillaResult")
1009
+ return {
1010
+ "output": output["VanillaResult"]["model_output"]
1011
+ }
1012
+
1013
+ case InferenceMode.TEE:
1014
+ if "TeeNodeResult" not in output:
1015
+ raise OpenGradientError("Missing TeeNodeResult in inference output")
1016
+ if "Response" not in output["TeeNodeResult"]:
1017
+ raise OpenGradientError("Missing Response in TeeNodeResult")
1018
+ if "VanillaResponse" in output["TeeNodeResult"]["Response"]:
1019
+ if "model_output" not in output["TeeNodeResult"]["Response"]["VanillaResponse"]:
1020
+ raise OpenGradientError("Missing model_output in VanillaResponse")
1021
+ return {
1022
+ "output": output["TeeNodeResult"]["Response"]["VanillaResponse"]["model_output"]
1023
+ }
1024
+
1025
+ else:
1026
+ raise OpenGradientError("Missing VanillaResponse in TeeNodeResult Response")
1027
+
1028
+ case InferenceMode.ZKML:
1029
+ if "ZkmlResult" not in output:
1030
+ raise OpenGradientError("Missing ZkmlResult in inference output")
1031
+ if "model_output" not in output["ZkmlResult"]:
1032
+ raise OpenGradientError("Missing model_output in ZkmlResult")
1033
+ return {
1034
+ "output": output["ZkmlResult"]["model_output"]
1035
+ }
1036
+
1037
+ case _:
1038
+ raise OpenGradientError(f"Invalid inference mode: {inference_mode}")
1039
+ else:
1040
+ return None
1041
+
994
1042
  else:
995
1043
  error_message = f"Failed to get inference result: HTTP {response.status_code}"
996
1044
  if response.text:
@@ -122,24 +122,18 @@ def convert_to_model_output(event_data: AttributeDict) -> Dict[str, np.ndarray]:
122
122
  We need to reshape each output array using the shape parameter in order to get the array
123
123
  back into its original shape.
124
124
  """
125
- logging.debug(f"Parsing event data: {event_data}")
126
-
127
125
  output_dict = {}
128
-
129
126
  output = event_data.get("output", {})
130
- logging.debug(f"Output data: {output}")
131
127
 
132
- if isinstance(output, AttributeDict):
133
- # Parse numbers
128
+ if isinstance(output, (AttributeDict, dict)):
134
129
  for tensor in output.get("numbers", []):
135
- logging.debug(f"Processing number tensor: {tensor}")
136
- if isinstance(tensor, AttributeDict):
130
+ if isinstance(tensor, (AttributeDict, dict)):
137
131
  name = tensor.get("name")
138
132
  shape = tensor.get("shape")
139
133
  values = []
140
134
  # Convert from fixed point back into np.float32
141
135
  for v in tensor.get("values", []):
142
- if isinstance(v, AttributeDict):
136
+ if isinstance(v, (AttributeDict, dict)):
143
137
  values.append(convert_to_float32(value=int(v.get("value")), decimals=int(v.get("decimals"))))
144
138
  else:
145
139
  logging.warning(f"Unexpected number type: {type(v)}")
@@ -149,8 +143,7 @@ def convert_to_model_output(event_data: AttributeDict) -> Dict[str, np.ndarray]:
149
143
 
150
144
  # Parse strings
151
145
  for tensor in output.get("strings", []):
152
- logging.debug(f"Processing string tensor: {tensor}")
153
- if isinstance(tensor, AttributeDict):
146
+ if isinstance(tensor, (AttributeDict, dict)):
154
147
  name = tensor.get("name")
155
148
  shape = tensor.get("shape")
156
149
  values = tensor.get("values", [])
@@ -160,8 +153,7 @@ def convert_to_model_output(event_data: AttributeDict) -> Dict[str, np.ndarray]:
160
153
 
161
154
  # Parse JSON dicts
162
155
  for tensor in output.get("jsons", []):
163
- logging.debug(f"Processing JSON tensor: {tensor}")
164
- if isinstance(tensor, AttributeDict):
156
+ if isinstance(tensor, (AttributeDict, dict)):
165
157
  name = tensor.get("name")
166
158
  value = tensor.get("value")
167
159
  output_dict[name] = np.array(json.loads(value))
@@ -172,7 +164,6 @@ def convert_to_model_output(event_data: AttributeDict) -> Dict[str, np.ndarray]:
172
164
  logging.warning(f"Unexpected output type: {type(output)}")
173
165
 
174
166
  logging.debug(f"Parsed output: {output_dict}")
175
-
176
167
  return output_dict
177
168
 
178
169
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opengradient
3
- Version: 0.4.12
3
+ Version: 0.4.13
4
4
  Summary: Python SDK for OpenGradient decentralized model management & inference services
5
5
  Author-email: OpenGradient <oliver@opengradient.ai>
6
6
  License: MIT License
File without changes
File without changes
File without changes