opengradient 0.3.20__tar.gz → 0.3.21__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 (30) hide show
  1. {opengradient-0.3.20 → opengradient-0.3.21}/PKG-INFO +18 -17
  2. {opengradient-0.3.20 → opengradient-0.3.21}/pyproject.toml +20 -17
  3. opengradient-0.3.21/setup.cfg +4 -0
  4. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/__init__.py +4 -3
  5. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/llm/og_langchain.py +3 -2
  6. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/llm/og_openai.py +0 -1
  7. opengradient-0.3.21/src/opengradient/mltools/__init__.py +14 -0
  8. opengradient-0.3.21/src/opengradient/mltools/model_tool.py +129 -0
  9. opengradient-0.3.21/src/opengradient.egg-info/PKG-INFO +276 -0
  10. opengradient-0.3.21/src/opengradient.egg-info/SOURCES.txt +27 -0
  11. opengradient-0.3.21/src/opengradient.egg-info/dependency_links.txt +1 -0
  12. opengradient-0.3.21/src/opengradient.egg-info/entry_points.txt +2 -0
  13. opengradient-0.3.21/src/opengradient.egg-info/requires.txt +97 -0
  14. opengradient-0.3.21/src/opengradient.egg-info/top_level.txt +1 -0
  15. opengradient-0.3.20/.gitignore +0 -162
  16. {opengradient-0.3.20 → opengradient-0.3.21}/LICENSE +0 -0
  17. {opengradient-0.3.20 → opengradient-0.3.21}/README.md +0 -0
  18. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/abi/inference.abi +0 -0
  19. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/account.py +0 -0
  20. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/cli.py +0 -0
  21. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/client.py +0 -0
  22. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/defaults.py +0 -0
  23. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/exceptions.py +0 -0
  24. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/llm/__init__.py +0 -0
  25. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/proto/__init__.py +0 -0
  26. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/proto/infer.proto +0 -0
  27. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/proto/infer_pb2.py +0 -0
  28. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/proto/infer_pb2_grpc.py +0 -0
  29. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/types.py +0 -0
  30. {opengradient-0.3.20 → opengradient-0.3.21}/src/opengradient/utils.py +0 -0
@@ -1,8 +1,7 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.2
2
2
  Name: opengradient
3
- Version: 0.3.20
3
+ Version: 0.3.21
4
4
  Summary: Python SDK for OpenGradient decentralized model management & inference services
5
- Project-URL: Homepage, https://opengradient.ai
6
5
  Author-email: OpenGradient <oliver@opengradient.ai>
7
6
  License: MIT License
8
7
 
@@ -25,7 +24,8 @@ License: MIT License
25
24
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
25
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
26
  SOFTWARE.
28
- License-File: LICENSE
27
+
28
+ Project-URL: Homepage, https://opengradient.ai
29
29
  Classifier: Development Status :: 3 - Alpha
30
30
  Classifier: Intended Audience :: Developers
31
31
  Classifier: License :: OSI Approved :: MIT License
@@ -33,13 +33,15 @@ Classifier: Programming Language :: Python :: 3.10
33
33
  Classifier: Programming Language :: Python :: 3.11
34
34
  Classifier: Programming Language :: Python :: 3.12
35
35
  Requires-Python: >=3.10
36
+ Description-Content-Type: text/markdown
37
+ License-File: LICENSE
36
38
  Requires-Dist: aiohappyeyeballs>=2.4.3
37
39
  Requires-Dist: aiohttp>=3.10.8
38
40
  Requires-Dist: aiosignal>=1.3.1
39
41
  Requires-Dist: annotated-types>=0.7.0
40
42
  Requires-Dist: attrs>=24.2.0
41
43
  Requires-Dist: bitarray>=2.9.2
42
- Requires-Dist: cachecontrol>=0.14.0
44
+ Requires-Dist: CacheControl>=0.14.0
43
45
  Requires-Dist: cachetools>=5.5.0
44
46
  Requires-Dist: certifi>=2024.8.30
45
47
  Requires-Dist: cffi>=1.17.1
@@ -53,7 +55,6 @@ Requires-Dist: cryptography>=43.0.1
53
55
  Requires-Dist: cytoolz>=0.12.3
54
56
  Requires-Dist: distlib>=0.3.8
55
57
  Requires-Dist: dulwich>=0.21.7
56
- Requires-Dist: eth-abi>=5.1.0
57
58
  Requires-Dist: eth-account>=0.13.4
58
59
  Requires-Dist: eth-hash>=0.7.0
59
60
  Requires-Dist: eth-keyfile>=0.8.1
@@ -61,6 +62,7 @@ Requires-Dist: eth-keys>=0.5.1
61
62
  Requires-Dist: eth-rlp>=2.1.0
62
63
  Requires-Dist: eth-typing>=5.0.0
63
64
  Requires-Dist: eth-utils>=5.0.0
65
+ Requires-Dist: eth_abi>=5.1.0
64
66
  Requires-Dist: fastjsonschema>=2.20.0
65
67
  Requires-Dist: fastparquet>=2024.5.0
66
68
  Requires-Dist: filelock>=3.16.1
