opengradient 0.3.9__tar.gz → 0.3.11__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 (22) hide show
  1. {opengradient-0.3.9/src/opengradient.egg-info → opengradient-0.3.11}/PKG-INFO +1 -2
  2. {opengradient-0.3.9 → opengradient-0.3.11}/pyproject.toml +1 -2
  3. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient/__init__.py +2 -1
  4. opengradient-0.3.11/src/opengradient/llm/__init__.py +5 -0
  5. opengradient-0.3.11/src/opengradient/llm/chat.py +119 -0
  6. {opengradient-0.3.9 → opengradient-0.3.11/src/opengradient.egg-info}/PKG-INFO +1 -2
  7. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient.egg-info/SOURCES.txt +3 -1
  8. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient.egg-info/requires.txt +0 -1
  9. {opengradient-0.3.9 → opengradient-0.3.11}/LICENSE +0 -0
  10. {opengradient-0.3.9 → opengradient-0.3.11}/README.md +0 -0
  11. {opengradient-0.3.9 → opengradient-0.3.11}/setup.cfg +0 -0
  12. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient/abi/inference.abi +0 -0
  13. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient/account.py +0 -0
  14. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient/cli.py +0 -0
  15. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient/client.py +0 -0
  16. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient/defaults.py +0 -0
  17. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient/exceptions.py +0 -0
  18. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient/types.py +0 -0
  19. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient/utils.py +0 -0
  20. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient.egg-info/dependency_links.txt +0 -0
  21. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient.egg-info/entry_points.txt +0 -0
  22. {opengradient-0.3.9 → opengradient-0.3.11}/src/opengradient.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opengradient
3
- Version: 0.3.9
3
+ Version: 0.3.11
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
@@ -87,7 +87,6 @@ Requires-Dist: keyring==24.3.1
87
87
  Requires-Dist: more-itertools==10.5.0
88
88
  Requires-Dist: msgpack==1.1.0
89
89
  Requires-Dist: multidict==6.1.0
90
- Requires-Dist: numpy==2.1.1
91
90
  Requires-Dist: packaging==24.1
92
91
  Requires-Dist: pandas==2.2.3
93
92
  Requires-Dist: parsimonious==0.10.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "opengradient"
