opengradient 0.4.5__py3-none-any.whl → 0.4.6__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/cli.py +4 -4
- opengradient/client.py +20 -7
- opengradient/llm/og_langchain.py +3 -1
- opengradient/llm/og_openai.py +3 -1
- opengradient/types.py +18 -1
- {opengradient-0.4.5.dist-info → opengradient-0.4.6.dist-info}/METADATA +1 -1
- {opengradient-0.4.5.dist-info → opengradient-0.4.6.dist-info}/RECORD +11 -11
- {opengradient-0.4.5.dist-info → opengradient-0.4.6.dist-info}/LICENSE +0 -0
- {opengradient-0.4.5.dist-info → opengradient-0.4.6.dist-info}/WHEEL +0 -0
- {opengradient-0.4.5.dist-info → opengradient-0.4.6.dist-info}/entry_points.txt +0 -0
- {opengradient-0.4.5.dist-info → opengradient-0.4.6.dist-info}/top_level.txt +0 -0
opengradient/cli.py
CHANGED
|
@@ -375,7 +375,7 @@ def completion(ctx, model_cid: str, inference_mode: str, prompt: str, max_tokens
|
|
|
375
375
|
client: Client = ctx.obj["client"]
|
|
376
376
|
try:
|
|
377
377
|
click.echo(f'Running LLM completion inference for model "{model_cid}"\n')
|
|
378
|
-
|
|
378
|
+
completion_output = client.llm_completion(
|
|
379
379
|
model_cid=model_cid,
|
|
380
380
|
inference_mode=LlmInferenceModes[inference_mode],
|
|
381
381
|
prompt=prompt,
|
|
@@ -384,7 +384,7 @@ def completion(ctx, model_cid: str, inference_mode: str, prompt: str, max_tokens
|
|
|
384
384
|
temperature=temperature,
|
|
385
385
|
)
|
|
386
386
|
|
|
387
|
-
print_llm_completion_result(model_cid,
|
|
387
|
+
print_llm_completion_result(model_cid, completion_output.transaction_hash, completion_output.completion_output)
|
|
388
388
|
except Exception as e:
|
|
389
389
|
click.echo(f"Error running LLM completion: {str(e)}")
|
|
390
390
|
|
|
@@ -517,7 +517,7 @@ def chat(
|
|
|
517
517
|
if not tools and not tools_file:
|
|
518
518
|
parsed_tools = None
|
|
519
519
|
|
|
520
|
-
|
|
520
|
+
completion_output = client.llm_chat(
|
|
521
521
|
model_cid=model_cid,
|
|
522
522
|
inference_mode=LlmInferenceModes[inference_mode],
|
|
523
523
|
messages=messages,
|
|
@@ -528,7 +528,7 @@ def chat(
|
|
|
528
528
|
tool_choice=tool_choice,
|
|
529
529
|
)
|
|
530
530
|
|
|
531
|
-
print_llm_chat_result(model_cid,
|
|
531
|
+
print_llm_chat_result(model_cid, completion_output.transaction_hash, completion_output.finish_reason, completion_output.chat_output)
|
|
532
532
|
except Exception as e:
|
|
533
533
|
click.echo(f"Error running LLM chat inference: {str(e)}")
|
|
534
534
|
|
opengradient/client.py
CHANGED
|
@@ -18,7 +18,7 @@ from web3.logs import DISCARD
|
|
|
18
18
|
from . import utils
|
|
19
19
|
from .exceptions import OpenGradientError
|
|
20
20
|
from .proto import infer_pb2, infer_pb2_grpc
|
|
21
|
-
from .types import LLM, TEE_LLM, HistoricalInputQuery, InferenceMode, LlmInferenceMode, ModelOutput, SchedulerParams
|
|
21
|
+
from .types import LLM, TEE_LLM, HistoricalInputQuery, InferenceMode, LlmInferenceMode, ModelOutput, TextGenerationOutput, SchedulerParams
|
|
22
22
|
from .defaults import DEFAULT_IMAGE_GEN_HOST, DEFAULT_IMAGE_GEN_PORT
|
|
23
23
|
|
|
24
24
|
_FIREBASE_CONFIG = {
|
|
@@ -350,7 +350,7 @@ class Client:
|
|
|
350
350
|
stop_sequence: Optional[List[str]] = None,
|
|
351
351
|
temperature: float = 0.0,
|
|
352
352
|
max_retries: Optional[int] = None,
|
|
353
|
-
) ->
|
|
353
|
+
) -> TextGenerationOutput:
|
|
354
354
|
"""
|
|
355
355
|
Perform inference on an LLM model using completions.
|
|
356
356
|
|
|
@@ -363,7 +363,9 @@ class Client:
|
|
|
363
363
|
temperature (float): Temperature for LLM inference, between 0 and 1. Default is 0.0.
|
|
364
364
|
|
|
365
365
|
Returns:
|
|
366
|
-
|
|
366
|
+
TextGenerationOutput: Generated text results including:
|
|
367
|
+
- Transaction hash
|
|
368
|
+
- String of completion output
|
|
367
369
|
|
|
368
370
|
Raises:
|
|
369
371
|
OpenGradientError: If the inference fails.
|
|
@@ -418,7 +420,11 @@ class Client:
|
|
|
418
420
|
raise OpenGradientError("LLM completion result event not found in transaction logs")
|
|
419
421
|
|
|
420
422
|
llm_answer = parsed_logs[0]["args"]["response"]["answer"]
|
|
421
|
-
|
|
423
|
+
|
|
424
|
+
return TextGenerationOutput(
|
|
425
|
+
transaction_hash=tx_hash.hex(),
|
|
426
|
+
completion_output=llm_answer
|
|
427
|
+
)
|
|
422
428
|
|
|
423
429
|
return run_with_retry(execute_transaction, max_retries)
|
|
424
430
|
|
|
@@ -433,7 +439,7 @@ class Client:
|
|
|
433
439
|
tools: Optional[List[Dict]] = [],
|
|
434
440
|
tool_choice: Optional[str] = None,
|
|
435
441
|
max_retries: Optional[int] = None,
|
|
436
|
-
) ->
|
|
442
|
+
) -> TextGenerationOutput:
|
|
437
443
|
"""
|
|
438
444
|
Perform inference on an LLM model using chat.
|
|
439
445
|
|
|
@@ -485,7 +491,10 @@ class Client:
|
|
|
485
491
|
tool_choice (str, optional): Sets a specific tool to choose. Default value is "auto".
|
|
486
492
|
|
|
487
493
|
Returns:
|
|
488
|
-
|
|
494
|
+
TextGenerationOutput: Generated text results including:
|
|
495
|
+
- Transaction hash
|
|
496
|
+
- Finish reason (tool_call, stop, etc.)
|
|
497
|
+
- Dictionary of chat message output (role, content, tool_call, etc.)
|
|
489
498
|
|
|
490
499
|
Raises:
|
|
491
500
|
OpenGradientError: If the inference fails.
|
|
@@ -570,7 +579,11 @@ class Client:
|
|
|
570
579
|
if (tool_calls := message.get("tool_calls")) is not None:
|
|
571
580
|
message["tool_calls"] = [dict(tool_call) for tool_call in tool_calls]
|
|
572
581
|
|
|
573
|
-
return
|
|
582
|
+
return TextGenerationOutput(
|
|
583
|
+
transaction_hash=tx_hash.hex(),
|
|
584
|
+
finish_reason=llm_result["finish_reason"],
|
|
585
|
+
chat_output=message,
|
|
586
|
+
)
|
|
574
587
|
|
|
575
588
|
return run_with_retry(execute_transaction, max_retries)
|
|
576
589
|
|
opengradient/llm/og_langchain.py
CHANGED
|
@@ -91,7 +91,7 @@ class OpenGradientChatModel(BaseChatModel):
|
|
|
91
91
|
else:
|
|
92
92
|
raise ValueError(f"Unexpected message type: {message}")
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
chat_output = self.client.llm_chat(
|
|
95
95
|
model_cid=self.model_cid,
|
|
96
96
|
messages=sdk_messages,
|
|
97
97
|
stop_sequence=stop,
|
|
@@ -99,6 +99,8 @@ class OpenGradientChatModel(BaseChatModel):
|
|
|
99
99
|
tools=self.tools,
|
|
100
100
|
inference_mode=LlmInferenceMode.VANILLA,
|
|
101
101
|
)
|
|
102
|
+
finish_reason = chat_output.finish_reason
|
|
103
|
+
chat_response = chat_output.chat_output
|
|
102
104
|
|
|
103
105
|
if "tool_calls" in chat_response and chat_response["tool_calls"]:
|
|
104
106
|
tool_calls = []
|
opengradient/llm/og_openai.py
CHANGED
|
@@ -26,7 +26,7 @@ class OGCompletions(object):
|
|
|
26
26
|
# convert OpenAI message format so it's compatible with the SDK
|
|
27
27
|
sdk_messages = OGCompletions.convert_to_abi_compatible(messages)
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
chat_output = self.client.llm_chat(
|
|
30
30
|
model_cid=model,
|
|
31
31
|
messages=sdk_messages,
|
|
32
32
|
max_tokens=200,
|
|
@@ -35,6 +35,8 @@ class OGCompletions(object):
|
|
|
35
35
|
temperature=0.25,
|
|
36
36
|
inference_mode=og.LlmInferenceMode.VANILLA,
|
|
37
37
|
)
|
|
38
|
+
finish_reason = chat_output.finish_reason
|
|
39
|
+
chat_completion = chat_output.chat_output
|
|
38
40
|
|
|
39
41
|
choice = {
|
|
40
42
|
"index": 0, # Add missing index field
|
opengradient/types.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import time
|
|
2
2
|
from dataclasses import dataclass
|
|
3
3
|
from enum import Enum, IntEnum
|
|
4
|
-
from typing import Dict, List, Optional, Tuple, Union
|
|
4
|
+
from typing import Dict, List, Optional, Tuple, Union, DefaultDict
|
|
5
5
|
import numpy as np
|
|
6
6
|
|
|
7
7
|
|
|
@@ -98,6 +98,23 @@ class ModelOutput:
|
|
|
98
98
|
jsons: Dict[str, np.ndarray] # Converts to JSON dictionary
|
|
99
99
|
is_simulation_result: bool
|
|
100
100
|
|
|
101
|
+
@dataclass
|
|
102
|
+
class TextGenerationOutput:
|
|
103
|
+
"""
|
|
104
|
+
Output structure for text generation requests.
|
|
105
|
+
"""
|
|
106
|
+
transaction_hash: str
|
|
107
|
+
"""Blockchain hash for the transaction."""
|
|
108
|
+
|
|
109
|
+
finish_reason: str | None = ""
|
|
110
|
+
"""Reason for completion (e.g., 'tool_call', 'stop', 'error'). Empty string if not applicable."""
|
|
111
|
+
|
|
112
|
+
chat_output: Dict | None = DefaultDict
|
|
113
|
+
"""Dictionary of chat response containing role, message content, tool call parameters, etc.. Empty dict if not applicable."""
|
|
114
|
+
|
|
115
|
+
completion_output: str | None = ""
|
|
116
|
+
"""Raw text output from completion-style generation. Empty string if not applicable."""
|
|
117
|
+
|
|
101
118
|
|
|
102
119
|
@dataclass
|
|
103
120
|
class AbiFunction:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
opengradient/__init__.py,sha256=RMjHgZ_Ef_l2cjN5a-81XYYx0LtWGKNZCg90-1zl3k0,12893
|
|
2
2
|
opengradient/account.py,sha256=5wrYpws_1lozjOFjLCTHtxgoxK-LmObDAaVy9eDcJY4,1145
|
|
3
|
-
opengradient/cli.py,sha256=
|
|
4
|
-
opengradient/client.py,sha256=
|
|
3
|
+
opengradient/cli.py,sha256=D89ysgoWbsbQ_ZbG0cRCHWcSE1gSwwv_It6611oo1Uo,25324
|
|
4
|
+
opengradient/client.py,sha256=r0Ev2VyqplXj0NSGtlecc4-UIw4NeMJ-w2DMC_2dR40,42281
|
|
5
5
|
opengradient/defaults.py,sha256=_WzWawpJ5j2V7sbTYGA3L_gqdftslLLqlRPQ2LBsCHY,417
|
|
6
6
|
opengradient/exceptions.py,sha256=88tfegboGtlehQcwhxsl6ZzhLJWZWlkf_bkHTiCtXpo,3391
|
|
7
|
-
opengradient/types.py,sha256=
|
|
7
|
+
opengradient/types.py,sha256=rnGTXWfF88Jqc9n0TbeX2YlR9hHoPaPoL66SjkBW9KA,4909
|
|
8
8
|
opengradient/utils.py,sha256=PIECAkk0lvj8TfBItugv01Hi_cJai09jGW34zhzsJ7E,8321
|
|
9
9
|
opengradient/abi/ModelExecutorHistorical.abi,sha256=AEceI9y-VyeaAvHna6AaCH8XOgF8nzSLGEHWCr89Ddw,2625
|
|
10
10
|
opengradient/abi/inference.abi,sha256=MR5u9npZ-Yx2EqRW17_M-UnGgFF3mMEMepOwaZ-Bkgc,7040
|
|
@@ -13,15 +13,15 @@ opengradient/alphasense/read_workflow_tool.py,sha256=p7lMFVgu4wZvvkjqlajBbLOhaUm
|
|
|
13
13
|
opengradient/alphasense/run_model_tool.py,sha256=UamcotxZcKfSGhFFmRTz6VRMvQdrL96yI3dCfKYsgo4,4971
|
|
14
14
|
opengradient/alphasense/types.py,sha256=uxk4JQKbaS2cM3ZiKpdHQb234OJ5ylprNR5vi01QFzA,220
|
|
15
15
|
opengradient/llm/__init__.py,sha256=b_msjZstmTRD20LOaZbBxxigtnL7vxh7CziiyVlqpAo,1104
|
|
16
|
-
opengradient/llm/og_langchain.py,sha256=
|
|
17
|
-
opengradient/llm/og_openai.py,sha256=
|
|
16
|
+
opengradient/llm/og_langchain.py,sha256=TEQu_8k1eyPI1DLq0FcLJyKHRJ-RrbPMscmAuWlPiHs,4400
|
|
17
|
+
opengradient/llm/og_openai.py,sha256=EcAWlYFpVJFl1noWBQPhkyDvTdj549GESq-VxcqjJaQ,3786
|
|
18
18
|
opengradient/proto/__init__.py,sha256=AhaSmrqV0TXGzCKaoPV8-XUvqs2fGAJBM2aOmDpkNbE,55
|
|
19
19
|
opengradient/proto/infer.proto,sha256=13eaEMcppxkBF8yChptsX9HooWFwJKze7oLZNl-LEb8,1217
|
|
20
20
|
opengradient/proto/infer_pb2.py,sha256=sGWDDVumYhXoCJTG9rLyvKu4XyaEjPE_b038kbNlj7w,3484
|
|
21
21
|
opengradient/proto/infer_pb2_grpc.py,sha256=q42_eZ7OZCMTXdWocYA4Ka3B0c3B74dOhfqdaIOO5AU,6700
|
|
22
|
-
opengradient-0.4.
|
|
23
|
-
opengradient-0.4.
|
|
24
|
-
opengradient-0.4.
|
|
25
|
-
opengradient-0.4.
|
|
26
|
-
opengradient-0.4.
|
|
27
|
-
opengradient-0.4.
|
|
22
|
+
opengradient-0.4.6.dist-info/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
|
|
23
|
+
opengradient-0.4.6.dist-info/METADATA,sha256=YFtaUXOqLLf_LRpzBlpqbhHnkNfcbDG4_FQQG8JdocQ,5832
|
|
24
|
+
opengradient-0.4.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
25
|
+
opengradient-0.4.6.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
|
|
26
|
+
opengradient-0.4.6.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
|
|
27
|
+
opengradient-0.4.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|