opengradient 0.4.6__py3-none-any.whl → 0.4.8__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/defaults.py CHANGED
@@ -3,6 +3,7 @@ DEFAULT_RPC_URL = "http://18.188.176.119:8545"
3
3
  DEFAULT_OG_FAUCET_URL = "https://faucet.opengradient.ai/?address="
4
4
  DEFAULT_HUB_SIGNUP_URL = "https://hub.opengradient.ai/signup"
5
5
  DEFAULT_INFERENCE_CONTRACT_ADDRESS = "0x8383C9bD7462F12Eb996DD02F78234C0421A6FaE"
6
+ DEFAULT_SCHEDULER_ADDRESS = "0x7179724De4e7FF9271FA40C0337c7f90C0508eF6"
6
7
  DEFAULT_BLOCKCHAIN_EXPLORER = "https://explorer.opengradient.ai/tx/"
7
8
  DEFAULT_IMAGE_GEN_HOST = "18.217.25.69"
8
9
  DEFAULT_IMAGE_GEN_PORT = 5125
@@ -10,7 +10,7 @@ from .og_langchain import *
10
10
  from .og_openai import *
11
11
 
12
12
 
13
- def langchain_adapter(private_key: str, model_cid: str, max_tokens: int = 300) -> OpenGradientChatModel:
13
+ def langchain_adapter(private_key: str, model_cid: LLM, max_tokens: int = 300) -> OpenGradientChatModel:
14
14
  """
15
15
  Returns an OpenGradient LLM that implements LangChain's LLM interface
16
16
  and can be plugged into LangChain agents.
@@ -1,5 +1,6 @@
1
1
  import json
2
- from typing import Any, Dict, List, Optional, Sequence, Union
2
+ from typing import Any, Dict, List, Optional, Sequence, Union, Callable
3
+ from typing_extensions import override
3
4
 
4
5
  from langchain.chat_models.base import BaseChatModel
5
6
  from langchain.schema import (
@@ -14,37 +15,45 @@ from langchain_core.callbacks.manager import CallbackManagerForLLMRun
14
15
  from langchain_core.messages import ToolCall
15
16
  from langchain_core.messages.tool import ToolMessage
16
17
  from langchain_core.tools import BaseTool
18
+ from langchain_core.runnables import Runnable
19
+ from langchain_core.language_models.base import LanguageModelInput
17
20
 
18
- from opengradient import Client, LlmInferenceMode
21
+ from opengradient import Client, LlmInferenceMode, LLM
19
22
  from opengradient.defaults import DEFAULT_INFERENCE_CONTRACT_ADDRESS, DEFAULT_RPC_URL
20
23
 
21
24
 
22
25
  class OpenGradientChatModel(BaseChatModel):
23
26
  """OpenGradient adapter class for LangChain chat model"""
24
27
 
25
- client: Client = None
26
- model_cid: str = None
27
- max_tokens: int = None
28
- tools: List[Dict] = []
28
+ _client: Client
29
+ _model_cid: LLM
30
+ _max_tokens: int
31
+ _tools: List[Dict] = []
29
32
 
30
- def __init__(self, private_key: str, model_cid: str, max_tokens: int = 300):
33
+ def __init__(self, private_key: str, model_cid: LLM, max_tokens: int = 300):
31
34
  super().__init__()
32
- self.client = Client(
35
+
36
+ self._client = Client(
33
37
  private_key=private_key, rpc_url=DEFAULT_RPC_URL, contract_address=DEFAULT_INFERENCE_CONTRACT_ADDRESS, email=None, password=None
34
38
  )
35
- self.model_cid = model_cid
36
- self.max_tokens = max_tokens
39
+ self._model_cid = model_cid
40
+ self._max_tokens = max_tokens
37
41
 
38
42
  @property
39
43
  def _llm_type(self) -> str:
40
44
  return "opengradient"
41
45
 
46
+ @override
42
47
  def bind_tools(
43
48
  self,
44
- tools: Sequence[Union[BaseTool, Dict]],
45
- ) -> "OpenGradientChatModel":
49
+ tools: Sequence[
50
+ Union[Dict[str, Any], type, Callable, BaseTool] # noqa: UP006
51
+ ],
52
+ **kwargs: Any,
53
+ ) -> Runnable[LanguageModelInput, BaseMessage]:
46
54
  """Bind tools to the model."""
47
- tool_dicts = []
55
+ tool_dicts: List[Dict] = []
56
+
48
57
  for tool in tools:
49
58
  if isinstance(tool, BaseTool):
50
59
  tool_dicts.append(
@@ -53,16 +62,20 @@ class OpenGradientChatModel(BaseChatModel):
53
62
  "function": {
54
63
  "name": tool.name,
55
64
  "description": tool.description,
56
- "parameters": tool.args_schema.schema() if hasattr(tool, "args_schema") else {},
65
+ "parameters": (
66
+ tool.args_schema.schema() if hasattr(tool, "args_schema") and tool.args_schema is not None else {}
67
+ ),
57
68
  },
58
69
  }
59
70
  )
60
71
  else:
61
72
  tool_dicts.append(tool)
62
73
 
63
- self.tools = tool_dicts
74
+ self._tools = tool_dicts
75
+
64
76
  return self
65
77
 
78
+ @override
66
79
  def _generate(
67
80
  self,
68
81
  messages: List[BaseMessage],
@@ -91,16 +104,17 @@ class OpenGradientChatModel(BaseChatModel):
91
104
  else:
92
105
  raise ValueError(f"Unexpected message type: {message}")
93
106
 
94
- chat_output = self.client.llm_chat(
95
- model_cid=self.model_cid,
107
+ chat_output = self._client.llm_chat(
108
+ model_cid=self._model_cid,
96
109
  messages=sdk_messages,
97
110
  stop_sequence=stop,
98
- max_tokens=self.max_tokens,
99
- tools=self.tools,
111
+ max_tokens=self._max_tokens,
112
+ tools=self._tools,
100
113
  inference_mode=LlmInferenceMode.VANILLA,
101
114
  )
102
- finish_reason = chat_output.finish_reason
103
- chat_response = chat_output.chat_output
115
+
116
+ finish_reason = chat_output.finish_reason or ""
117
+ chat_response = chat_output.chat_output or {}
104
118
 
105
119
  if "tool_calls" in chat_response and chat_response["tool_calls"]:
106
120
  tool_calls = []
@@ -116,5 +130,5 @@ class OpenGradientChatModel(BaseChatModel):
116
130
  @property
117
131
  def _identifying_params(self) -> Dict[str, Any]:
118
132
  return {
119
- "model_name": self.model_cid,
133
+ "model_name": self._model_cid,
120
134
  }
@@ -16,7 +16,7 @@ class OGCompletions(object):
16
16
 
17
17
  def create(
18
18
  self,
19
- model: str,
19
+ model: og.LLM,
20
20
  messages: List[object],
21
21
  tools: List[object],
22
22
  tool_choice: str,
opengradient/types.py CHANGED
@@ -15,6 +15,7 @@ class CandleType(IntEnum):
15
15
  LOW = 1
16
16
  OPEN = 2
17
17
  CLOSE = 3
18
+ VOLUME = 4
18
19
 
19
20
 
20
21
  @dataclass
@@ -37,20 +38,6 @@ class HistoricalInputQuery:
37
38
  [int(ct) for ct in self.candle_types],
38
39
  )
39
40
 
40
- @classmethod
41
- def from_dict(cls, data: dict) -> "HistoricalInputQuery":
42
- """Create HistoricalInputQuery from dictionary format"""
43
- order = CandleOrder[data["order"].upper()]
44
- candle_types = [CandleType[ct.upper()] for ct in data["candle_types"]]
45
- return cls(
46
- base=data["base"],
47
- quote=data["quote"],
48
- total_candles=int(data["total_candles"]),
49
- candle_duration_in_mins=int(data["candle_duration_in_mins"]),
50
- order=order,
51
- candle_types=candle_types,
52
- )
53
-
54
41
 
55
42
  @dataclass
56
43
  class Number:
@@ -76,13 +63,13 @@ class ModelInput:
76
63
  strings: List[StringTensor]
77
64
 
78
65
 
79
- class InferenceMode:
66
+ class InferenceMode(Enum):
80
67
  VANILLA = 0
81
68
  ZKML = 1
82
69
  TEE = 2
83
70
 
84
71
 
85
- class LlmInferenceMode:
72
+ class LlmInferenceMode(Enum):
86
73
  VANILLA = 0
87
74
  TEE = 1
88
75
 
@@ -98,21 +85,36 @@ class ModelOutput:
98
85
  jsons: Dict[str, np.ndarray] # Converts to JSON dictionary
99
86
  is_simulation_result: bool
100
87
 
88
+
89
+ @dataclass
90
+ class InferenceResult:
91
+ """
92
+ Output for ML inference requests
93
+ """
94
+
95
+ transaction_hash: str
96
+ """Blockchain hash for the transaction."""
97
+
98
+ model_output: Dict[str, np.ndarray]
99
+ """Output of ONNX model"""
100
+
101
+
101
102
  @dataclass
102
103
  class TextGenerationOutput:
103
104
  """