7
- version = "0.3.9"
7
+ version = "0.3.11"
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"}
@@ -71,7 +71,6 @@ dependencies = [
71
71
  "more-itertools==10.5.0",
72
72
  "msgpack==1.1.0",
73
73
  "multidict==6.1.0",
74
- "numpy==2.1.1",
75
74
  "packaging==24.1",
76
75
  "pandas==2.2.3",
77
76
  "parsimonious==0.10.0",
@@ -3,8 +3,9 @@ from typing import Dict, List, Optional, Tuple
3
3
  from .client import Client
4
4
  from .defaults import DEFAULT_INFERENCE_CONTRACT_ADDRESS, DEFAULT_RPC_URL
5
5
  from .types import InferenceMode, LLM
6
+ from . import llm
6
7
 
7
- __version__ = "0.3.9"
8
+ __version__ = "0.3.11"
8
9
 
9
10
  _client = None
10
11
 
@@ -0,0 +1,5 @@
1
+ from .chat import *
2
+
3
+ __all__ = [
4
+ 'OpenGradientChatModel'
5
+ ]
@@ -0,0 +1,119 @@
1
+ from typing import List, Dict, Optional, Any, Sequence, Union
2
+ import json
3
+
4
+ from langchain.chat_models.base import BaseChatModel
5
+ from langchain.schema import (
6
+ AIMessage,
7
+ HumanMessage,
8
+ SystemMessage,
9
+ BaseMessage,
10
+ ChatResult,
11
+ ChatGeneration,
12
+ )
13
+ from langchain_core.callbacks.manager import CallbackManagerForLLMRun
14
+ from langchain_core.tools import BaseTool
15
+ from langchain_core.messages import ToolCall
16
+
17
+ from opengradient import Client
18
+ from opengradient.defaults import DEFAULT_RPC_URL, DEFAULT_INFERENCE_CONTRACT_ADDRESS
19
+
20
+
21
+ class OpenGradientChatModel(BaseChatModel):
22
+ """OpenGradient adapter class for LangChain chat model"""
23
+
24
+ client: Client = None
25
+ model_cid: str = None
26
+ max_tokens: int = None
27
+ tools: List[Dict] = []
28
+
29
+ def __init__(self, private_key: str, model_cid: str, max_tokens: int = 300):
30
+ super().__init__()
31
+ self.client = Client(
32
+ private_key=private_key,
33
+ rpc_url=DEFAULT_RPC_URL,
34
+ contract_address=DEFAULT_INFERENCE_CONTRACT_ADDRESS,
35
+ email=None,
36
+ password=None)
37
+ self.model_cid = model_cid
38
+ self.max_tokens = max_tokens
39
+
40
+ @property
41
+ def _llm_type(self) -> str:
42
+ return "opengradient"
43
+
44
+ def bind_tools(
45
+ self,
46
+ tools: Sequence[Union[BaseTool, Dict]],
47
+ ) -> "OpenGradientChatModel":
48
+ """Bind tools to the model."""
49
+ tool_dicts = []
50
+ for tool in tools:
51
+ if isinstance(tool, BaseTool):
52
+ tool_dicts.append({
53
+ "type": "function",
54
+ "function": {
55
+ "name": tool.name,
56
+ "description": tool.description,
57
+ "parameters": tool.args_schema.schema() if hasattr(tool, "args_schema") else {}
58
+ }
59
+ })
60
+ else:
61
+ tool_dicts.append(tool)
62
+
63
+ self.tools = tool_dicts
64
+ return self
65
+
66
+ def _generate(
67
+ self,
68
+ messages: List[BaseMessage],
69
+ stop: Optional[List[str]] = None,
70
+ run_manager: Optional[CallbackManagerForLLMRun] = None,
71
+ **kwargs: Any,
72
+ ) -> ChatResult:
73
+ chat_messages = []
74
+ for message in messages:
75
+ if isinstance(message, SystemMessage):
76
+ chat_messages.append({"role": "system", "content": message.content})
77
+ elif isinstance(message, HumanMessage):
78
+ chat_messages.append({"role": "user", "content": message.content})
79
+ elif isinstance(message, AIMessage):
80
+ chat_messages.append({"role": "assistant", "content": message.content})
81
+
82
+ tx_hash, finish_reason, chat_response = self.client.llm_chat(
83
+ model_cid=self.model_cid,
84
+ messages=chat_messages,
85
+ stop_sequence=stop,
86
+ max_tokens=self.max_tokens,
87
+ tools=self.tools
88
+ )
89
+
90
+ if "tool_calls" in chat_response:
91
+ tool_calls = []
92
+ for tool_call in chat_response["tool_calls"]:
93
+ tool_calls.append(
94
+ ToolCall(
95
+ id=tool_call.get("id", ""),
96
+ name=tool_call["name"],
97
+ args=json.loads(tool_call["arguments"])
98
+ )
99
+ )
100
+
101
+ message = AIMessage(
102
+ content='',
103
+ tool_calls=tool_calls
104
+ )
105
+ else:
106
+ message = AIMessage(content=chat_response["content"])
107
+
108
+ return ChatResult(
109
+ generations=[ChatGeneration(
110
+ message=message,
111
+ generation_info={"finish_reason": finish_reason}
112
+ )]
113
+ )
114
+
115
+ @property
116
+ def _identifying_params(self) -> Dict[str, Any]:
117
+ return {
118
+ "model_name": self.model_cid,
119
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opengradient
3
- Version: 0.3.9
3
+ Version: 0.3.11
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
@@ -87,7 +87,6 @@ Requires-Dist: keyring==24.3.1
87
87
  Requires-Dist: more-itertools==10.5.0
88
88
  Requires-Dist: msgpack==1.1.0
89
89
  Requires-Dist: multidict==6.1.0
90
- Requires-Dist: numpy==2.1.1
91
90
  Requires-Dist: packaging==24.1
92
91
  Requires-Dist: pandas==2.2.3
93
92
  Requires-Dist: parsimonious==0.10.0
@@ -15,4 +15,6 @@ src/opengradient.egg-info/dependency_links.txt
15
15
  src/opengradient.egg-info/entry_points.txt
16
16
  src/opengradient.egg-info/requires.txt
17
17
  src/opengradient.egg-info/top_level.txt
18
- src/opengradient/abi/inference.abi
18
+ src/opengradient/abi/inference.abi
19
+ src/opengradient/llm/__init__.py
20
+ src/opengradient/llm/chat.py
@@ -50,7 +50,6 @@ keyring==24.3.1
50
50
  more-itertools==10.5.0
51
51
  msgpack==1.1.0
52
52
  multidict==6.1.0
53
- numpy==2.1.1
54
53
  packaging==24.1
55
54
  pandas==2.2.3
56
55
  parsimonious==0.10.0
File without changes
File without changes
File without changes