@@ -75,11 +77,12 @@ Requires-Dist: google-cloud-storage>=2.18.2
75
77
  Requires-Dist: google-crc32c>=1.6.0
76
78
  Requires-Dist: google-resumable-media>=2.7.2
77
79
  Requires-Dist: googleapis-common-protos>=1.65.0
78
- Requires-Dist: grpcio-tools>=1.66.2
79
80
  Requires-Dist: grpcio>=1.66.2
81
+ Requires-Dist: grpcio-tools>=1.66.2
82
+ Requires-Dist: protobuf>=4.24.0
80
83
  Requires-Dist: hexbytes>=1.2.1
81
84
  Requires-Dist: idna>=3.10
82
- Requires-Dist: jaraco-classes>=3.4.0
85
+ Requires-Dist: jaraco.classes>=3.4.0
83
86
  Requires-Dist: jwcrypto>=1.5.6
84
87
  Requires-Dist: keyring>=24.3.1
85
88
  Requires-Dist: langchain>=0.3.7
@@ -96,25 +99,24 @@ Requires-Dist: pkce>=1.0.3
96
99
  Requires-Dist: pkginfo>=1.11.1
97
100
  Requires-Dist: platformdirs>=4.3.6
98
101
  Requires-Dist: proto-plus>=1.24.0
99
- Requires-Dist: protobuf>=4.24.0
100
102
  Requires-Dist: protobuf>=5.28.2
101
103
  Requires-Dist: ptyprocess>=0.7.0
102
104
  Requires-Dist: pyarrow>=17.0.0
103
- Requires-Dist: pyasn1-modules>=0.4.1
104
105
  Requires-Dist: pyasn1>=0.6.1
106
+ Requires-Dist: pyasn1_modules>=0.4.1
105
107
  Requires-Dist: pycparser>=2.22
106
108
  Requires-Dist: pycryptodome>=3.21.0
107
- Requires-Dist: pydantic-core>=2.23.4
108
109
  Requires-Dist: pydantic>=2.9.2
109
- Requires-Dist: pyproject-hooks>=1.2.0
110
+ Requires-Dist: pydantic_core>=2.23.4
111
+ Requires-Dist: pyproject_hooks>=1.2.0
110
112
  Requires-Dist: python-dateutil>=2.9.0.post0
111
113
  Requires-Dist: python-jwt>=4.1.0
112
114
  Requires-Dist: pytz>=2024.2
113
115
  Requires-Dist: pyunormalize>=16.0.0
114
- Requires-Dist: rapidfuzz>=3.10.0
116
+ Requires-Dist: RapidFuzz>=3.10.0
115
117
  Requires-Dist: regex>=2024.9.11
116
- Requires-Dist: requests-toolbelt>=1.0.0
117
118
  Requires-Dist: requests>=2.32.3
119
+ Requires-Dist: requests-toolbelt>=1.0.0
118
120
  Requires-Dist: rlp>=4.0.1
119
121
  Requires-Dist: rsa>=4.9
120
122
  Requires-Dist: shellingham>=1.5.4
@@ -123,14 +125,13 @@ Requires-Dist: tomlkit>=0.13.2
123
125
  Requires-Dist: toolz>=0.12.1
124
126
  Requires-Dist: trove-classifiers>=2024.9.12
125
127
  Requires-Dist: types-requests>=2.32.0.20240914
126
- Requires-Dist: typing-extensions>=4.12.2
128
+ Requires-Dist: typing_extensions>=4.12.2
127
129
  Requires-Dist: tzdata>=2024.2
128
130
  Requires-Dist: urllib3>=2.2.3
129
131
  Requires-Dist: web3>=7.3.0
130
132
  Requires-Dist: websockets>=13.1
131
133
  Requires-Dist: xattr>=1.1.0
132
134
  Requires-Dist: yarl>=1.13.1
133
- Description-Content-Type: text/markdown
134
135
 
135
136
  # OpenGradient Python SDK
136
137
  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.
@@ -272,4 +273,4 @@ Or you can use files instead of text input in order to simplify your command:
272
273
  opengradient chat --model "mistralai/Mistral-7B-Instruct-v0.3" --messages-file messages.json --tools-file tools.json --max-tokens 200
