opengradient 0.3.8__tar.gz → 0.3.10__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.8/src/opengradient.egg-info → opengradient-0.3.10}/PKG-INFO +1 -2
  2. {opengradient-0.3.8 → opengradient-0.3.10}/pyproject.toml +1 -2
  3. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient/__init__.py +2 -1
  4. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient/cli.py +3 -4
  5. opengradient-0.3.10/src/opengradient/llm/__init__.py +5 -0
  6. opengradient-0.3.10/src/opengradient/llm/chat.py +118 -0
  7. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient/types.py +2 -1
  8. {opengradient-0.3.8 → opengradient-0.3.10/src/opengradient.egg-info}/PKG-INFO +1 -2
  9. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient.egg-info/SOURCES.txt +3 -1
  10. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient.egg-info/requires.txt +0 -1
  11. {opengradient-0.3.8 → opengradient-0.3.10}/LICENSE +0 -0
  12. {opengradient-0.3.8 → opengradient-0.3.10}/README.md +0 -0
  13. {opengradient-0.3.8 → opengradient-0.3.10}/setup.cfg +0 -0
  14. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient/abi/inference.abi +0 -0
  15. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient/account.py +0 -0
  16. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient/client.py +0 -0
  17. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient/defaults.py +0 -0
  18. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient/exceptions.py +0 -0
  19. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient/utils.py +0 -0
  20. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient.egg-info/dependency_links.txt +0 -0
  21. {opengradient-0.3.8 → opengradient-0.3.10}/src/opengradient.egg-info/entry_points.txt +0 -0
  22. {opengradient-0.3.8 → opengradient-0.3.10}/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.8
3
+ Version: 0.3.10
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.8"
7
+ version = "0.3.10"
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.8"
8
+ __version__ = "0.3.10"
8
9
 
9
10
  _client = None
10
11
 
@@ -417,7 +417,7 @@ def print_llm_completion_result(model_cid, tx_hash, llm_output):
417
417
  help='Temperature for LLM inference (0.0 to 1.0)')
418
418
  @click.option('--tools',
419
419
  type=str,
420
- default="[]",
420
+ default=None,
421
421
  help='Tool configurations in JSON format')
422
422
  @click.option('--tools-file',
423
423
  type=click.Path(exists=True, path_type=Path),
@@ -450,7 +450,6 @@ def chat(
450
450
  opengradient chat --model meta-llama/Meta-Llama-3-8B-Instruct --messages '[{"role":"user","content":"hello"}]' --max-tokens 50 --temperature 0.7
451
451
  opengradient chat -m mistralai/Mistral-7B-Instruct-v0.3 --messages-file messages.json --stop-sequence "." --stop-sequence "\n"
452
452
  """
453
- # TODO (Kyle): ^^^^^^^ Edit description with more examples using tools
454
453
  client: Client = ctx.obj['client']
455
454
  try:
456
455
  click.echo(f"Running LLM chat inference for model \"{model_cid}\"\n")
@@ -474,9 +473,9 @@ def chat(
474
473
  messages = json.load(file)
475
474
 
476
475
  # Parse tools if provided
477
- if (tools or tools != "[]") and tools_file:
476
+ if tools is not None and tools != "[]" and tools_file:
478
477
  click.echo("Cannot have both tools and tools_file")
479
- click.exit(1)
478
+ ctx.exit(1)
480
479
  return
481
480
 
482
481
  parsed_tools=[]
@@ -0,0 +1,5 @@
1
+ from .chat import *
2
+
3
+ __all__ = [
4
+ 'OpenGradientChatModel'
5
+ ]
@@ -0,0 +1,118 @@
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
+
39
+ @property
40
+ def _llm_type(self) -> str:
41
+ return "opengradient"
42
+
43
+ def bind_tools(
44
+ self,
45
+ tools: Sequence[Union[BaseTool, Dict]],
46
+ ) -> "OpenGradientChatModel":
47
+ """Bind tools to the model."""
48
+ tool_dicts = []
49
+ for tool in tools:
50
+ if isinstance(tool, BaseTool):
51
+ tool_dicts.append({
52
+ "type": "function",
53
+ "function": {
54
+ "name": tool.name,
55
+ "description": tool.description,
56
+ "parameters": tool.args_schema.schema() if hasattr(tool, "args_schema") else {}
57
+ }
58
+ })
59
+ else:
60
+ tool_dicts.append(tool)
61
+
62
+ self.tools = tool_dicts
63
+ return self
64
+
65
+ def _generate(
66
+ self,
67
+ messages: List[BaseMessage],
68
+ stop: Optional[List[str]] = None,
69
+ run_manager: Optional[CallbackManagerForLLMRun] = None,
70
+ **kwargs: Any,
71
+ ) -> ChatResult:
72
+ chat_messages = []
73
+ for message in messages:
74
+ if isinstance(message, SystemMessage):
75
+ chat_messages.append({"role": "system", "content": message.content})
76
+ elif isinstance(message, HumanMessage):
77
+ chat_messages.append({"role": "user", "content": message.content})
78
+ elif isinstance(message, AIMessage):
79
+ chat_messages.append({"role": "assistant", "content": message.content})
80
+
81
+ tx_hash, finish_reason, chat_response = self.client.llm_chat(
82
+ model_cid=self.model_cid,
83
+ messages=chat_messages,
84
+ stop_sequence=stop,
85
+ max_tokens=self.max_tokens,
86
+ tools=self.tools
87
+ )
88
+
89
+ if "tool_calls" in chat_response:
90
+ tool_calls = []
91
+ for tool_call in chat_response["tool_calls"]:
92
+ tool_calls.append(
93
+ ToolCall(
94
+ id=tool_call.get("id", ""),
95
+ name=tool_call["name"],
96
+ args=json.loads(tool_call["arguments"])
97
+ )
98
+ )
99
+
100
+ message = AIMessage(
101
+ content='',
102
+ tool_calls=tool_calls
103
+ )
104
+ else:
105
+ message = AIMessage(content=chat_response["content"])
106
+
107
+ return ChatResult(
108
+ generations=[ChatGeneration(
109
+ message=message,
110
+ generation_info={"finish_reason": finish_reason}
111
+ )]
112
+ )
113
+
114
+ @property
115
+ def _identifying_params(self) -> Dict[str, Any]:
116
+ return {
117
+ "model_name": self.model_cid,
118
+ }
@@ -77,4 +77,5 @@ class Abi:
77
77
  class LLM(str, Enum):
78
78
  META_LLAMA3_8B_INSTRUCT = "meta-llama/Meta-Llama-3-8B-Instruct"
79
79
  LLAMA_3_2_3B_INSTRUCT = "meta-llama/Llama-3.2-3B-Instruct"
80
- MISTRAL_7B_INSTRUCT_V3 = "mistralai/Mistral-7B-Instruct-v0.3"
80
+ MISTRAL_7B_INSTRUCT_V3 = "mistralai/Mistral-7B-Instruct-v0.3"
81
+ HERMES_3_LLAMA_3_1_70B = "NousResearch/Hermes-3-Llama-3.1-70B"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opengradient
3
- Version: 0.3.8
3
+ Version: 0.3.10
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