104
105
  Output structure for text generation requests.
105
106
  """
107
+
106
108
  transaction_hash: str
107
109
  """Blockchain hash for the transaction."""
108
110
 
109
- finish_reason: str | None = ""
111
+ finish_reason: Optional[str] = None
110
112
  """Reason for completion (e.g., 'tool_call', 'stop', 'error'). Empty string if not applicable."""
111
-
112
- chat_output: Dict | None = DefaultDict
113
+
114
+ chat_output: Optional[Dict] = None
113
115
  """Dictionary of chat response containing role, message content, tool call parameters, etc.. Empty dict if not applicable."""
114
116
 
115
- completion_output: str | None = ""
117
+ completion_output: Optional[str] = None
116
118
  """Raw text output from completion-style generation. Empty string if not applicable."""
117
119
 
118
120
 
@@ -182,3 +184,15 @@ class SchedulerParams:
182
184
  if data is None:
183
185
  return None
184
186
  return SchedulerParams(frequency=data.get("frequency", 600), duration_hours=data.get("duration_hours", 2))
187
+
188
+
189
+ @dataclass
190
+ class ModelRepository:
191
+ name: str
192
+ initialVersion: str
193
+
194
+
195
+ @dataclass
196
+ class FileUploadResult:
197
+ modelCid: str
198
+ size: int
opengradient/utils.py CHANGED
@@ -1,3 +1,5 @@
1
+ # type: ignore
2
+
1
3
  import json
2
4
  import logging
3
5
  from decimal import Decimal
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.2
2
+ Name: opengradient
3
+ Version: 0.4.8
4
+ Summary: Python SDK for OpenGradient decentralized model management & inference services
5
+ Author-email: OpenGradient <oliver@opengradient.ai>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 OpenGradient
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://opengradient.ai
29
+ Classifier: Development Status :: 3 - Alpha
30
+ Classifier: Intended Audience :: Developers
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python :: 3.10
33
+ Classifier: Programming Language :: Python :: 3.11
34
+ Classifier: Programming Language :: Python :: 3.12
35
+ Requires-Python: >=3.10
36
+ Description-Content-Type: text/markdown
37
+ License-File: LICENSE
38
+ Requires-Dist: eth-account>=0.13.4
39
+ Requires-Dist: web3>=7.3.0
40
+ Requires-Dist: click>=8.1.7
41
+ Requires-Dist: firebase-rest-api>=1.11.0
42
+ Requires-Dist: grpcio>=1.66.2
43
+ Requires-Dist: numpy>=1.26.4
44
+ Requires-Dist: requests>=2.32.3
45
+ Requires-Dist: langchain>=0.3.7
46
+ Requires-Dist: openai>=1.58.1
47
+ Requires-Dist: pydantic>=2.9.2
48
+
49
+ # OpenGradient Python SDK
50
+
51
+ A Python SDK for decentralized model management and inference services on the OpenGradient platform. The SDK enables programmatic access to our model repository and decentralized AI infrastructure.
52
+
53
+ ## Key Features
54
+
55
+ - Model management and versioning
56
+ - Decentralized model inference
57
+ - Support for LLM inference with various models
58
+ - End-to-end verified AI execution
59
+ - Command-line interface (CLI) for direct access
60
+
61
+ ## Model Hub
62
+
63
+ Browse and discover AI models on our [Model Hub](https://hub.opengradient.ai/). The Hub provides:
64
+ - Registry of models and LLMs
65
+ - Easy model discovery and deployment
66
+ - Direct integration with the SDK
67
+
68
+ ## Installation
69
+
70
+ ```bash
71
+ pip install opengradient
72
+ ```
73
+
74
+ Note: Windows users should temporarily enable WSL when installing `opengradient` (fix in progress).
75
+
76
+ ## Getting Started
77
+
78
+ ### 1. Account Setup
79
+
80
+ You'll need two accounts to use the SDK:
81
+ - **Model Hub account**: Create one at [Hub Sign Up](https://hub.opengradient.ai/signup)
82
+ - **OpenGradient account**: Use an existing Ethereum-compatible wallet or create a new one via SDK
83
+
84
+ The easiest way to set up your accounts is through our configuration wizard:
85
+
86
+ ```bash
87
+ opengradient config init
88
+ ```
89
+
90
+ This wizard will:
91
+ - Guide you through account creation
92
+ - Help you set up credentials
93
+ - Direct you to our Test Faucet for devnet tokens
94
+
95
+ ### 2. Initialize the SDK
96
+
97
+ ```python
98
+ import opengradient as og
99
+ og.init(private_key="<private_key>", email="<email>", password="<password>")
100
+ ```
101
+
102
+ ### 3. Basic Usage
103
+
104
+ Browse available models on our [Model Hub](https://hub.opengradient.ai/) or create and upload your own:
105
+
106
+
107
+ ```python
108
+ # Create and upload a model
109
+ og.create_model(
110
+ model_name="my-model",
111
+ model_desc="Model description",
112
+ model_path="/path/to/model"
113
+ )
114
+
115
+ # Run inference
116
+ inference_mode = og.InferenceMode.VANILLA
117
+ result = og.infer(
118
+ model_cid="your-model-cid",
119
+ model_inputs={"input": "value"},
120
+ inference_mode=inference_mode
121
+ )
122
+ ```
123
+
124
+ ### 4. Examples
125
+
126
+ See code examples under [examples](./examples).
127
+
128
+ ## CLI Usage
129
+
130
+ The SDK includes a command-line interface for quick operations. First, verify your configuration:
131
+
132
+ ```bash
133
+ opengradient config show
134
+ ```
135
+
136
+ Run a test inference:
137
+
138
+ ```bash
139
+ opengradient infer -m QmbUqS93oc4JTLMHwpVxsE39mhNxy6hpf6Py3r9oANr8aZ \
140
+ --input '{"num_input1":[1.0, 2.0, 3.0], "num_input2":10}'
141
+ ```
142
+
143
+ ## Use Cases
144
+
145
+ 1. **Off-chain Applications**: Use OpenGradient as a decentralized alternative to centralized AI providers like HuggingFace and OpenAI.
146
+
147
+ 2. **Model Development**: Manage models on the Model Hub and integrate directly into your development workflow.
148
+
149
+ ## Documentation
150
+
151
+ For comprehensive documentation, API reference, and examples, visit:
152
+ - [OpenGradient Documentation](https://docs.opengradient.ai/)
153
+ - [API Reference](https://docs.opengradient.ai/api_reference/python_sdk/)
154
+
155
+ ## Support
156
+
157
+ - Run `opengradient --help` for CLI command reference
158
+ - Visit our [documentation](https://docs.opengradient.ai/) for detailed guides
159
+ - Join our [community](https://.opengradient.ai/) for support
@@ -0,0 +1,29 @@
1
+ opengradient/__init__.py,sha256=l-bAgytvG4EnSE6q5OUIkyiaE4ROes9vy3xDN1PgWJg,12178
2
+ opengradient/account.py,sha256=5wrYpws_1lozjOFjLCTHtxgoxK-LmObDAaVy9eDcJY4,1145
3
+ opengradient/cli.py,sha256=12fezJJvuceUaPSllsMqrBFoSpd2sTJjMpZ1_Dhzskg,25426
4
+ opengradient/client.py,sha256=q6Md6uleBl8h2Vkz1tjYrovFrg7_Lm0CWDMhymZmPzE,43773
5
+ opengradient/defaults.py,sha256=Dqc64Qv7RdLv7ZBjXzvxRRqBDc1HhyVbbdImpmzyrzU,490
6
+ opengradient/exceptions.py,sha256=88tfegboGtlehQcwhxsl6ZzhLJWZWlkf_bkHTiCtXpo,3391
7
+ opengradient/types.py,sha256=hAOsNJPoeZQtXM_qPnOTyk0ukTRKVAIMuJDr0Z8Z9t0,4757
8
+ opengradient/utils.py,sha256=NMXg_mi5cHVeV01O4fFQJCcbwgGuGFbdYNrAG9K2Um0,8337
9
+ opengradient/abi/PriceHistoryInference.abi,sha256=ZB3fZdx1kaFlp2wt1vTbTZZG1k8HPvmNtkG5Q8Bnajw,5098
10
+ opengradient/abi/WorkflowScheduler.abi,sha256=yEGs76qO4S1z980KL5hBdfyXiJ6k-kERcB1O_o73AEU,416
11
+ opengradient/abi/inference.abi,sha256=MR5u9npZ-Yx2EqRW17_M-UnGgFF3mMEMepOwaZ-Bkgc,7040
12
+ opengradient/alphasense/__init__.py,sha256=Ah6IpoPTb6UkY7ImOWLJs3tjlxDJx6vZVR7p5IwP_Ks,292
13
+ opengradient/alphasense/read_workflow_tool.py,sha256=ojCf-eMO6e0ib77nqjgEJtXxTxdLZmc_-MvyRemYFY0,3216
14
+ opengradient/alphasense/run_model_tool.py,sha256=_Yh143Cq6zVlNMhBot30GwCR3Zbi6G1PK1nViU50lfA,5002
15
+ opengradient/alphasense/types.py,sha256=uxk4JQKbaS2cM3ZiKpdHQb234OJ5ylprNR5vi01QFzA,220
16
+ opengradient/bin/PriceHistoryInference.bin,sha256=nU2FZpGHIKBZ7NSK9Sr-p9lr-nXja_40ISPN9yckDq8,41276
17
+ opengradient/llm/__init__.py,sha256=eYFBrOf1GZr0VGbIw-gSFr8hM3Rbw74ye8l-pnBPNuA,1104
18
+ opengradient/llm/og_langchain.py,sha256=Dn17DtsKnlJ1h7Q_2jx3MR9QJ6nzRnvrDisVBV_OvH4,4816
19
+ opengradient/llm/og_openai.py,sha256=26W_NDnLaICIaWbi9aou40v5ZJXLlmLdztDrdFoDGAU,3789
20
+ opengradient/proto/__init__.py,sha256=AhaSmrqV0TXGzCKaoPV8-XUvqs2fGAJBM2aOmDpkNbE,55
21
+ opengradient/proto/infer.proto,sha256=13eaEMcppxkBF8yChptsX9HooWFwJKze7oLZNl-LEb8,1217
22
+ opengradient/proto/infer_pb2.py,sha256=sGWDDVumYhXoCJTG9rLyvKu4XyaEjPE_b038kbNlj7w,3484
23
+ opengradient/proto/infer_pb2_grpc.py,sha256=q42_eZ7OZCMTXdWocYA4Ka3B0c3B74dOhfqdaIOO5AU,6700
24
+ opengradient-0.4.8.dist-info/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
25
+ opengradient-0.4.8.dist-info/METADATA,sha256=teo3WbkHF5H2u0sy2aK2VAh1_HV0OLjwLmhNvf1DWFM,5214
26
+ opengradient-0.4.8.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
27
+ opengradient-0.4.8.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
28
+ opengradient-0.4.8.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
29
+ opengradient-0.4.8.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1 +0,0 @@
1
- [{"inputs":[],"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"}]
@@ -1,189 +0,0 @@
1
- Metadata-Version: 2.2
2
- Name: opengradient
3
- Version: 0.4.6
4
- Summary: Python SDK for OpenGradient decentralized model management & inference services
5
- Author-email: OpenGradient <oliver@opengradient.ai>
6
- License: MIT License
7
-
8
- Copyright (c) 2024 OpenGradient
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
- SOFTWARE.
27
-
28
- Project-URL: Homepage, https://opengradient.ai
29
- Classifier: Development Status :: 3 - Alpha
30
- Classifier: Intended Audience :: Developers
31
- Classifier: License :: OSI Approved :: MIT License
32
- Classifier: Programming Language :: Python :: 3.10
33
- Classifier: Programming Language :: Python :: 3.11
34
- Classifier: Programming Language :: Python :: 3.12
35
- Requires-Python: >=3.10
36
- Description-Content-Type: text/markdown
37
- License-File: LICENSE
38
- Requires-Dist: eth-account>=0.13.4
39
- Requires-Dist: web3>=7.3.0
40
- Requires-Dist: click>=8.1.7
41
- Requires-Dist: firebase-rest-api>=1.11.0
42
- Requires-Dist: grpcio>=1.66.2
43
- Requires-Dist: numpy>=1.26.4
44
- Requires-Dist: requests>=2.32.3
45
- Requires-Dist: langchain>=0.3.7
46
- Requires-Dist: openai>=1.58.1
47
- Requires-Dist: pydantic>=2.9.2
48
-
49
- # OpenGradient Python SDK
50
- Python SDK for the OpenGradient platform provides decentralized model management & inference services. Python SDK allows programmatic access to our model repository and decentralized AI infrastructure.
51
-
52
- ## Installation
53
-
54
- To install Python SDK and CLI, run the following command:
55
- ```python
56
- pip install opengradient
57
- ```
58
-
59
- ## Quick Start
60
-
61
- To get started, run:
62
-
63
- ```python
64
- import opengradient as og
65
- og.init(private_key="<private_key>", email="<email>", password="<password>")
66
- ```
67
-
68
- The following commands show how to use Python SDK.
69
-
70
- ### Create a Model
71
- ```python
72
- og.create_model(model_name="<model_name>", model_desc="<model_description>")
73
- ```
74
-
75
- ### Create a Model (with file upload)
76
- ```python
77
- og.create_model(model_name="<model_name>", model_desc="<model_description>", model_path="<model_path>")
78
- ```
79
-
80
- ### Create a Version of a Model
81
- ```python
82
- og.create_version(model_name="<model_name>", notes="<model_notes>")
83
- ```
84
-
85
- ### Upload Files to a Model
86
- ```python
87
- og.upload(model_path="<model_path>", model_name="<model_name>", version="<version>")
88
- ```
89
-
90
- ### List Files of a Model Version
91
- ```python
92
- og.list_files(model_name="<model_name>", version="<version>")
93
- ```
94
-
95
- ### Run Inference
96
- ```python
97
- inference_mode = og.InferenceMode.VANILLA
98
- og.infer(model_cid, model_inputs, inference_mode)
99
- ```
100
- - inference mode can be `VANILLA`, `ZKML`, or `TEE`
101
-
102
- ### LLM Inference
103
- #### LLM Completion
104
- ```python
105
- tx_hash, response = og.llm_completion(
106
- model_cid='meta-llama/Meta-Llama-3-8B-Instruct',
107
- prompt="Translate the following English text to French: 'Hello, how are you?'",
108
- max_tokens=50,
109
- temperature=0.0
110
- )
111
- ```
112
-
113
- #### LLM Chat
114
- ```python
115
- # create messages history
116
- messages = [
117
- {
118
- "role": "system",
119
- "content": "You are a helpful AI assistant.",
120
- "name": "HAL"
121
- },
122
- {
123
- "role": "user",
124
- "content": "Hello! How are you doing? Can you repeat my name?",
125
- }]
126
-
127
- # run LLM inference
128
- tx_hash, finish_reason, message = og.llm_chat(
129
- model_cid=og.LLM.MISTRAL_7B_INSTRUCT_V3,
130
- messages=messages
131
- )
132
- ```
133
-
134
-
135
-
136
- ## Using the CLI
137
-
138
- ```bash
139
- export OPENGRADIENT_EMAIL="<email>"
140
- export OPENGRADIENT_PASSWORD="<password>"
141
- ```
142
-
143
- #### Creating a Model Repo
144
- ```bash
145
- opengradient create_model_repo "<model_name>" "<description>"
146
- ```
147
- - creating a model automatically initializes version `v0.01`
148
-
149
- #### Creating a Version
150
- ```bash
151
- opengradient create_model_repo "<model_name>" "<description>"
152
- ```
153
-
154
- #### Upload a File
155
- ```bash
156
- opengradient upload "<model_path>" "<model_name>" "<version>"
157
- ```
158
-
159
- #### List Files of a Model Version
160
- ```bash
161
- opengradient list_files "<model_name>" "<version>"
162
- ```
163
-
164
- #### CLI infer using string
165
- ```bash
166
- opengradient infer QmbUqS93oc4JTLMHwpVxsE39mhNxy6hpf6Py3r9oANr8aZ VANILLA '{"num_input1":[1.0, 2.0, 3.0], "num_input2":10, "str_input1":["hello", "ONNX"], "str_input2":" world"}'
167
- ```
168
-
169
- #### CLI infer using file path input
170
- ```bash
171
- opengradient infer QmbUqS93oc4JTLMHwpVxsE39mhNxy6hpf6Py3r9oANr8aZ VANILLA --input_file input.json
172
- ```
173
-
174
- #### Run LLM Inference
175
- We also have explicit support for using LLMs through the completion and chat commands in the CLI.
176
-
177
- For example, you can run a competion inference with Llama-3 using the following command:
178
-
179
- ``` bash
180
- opengradient completion --model "meta-llama/Meta-Llama-3-8B-Instruct" --prompt "hello who are you?" --max-tokens 50
181
- ```
182
-
183
- Or you can use files instead of text input in order to simplify your command:
184
-
185
- ```bash
186
- opengradient chat --model "mistralai/Mistral-7B-Instruct-v0.3" --messages-file messages.json --tools-file tools.json --max-tokens 200
187
- ```
188
-
189
- For more information read the OpenGradient [documentation](https://docs.opengradient.ai/).