273
274
  ```
274
275
 
275
- For more information read the OpenGradient [documentation](https://docs.opengradient.ai/).
276
+ For more information read the OpenGradient [documentation](https://docs.opengradient.ai/).
@@ -1,9 +1,10 @@
1
1
  [build-system]
2
- requires = ["hatchling"]
3
- build-backend = "hatchling.build"
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
4
5
  [project]
5
6
  name = "opengradient"
6
- version = "0.3.20"
7
+ version = "0.3.21"
7
8
  description = "Python SDK for OpenGradient decentralized model management & inference services"
8
9
  authors = [{name = "OpenGradient", email = "oliver@opengradient.ai"}]
9
10
  license = {file = "LICENSE"}
@@ -17,6 +18,7 @@ classifiers = [
17
18
  "Programming Language :: Python :: 3.11",
18
19
  "Programming Language :: Python :: 3.12",
19
20
  ]
21
+ # Dependencies kept as is...
20
22
  dependencies = [
21
23
  "aiohappyeyeballs>=2.4.3",
22
24
  "aiohttp>=3.10.8",
@@ -116,33 +118,34 @@ dependencies = [
116
118
  "xattr>=1.1.0",
117
119
  "yarl>=1.13.1",
118
120
  ]
121
+
119
122
  [project.scripts]
120
123
  opengradient = "opengradient.cli:cli"
124
+
121
125
  [project.urls]
122
126
  Homepage = "https://opengradient.ai"
127
+
123
128
  [tool.setuptools]
124
129
  package-dir = {"" = "src"}
125
130
  include-package-data = true
131
+
126
132
  [tool.setuptools.packages.find]
127
133
  where = ["src"]
134
+ include = ["opengradient*"] # Explicitly include all opengradient packages
128
135
  exclude = ["tests*", "stresstest*"]
136
+
129
137
  [tool.setuptools.package-data]
130
- "*" = ["*.py", "*.abi"]
131
- "opengradient" = ["abi/*.abi"]
132
- [tool.setuptools.exclude-package-data]
133
- "*" = ["*.ipynb", "*.pyc", "*.pyo", ".gitignore", "requirements.txt", "conftest.py"]
138
+ "opengradient" = [
139
+ "abi/*.abi",
140
+ "proto/*.proto",
141
+ "**/*.py"
142
+ ]
143
+
134
144
  [tool.ruff]
135
145
  line-length = 140
136
- target-version = "py310" # Specify your Python version
146
+ target-version = "py310"
137
147
  select = ["E", "F", "I", "N"]
138
148
  ignore = []
149
+
139
150
  [tool.ruff.mccabe]
140
- max-complexity = 10
141
- [tool.hatch.build]
142
- include = [
143
- "src/opengradient/**/*.py",
144
- "src/opengradient/proto/*.proto",
145
- "src/opengradient/abi/*.abi"
146
- ]
147
- [tool.hatch.build.targets.wheel]
148
- packages = ["src/opengradient"]
151
+ max-complexity = 10
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -7,9 +7,9 @@ from typing import Dict, List, Optional, Tuple
7
7
  from .client import Client
8
8
  from .defaults import DEFAULT_INFERENCE_CONTRACT_ADDRESS, DEFAULT_RPC_URL
9
9
  from .types import InferenceMode, LlmInferenceMode, LLM, TEE_LLM
10
- from . import llm
11
10
 
12
- __version__ = "0.3.20"
11
+ from . import llm
12
+ from . import mltools
13
13
 
14
14
  _client = None
15
15
 
@@ -241,7 +241,7 @@ def generate_image(model: str, prompt: str, height: Optional[int] = None, width:
241
241
 
242
242
  __all__ = [
243
243
  'generate_image',
244
- 'list_files'
244
+ 'list_files',
245
245
  'login',
246
246
  'llm_chat',
247
247
  'llm_completion',
@@ -261,6 +261,7 @@ __pdoc__ = {
261
261
  'defaults': False,
262
262
  'exceptions': False,
263
263
  'llm': True,
264
+ 'mltools': True,
264
265
  'proto': False,
265
266
  'types': False,
266
267
  'utils': False
@@ -17,7 +17,7 @@ from langchain_core.callbacks.manager import CallbackManagerForLLMRun
17
17
  from langchain_core.tools import BaseTool
18
18
  from langchain_core.messages import ToolCall
19
19
 
20
- from opengradient import Client
20
+ from opengradient import Client, LlmInferenceMode
21
21
  from opengradient.defaults import DEFAULT_RPC_URL, DEFAULT_INFERENCE_CONTRACT_ADDRESS
22
22
 
23
23
 
@@ -99,7 +99,8 @@ class OpenGradientChatModel(BaseChatModel):
99
99
  messages=sdk_messages,
100
100
  stop_sequence=stop,
101
101
  max_tokens=self.max_tokens,
102
- tools=self.tools
102
+ tools=self.tools,
103
+ inference_mode=LlmInferenceMode.VANILLA
103
104
  )
104
105
 
105
106
  if "tool_calls" in chat_response and chat_response["tool_calls"]:
@@ -4,7 +4,6 @@ from opengradient.defaults import DEFAULT_RPC_URL, DEFAULT_INFERENCE_CONTRACT_AD
4
4
 
5
5
  from typing import List
6
6
  import time
7
- import json
8
7
  import uuid
9
8
 
10
9
  class OGCompletions(object):
@@ -0,0 +1,14 @@
1
+ """
2
+ OpenGradient AlphaSense Tools
3
+ """
4
+
5
+ from .model_tool import *
6
+
7
+ __all__ = [
8
+ 'create_og_model_tool',
9
+ 'ToolType'
10
+ ]
11
+
12
+ __pdoc__ = {
13
+ 'model_tool': False
14
+ }
@@ -0,0 +1,129 @@
1
+ from enum import Enum
2
+ from typing import Callable, Dict, Any, Type
3
+
4
+ from pydantic import BaseModel
5
+ from langchain_core.tools import BaseTool, StructuredTool
6
+ import opengradient as og
7
+
8
+ class ToolType(str, Enum):
9
+ """Indicates the framework the tool is compatible with."""
10
+
11
+ LANGCHAIN = "langchain"
12
+ SWARM = "swarm"
13
+
14
+ def __str__(self) -> str:
15
+ return self.value
16
+
17
+ def create_og_model_tool(
18
+ tool_type: ToolType,
19
+ model_cid: str,
20
+ tool_name: str,
21
+ input_getter: Callable,
22
+ output_formatter: Callable[..., str],
23
+ input_schema: Type[BaseModel] = None,
24
+ tool_description: str = "Executes the given ML model",
25
+ inference_mode: og.InferenceMode= og.InferenceMode.VANILLA) -> BaseTool:
26
+ """
27
+ Creates a tool that wraps an OpenGradient model for inference.
28
+
29
+ This function generates a tool that can be integrated into either a LangChain pipeline
30
+ or a Swarm system, allowing the model to be executed as part of a chain of operations.
31
+ The tool uses the provided input_getter function to obtain the necessary input data and
32
+ runs inference using the specified OpenGradient model.
33
+
34
+ Args:
35
+ tool_type (ToolType): Specifies the framework to create the tool for. Use
36
+ ToolType.LANGCHAIN for LangChain integration or ToolType.SWARM for Swarm
37
+ integration.
38
+ model_cid (str): The CID of the OpenGradient model to be executed.
39
+ tool_name (str): The name to assign to the created tool. This will be used to identify
40
+ and invoke the tool within the agent.
41
+ input_getter (Callable): A function that returns the input data required by the model.
42
+ The function should return data in a format compatible with the model's expectations.
43
+ output_formatter (Callable[..., str]): A function that takes the model output and
44
+ formats it into a string. This is required to ensure the output is compatible
45
+ with the tool framework.
46
+ input_schema (Type[BaseModel], optional): A Pydantic BaseModel class defining the
47
+ input schema. This will be used directly for LangChain tools and converted
48
+ to appropriate annotations for Swarm tools. Default is None.
49
+ tool_description (str, optional): A description of what the tool does. Defaults to
50
+ "Executes the given ML model".
51
+ inference_mode (og.InferenceMode, optional): The inference mode to use when running
52
+ the model. Defaults to VANILLA.
53
+
54
+ Returns:
55
+ BaseTool: For ToolType.LANGCHAIN, returns a LangChain StructuredTool.
56
+ Callable: For ToolType.SWARM, returns a decorated function with appropriate metadata.
57
+
58
+ Raises:
59
+ ValueError: If an invalid tool_type is provided.
60
+
61
+ Examples:
62
+ >>> from pydantic import BaseModel, Field
63
+ >>> class ClassifierInput(BaseModel):
64
+ ... query: str = Field(description="User query to analyze")
65
+ ... parameters: dict = Field(description="Additional parameters")
66
+ >>> def get_input():
67
+ ... return {"text": "Sample input text"}
68
+ >>> def format_output(output):
69
+ ... return str(output.get("class", "Unknown"))
70
+ >>> # Create a LangChain tool
71
+ >>> langchain_tool = create_og_model_tool(
72
+ ... tool_type=ToolType.LANGCHAIN,
73
+ ... model_cid="Qm...",
74
+ ... tool_name="text_classifier",
75
+ ... input_getter=get_input,
76
+ ... output_formatter=format_output,
77
+ ... input_schema=ClassifierInput
78
+ ... tool_description="Classifies text into categories"
79
+ ... )
80
+ """
81
+ # define runnable
82
+ def model_executor(**llm_input):
83
+ # Combine LLM input with input provided by code
84
+ combined_input = {
85
+ **llm_input,
86
+ **input_getter()
87
+ }
88
+
89
+ _, output = og.infer(
90
+ model_cid=model_cid,
91
+ inference_mode=inference_mode,
92
+ model_input=combined_input
93
+ )
94
+
95
+ return output_formatter(output)
96
+
97
+ if tool_type == ToolType.LANGCHAIN:
98
+ return StructuredTool.from_function(
99
+ func=model_executor,
100
+ name=tool_name,
101
+ description=tool_description,
102
+ args_schema=input_schema
103
+ )
104
+ elif tool_type == ToolType.SWARM:
105
+ model_executor.__name__ = tool_name
106
+ model_executor.__doc__ = tool_description
107
+ # Convert Pydantic model to Swarm annotations if provided
108
+ if input_schema:
109
+ model_executor.__annotations__ = _convert_pydantic_to_annotations(input_schema)
110
+ return model_executor
111
+ else:
112
+ raise ValueError(f"Invalid tooltype: {tool_type}")
113
+
114
+ def _convert_pydantic_to_annotations(model: Type[BaseModel]) -> Dict[str, Any]:
115
+ """
116
+ Convert a Pydantic model to function annotations format used by Swarm.
117
+
118
+ Args:
119
+ model: A Pydantic BaseModel class
120
+
121
+ Returns:
122
+ Dict mapping field names to (type, description) tuples
123
+ """
124
+ annotations = {}
125
+ for field_name, field in model.model_fields.items():
126
+ field_type = field.annotation
127
+ description = field.description or ""
128
+ annotations[field_name] = (field_type, description)
129
+ return annotations
@@ -0,0 +1,276 @@
1
+ Metadata-Version: 2.2
2
+ Name: opengradient
3
+ Version: 0.3.21
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: aiohappyeyeballs>=2.4.3
39
+ Requires-Dist: aiohttp>=3.10.8
40
+ Requires-Dist: aiosignal>=1.3.1
41
+ Requires-Dist: annotated-types>=0.7.0
42
+ Requires-Dist: attrs>=24.2.0
43
+ Requires-Dist: bitarray>=2.9.2
44
+ Requires-Dist: CacheControl>=0.14.0
45
+ Requires-Dist: cachetools>=5.5.0
46
+ Requires-Dist: certifi>=2024.8.30
47
+ Requires-Dist: cffi>=1.17.1
48
+ Requires-Dist: charset-normalizer>=3.3.2
49
+ Requires-Dist: ckzg>=2.0.1
50
+ Requires-Dist: cleo>=2.1.0
51
+ Requires-Dist: click>=8.1.7
52
+ Requires-Dist: cramjam>=2.8.4
53
+ Requires-Dist: crashtest>=0.4.1
54
+ Requires-Dist: cryptography>=43.0.1
55
+ Requires-Dist: cytoolz>=0.12.3
56
+ Requires-Dist: distlib>=0.3.8
57
+ Requires-Dist: dulwich>=0.21.7
58
+ Requires-Dist: eth-account>=0.13.4
59
+ Requires-Dist: eth-hash>=0.7.0
60
+ Requires-Dist: eth-keyfile>=0.8.1
61
+ Requires-Dist: eth-keys>=0.5.1
62
+ Requires-Dist: eth-rlp>=2.1.0
63
+ Requires-Dist: eth-typing>=5.0.0
64
+ Requires-Dist: eth-utils>=5.0.0
65
+ Requires-Dist: eth_abi>=5.1.0
66
+ Requires-Dist: fastjsonschema>=2.20.0
67
+ Requires-Dist: fastparquet>=2024.5.0
68
+ Requires-Dist: filelock>=3.16.1
69
+ Requires-Dist: firebase-rest-api>=1.11.0
70
+ Requires-Dist: frozenlist>=1.4.1
71
+ Requires-Dist: fsspec>=2024.9.0
72
+ Requires-Dist: google-api-core>=2.20.0
73
+ Requires-Dist: google-auth>=2.35.0
74
+ Requires-Dist: google-cloud-core>=2.4.1
75
+ Requires-Dist: google-cloud-firestore>=2.19.0
76
+ Requires-Dist: google-cloud-storage>=2.18.2
77
+ Requires-Dist: google-crc32c>=1.6.0
78
+ Requires-Dist: google-resumable-media>=2.7.2
79
+ Requires-Dist: googleapis-common-protos>=1.65.0
80
+ Requires-Dist: grpcio>=1.66.2
81
+ Requires-Dist: grpcio-tools>=1.66.2
82
+ Requires-Dist: protobuf>=4.24.0
83
+ Requires-Dist: hexbytes>=1.2.1
84
+ Requires-Dist: idna>=3.10
85
+ Requires-Dist: jaraco.classes>=3.4.0
86
+ Requires-Dist: jwcrypto>=1.5.6
87
+ Requires-Dist: keyring>=24.3.1
88
+ Requires-Dist: langchain>=0.3.7
89
+ Requires-Dist: more-itertools>=10.5.0
90
+ Requires-Dist: msgpack>=1.1.0
91
+ Requires-Dist: multidict>=6.1.0
92
+ Requires-Dist: openai>=1.58.1
93
+ Requires-Dist: packaging>=24.1
94
+ Requires-Dist: pandas>=2.2.3
95
+ Requires-Dist: parsimonious>=0.10.0
96
+ Requires-Dist: pathlib>=1.0.1
97
+ Requires-Dist: pexpect>=4.9.0
98
+ Requires-Dist: pkce>=1.0.3
99
+ Requires-Dist: pkginfo>=1.11.1
100
+ Requires-Dist: platformdirs>=4.3.6
101
+ Requires-Dist: proto-plus>=1.24.0
102
+ Requires-Dist: protobuf>=5.28.2
103
+ Requires-Dist: ptyprocess>=0.7.0
104
+ Requires-Dist: pyarrow>=17.0.0
105
+ Requires-Dist: pyasn1>=0.6.1
106
+ Requires-Dist: pyasn1_modules>=0.4.1
107
+ Requires-Dist: pycparser>=2.22
108
+ Requires-Dist: pycryptodome>=3.21.0
109
+ Requires-Dist: pydantic>=2.9.2
110
+ Requires-Dist: pydantic_core>=2.23.4
111
+ Requires-Dist: pyproject_hooks>=1.2.0
112
+ Requires-Dist: python-dateutil>=2.9.0.post0
113
+ Requires-Dist: python-jwt>=4.1.0
114
+ Requires-Dist: pytz>=2024.2
115
+ Requires-Dist: pyunormalize>=16.0.0
116
+ Requires-Dist: RapidFuzz>=3.10.0
117
+ Requires-Dist: regex>=2024.9.11
118
+ Requires-Dist: requests>=2.32.3
119
+ Requires-Dist: requests-toolbelt>=1.0.0
120
+ Requires-Dist: rlp>=4.0.1
121
+ Requires-Dist: rsa>=4.9
122
+ Requires-Dist: shellingham>=1.5.4
123
+ Requires-Dist: six>=1.16.0
124
+ Requires-Dist: tomlkit>=0.13.2
125
+ Requires-Dist: toolz>=0.12.1
126
+ Requires-Dist: trove-classifiers>=2024.9.12
127
+ Requires-Dist: types-requests>=2.32.0.20240914
128
+ Requires-Dist: typing_extensions>=4.12.2
129
+ Requires-Dist: tzdata>=2024.2
130
+ Requires-Dist: urllib3>=2.2.3
131
+ Requires-Dist: web3>=7.3.0
132
+ Requires-Dist: websockets>=13.1
133
+ Requires-Dist: xattr>=1.1.0
134
+ Requires-Dist: yarl>=1.13.1
135
+
136
+ # OpenGradient Python SDK
137
+ 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.
138
+
139
+ ## Installation
140
+
141
+ To install Python SDK and CLI, run the following command:
142
+ ```python
143
+ pip install opengradient
144
+ ```
145
+
146
+ ## Quick Start
147
+
148
+ To get started, run:
149
+
150
+ ```python
151
+ import opengradient as og
152
+ og.init(private_key="<private_key>", email="<email>", password="<password>")
153
+ ```
154
+
155
+ The following commands show how to use Python SDK.
156
+
157
+ ### Create a Model
158
+ ```python
159
+ og.create_model(model_name="<model_name>", model_desc="<model_description>")
160
+ ```
161
+
162
+ ### Create a Model (with file upload)
163
+ ```python
164
+ og.create_model(model_name="<model_name>", model_desc="<model_description>", model_path="<model_path>")
165
+ ```
166
+
167
+ ### Create a Version of a Model
168
+ ```python
169
+ og.create_version(model_name="<model_name>", notes="<model_notes>")
170
+ ```
171
+
172
+ ### Upload Files to a Model
173
+ ```python
174
+ og.upload(model_path="<model_path>", model_name="<model_name>", version="<version>")
175
+ ```
176
+
177
+ ### List Files of a Model Version
178
+ ```python
179
+ og.list_files(model_name="<model_name>", version="<version>")
180
+ ```
181
+
182
+ ### Run Inference
183
+ ```python
184
+ inference_mode = og.InferenceMode.VANILLA
185
+ og.infer(model_cid, model_inputs, inference_mode)
186
+ ```
187
+ - inference mode can be `VANILLA`, `ZKML`, or `TEE`
188
+
189
+ ### LLM Inference
190
+ #### LLM Completion
191
+ ```python
192
+ tx_hash, response = og.llm_completion(
193
+ model_cid='meta-llama/Meta-Llama-3-8B-Instruct',
194
+ prompt="Translate the following English text to French: 'Hello, how are you?'",
195
+ max_tokens=50,
196
+ temperature=0.0
197
+ )
198
+ ```
199
+
200
+ #### LLM Chat
201
+ ```python
202
+ # create messages history
203
+ messages = [
204
+ {
205
+ "role": "system",
206
+ "content": "You are a helpful AI assistant.",
207
+ "name": "HAL"
208
+ },
209
+ {
210
+ "role": "user",
211
+ "content": "Hello! How are you doing? Can you repeat my name?",
212
+ }]
213
+
214
+ # run LLM inference
215
+ tx_hash, finish_reason, message = og.llm_chat(
216
+ model_cid=og.LLM.MISTRAL_7B_INSTRUCT_V3,
217
+ messages=messages
218
+ )
219
+ ```
220
+
221
+
222
+
223
+ ## Using the CLI
224
+
225
+ ```bash
226
+ export OPENGRADIENT_EMAIL="<email>"
227
+ export OPENGRADIENT_PASSWORD="<password>"
228
+ ```
229
+
230
+ #### Creating a Model Repo
231
+ ```bash
232
+ opengradient create_model_repo "<model_name>" "<description>"
233
+ ```
234
+ - creating a model automatically initializes version `v0.01`
235
+
236
+ #### Creating a Version
237
+ ```bash
238
+ opengradient create_model_repo "<model_name>" "<description>"
239
+ ```
240
+
241
+ #### Upload a File
242
+ ```bash
243
+ opengradient upload "<model_path>" "<model_name>" "<version>"
244
+ ```
245
+
246
+ #### List Files of a Model Version
247
+ ```bash
248
+ opengradient list_files "<model_name>" "<version>"
249
+ ```
250
+
251
+ #### CLI infer using string
252
+ ```bash
253
+ opengradient infer QmbUqS93oc4JTLMHwpVxsE39mhNxy6hpf6Py3r9oANr8aZ VANILLA '{"num_input1":[1.0, 2.0, 3.0], "num_input2":10, "str_input1":["hello", "ONNX"], "str_input2":" world"}'
254
+ ```
255
+
256
+ #### CLI infer using file path input
257
+ ```bash
258
+ opengradient infer QmbUqS93oc4JTLMHwpVxsE39mhNxy6hpf6Py3r9oANr8aZ VANILLA --input_file input.json
259
+ ```
260
+
261
+ #### Run LLM Inference
262
+ We also have explicit support for using LLMs through the completion and chat commands in the CLI.
263
+
264
+ For example, you can run a competion inference with Llama-3 using the following command:
265
+
266
+ ``` bash
267
+ opengradient completion --model "meta-llama/Meta-Llama-3-8B-Instruct" --prompt "hello who are you?" --max-tokens 50
268
+ ```
269
+
270
+ Or you can use files instead of text input in order to simplify your command:
271
+
272
+ ```bash
273
+ opengradient chat --model "mistralai/Mistral-7B-Instruct-v0.3" --messages-file messages.json --tools-file tools.json --max-tokens 200
274
+ ```
275
+
276
+ For more information read the OpenGradient [documentation](https://docs.opengradient.ai/).
@@ -0,0 +1,27 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/opengradient/__init__.py
5
+ src/opengradient/account.py
6
+ src/opengradient/cli.py
7
+ src/opengradient/client.py
8
+ src/opengradient/defaults.py
9
+ src/opengradient/exceptions.py
10
+ src/opengradient/types.py
11
+ src/opengradient/utils.py
12
+ src/opengradient.egg-info/PKG-INFO
13
+ src/opengradient.egg-info/SOURCES.txt
14
+ src/opengradient.egg-info/dependency_links.txt
15
+ src/opengradient.egg-info/entry_points.txt
16
+ src/opengradient.egg-info/requires.txt
17
+ src/opengradient.egg-info/top_level.txt
18
+ src/opengradient/abi/inference.abi
19
+ src/opengradient/llm/__init__.py
20
+ src/opengradient/llm/og_langchain.py
21
+ src/opengradient/llm/og_openai.py
22
+ src/opengradient/mltools/__init__.py
23
+ src/opengradient/mltools/model_tool.py
24
+ src/opengradient/proto/__init__.py
25
+ src/opengradient/proto/infer.proto
26
+ src/opengradient/proto/infer_pb2.py
27
+ src/opengradient/proto/infer_pb2_grpc.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ opengradient = opengradient.cli:cli
@@ -0,0 +1,97 @@
1
+ aiohappyeyeballs>=2.4.3
2
+ aiohttp>=3.10.8
3
+ aiosignal>=1.3.1
4
+ annotated-types>=0.7.0
5
+ attrs>=24.2.0
6
+ bitarray>=2.9.2
7
+ CacheControl>=0.14.0
8
+ cachetools>=5.5.0
9
+ certifi>=2024.8.30
10
+ cffi>=1.17.1
11
+ charset-normalizer>=3.3.2
12
+ ckzg>=2.0.1
13
+ cleo>=2.1.0
14
+ click>=8.1.7
15
+ cramjam>=2.8.4
16
+ crashtest>=0.4.1
17
+ cryptography>=43.0.1
18
+ cytoolz>=0.12.3
19
+ distlib>=0.3.8
20
+ dulwich>=0.21.7
21
+ eth-account>=0.13.4
22
+ eth-hash>=0.7.0
23
+ eth-keyfile>=0.8.1
24
+ eth-keys>=0.5.1
25
+ eth-rlp>=2.1.0
26
+ eth-typing>=5.0.0
27
+ eth-utils>=5.0.0
28
+ eth_abi>=5.1.0
29
+ fastjsonschema>=2.20.0
30
+ fastparquet>=2024.5.0
31
+ filelock>=3.16.1
32
+ firebase-rest-api>=1.11.0
33
+ frozenlist>=1.4.1
34
+ fsspec>=2024.9.0
35
+ google-api-core>=2.20.0
36
+ google-auth>=2.35.0
37
+ google-cloud-core>=2.4.1
38
+ google-cloud-firestore>=2.19.0
39
+ google-cloud-storage>=2.18.2
40
+ google-crc32c>=1.6.0
41
+ google-resumable-media>=2.7.2
42
+ googleapis-common-protos>=1.65.0
43
+ grpcio>=1.66.2
44
+ grpcio-tools>=1.66.2
45
+ protobuf>=4.24.0
46
+ hexbytes>=1.2.1
47
+ idna>=3.10
48
+ jaraco.classes>=3.4.0
49
+ jwcrypto>=1.5.6
50
+ keyring>=24.3.1
51
+ langchain>=0.3.7
52
+ more-itertools>=10.5.0
53
+ msgpack>=1.1.0
54
+ multidict>=6.1.0
55
+ openai>=1.58.1
56
+ packaging>=24.1
57
+ pandas>=2.2.3
58
+ parsimonious>=0.10.0
59
+ pathlib>=1.0.1
60
+ pexpect>=4.9.0
61
+ pkce>=1.0.3
62
+ pkginfo>=1.11.1
63
+ platformdirs>=4.3.6
64
+ proto-plus>=1.24.0
65
+ protobuf>=5.28.2
66
+ ptyprocess>=0.7.0
67
+ pyarrow>=17.0.0
68
+ pyasn1>=0.6.1
69
+ pyasn1_modules>=0.4.1
70
+ pycparser>=2.22
71
+ pycryptodome>=3.21.0
72
+ pydantic>=2.9.2
73
+ pydantic_core>=2.23.4
74
+ pyproject_hooks>=1.2.0
75
+ python-dateutil>=2.9.0.post0
76
+ python-jwt>=4.1.0
77
+ pytz>=2024.2
78
+ pyunormalize>=16.0.0
79
+ RapidFuzz>=3.10.0
80
+ regex>=2024.9.11
81
+ requests>=2.32.3
82
+ requests-toolbelt>=1.0.0
83
+ rlp>=4.0.1
84
+ rsa>=4.9
85
+ shellingham>=1.5.4
86
+ six>=1.16.0
87
+ tomlkit>=0.13.2
88
+ toolz>=0.12.1
89
+ trove-classifiers>=2024.9.12
90
+ types-requests>=2.32.0.20240914
91
+ typing_extensions>=4.12.2
92
+ tzdata>=2024.2
93
+ urllib3>=2.2.3
94
+ web3>=7.3.0
95
+ websockets>=13.1
96
+ xattr>=1.1.0
97
+ yarl>=1.13.1
@@ -0,0 +1 @@
1
+ opengradient
@@ -1,162 +0,0 @@
1
- # Byte-compiled / optimized / DLL files
2
- __pycache__/
3
- *.py[cod]
4
- *$py.class
5
-
6
- # C extensions
7
- *.so
8
-
9
- # Distribution / packaging
10
- .Python
11
- build/
12
- develop-eggs/
13
- dist/
14
- downloads/
15
- eggs/
16
- .eggs/
17
- lib/
18
- lib64/
19
- parts/
20
- sdist/
21
- var/
22
- wheels/
23
- share/python-wheels/
24
- *.egg-info/
25
- .installed.cfg
26
- *.egg
27
- MANIFEST
28
-
29
- # PyInstaller
30
- # Usually these files are written by a python script from a template
31
- # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
- *.manifest
33
- *.spec
34
-
35
- # Installer logs
36
- pip-log.txt
37
- pip-delete-this-directory.txt
38
-
39
- # Unit test / coverage reports
40
- htmlcov/
41
- .tox/
42
- .nox/
43
- .coverage
44
- .coverage.*
45
- .cache
46
- nosetests.xml
47
- coverage.xml
48
- *.cover
49
- *.py,cover
50
- .hypothesis/
51
- .pytest_cache/
52
- cover/
53
-
54
- # Translations
55
- *.mo
56
- *.pot
57
-
58
- # Django stuff:
59
- *.log
60
- local_settings.py
61
- db.sqlite3
62
- db.sqlite3-journal
63
-
64
- # Flask stuff:
65
- instance/
66
- .webassets-cache
67
-
68
- # Scrapy stuff:
69
- .scrapy
70
-
71
- # Sphinx documentation
72
- docs/_build/
73
-
74
- # PyBuilder
75
- .pybuilder/
76
- target/
77
-
78
- # Jupyter Notebook
79
- .ipynb_checkpoints
80
-
81
- # IPython
82
- profile_default/
83
- ipython_config.py
84
-
85
- # pyenv
86
- # For a library or package, you might want to ignore these files since the code is
87
- # intended to run in multiple environments; otherwise, check them in:
88
- # .python-version
89
-
90
- # pipenv
91
- # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
- # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
- # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
- # install all needed dependencies.
95
- #Pipfile.lock
96
-
97
- # poetry
98
- # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
- # This is especially recommended for binary packages to ensure reproducibility, and is more
100
- # commonly ignored for libraries.
101
- # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
- #poetry.lock
103
-
104
- # pdm
105
- # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
- #pdm.lock
107
- # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
- # in version control.
109
- # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
- .pdm.toml
111
- .pdm-python
112
- .pdm-build/
113
-
114
- # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
- __pypackages__/
116
-
117
- # Celery stuff
118
- celerybeat-schedule
119
- celerybeat.pid
120
-
121
- # SageMath parsed files
122
- *.sage.py
123
-
124
- # Environments
125
- .env
126
- .venv
127
- env/
128
- venv/
129
- ENV/
130
- env.bak/
131
- venv.bak/
132
-
133
- # Spyder project settings
134
- .spyderproject
135
- .spyproject
136
-
137
- # Rope project settings
138
- .ropeproject
139
-
140
- # mkdocs documentation
141
- /site
142
-
143
- # mypy
144
- .mypy_cache/
145
- .dmypy.json
146
- dmypy.json
147
-
148
- # Pyre type checker
149
- .pyre/
150
-
151
- # pytype static type analyzer
152
- .pytype/
153
-
154
- # Cython debug symbols
155
- cython_debug/
156
-
157
- # PyCharm
158
- # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
- # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
- # and can be added to the global gitignore or merged into this file. For a more nuclear
161
- # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
- #.idea/
File without changes
File without changes