opengradient 0.5.0a3__py3-none-any.whl → 0.5.2__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/client.py +48 -33
- opengradient/types.py +50 -3
- {opengradient-0.5.0a3.dist-info → opengradient-0.5.2.dist-info}/METADATA +1 -1
- {opengradient-0.5.0a3.dist-info → opengradient-0.5.2.dist-info}/RECORD +8 -8
- {opengradient-0.5.0a3.dist-info → opengradient-0.5.2.dist-info}/WHEEL +0 -0
- {opengradient-0.5.0a3.dist-info → opengradient-0.5.2.dist-info}/entry_points.txt +0 -0
- {opengradient-0.5.0a3.dist-info → opengradient-0.5.2.dist-info}/licenses/LICENSE +0 -0
- {opengradient-0.5.0a3.dist-info → opengradient-0.5.2.dist-info}/top_level.txt +0 -0
opengradient/client.py
CHANGED
|
@@ -61,6 +61,9 @@ DEFAULT_RETRY_DELAY_SEC = 1
|
|
|
61
61
|
|
|
62
62
|
PRECOMPILE_CONTRACT_ADDRESS = "0x00000000000000000000000000000000000000F4"
|
|
63
63
|
|
|
64
|
+
X402_PROCESSING_HASH_HEADER = "x-processing-hash"
|
|
65
|
+
X402_PLACEHOLDER_API_KEY = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
|
|
66
|
+
|
|
64
67
|
class Client:
|
|
65
68
|
_inference_hub_contract_address: str
|
|
66
69
|
_blockchain: Web3
|
|
@@ -456,9 +459,13 @@ class Client:
|
|
|
456
459
|
OpenGradientError: If the inference fails.
|
|
457
460
|
"""
|
|
458
461
|
# Check if this is a local model or external
|
|
459
|
-
|
|
462
|
+
# TODO (Kyle): separate TEE and Vanilla completion requests
|
|
463
|
+
if inference_mode == LlmInferenceMode.TEE:
|
|
464
|
+
if model_cid not in TEE_LLM:
|
|
465
|
+
return OpenGradientError("That model CID is not supported yet for TEE inference")
|
|
466
|
+
|
|
460
467
|
return self._external_llm_completion(
|
|
461
|
-
model=model_cid,
|
|
468
|
+
model=model_cid.split('/')[1],
|
|
462
469
|
prompt=prompt,
|
|
463
470
|
max_tokens=max_tokens,
|
|
464
471
|
stop_sequence=stop_sequence,
|
|
@@ -467,17 +474,21 @@ class Client:
|
|
|
467
474
|
|
|
468
475
|
# Original local model logic
|
|
469
476
|
def execute_transaction():
|
|
470
|
-
if inference_mode != LlmInferenceMode.VANILLA
|
|
477
|
+
if inference_mode != LlmInferenceMode.VANILLA:
|
|
471
478
|
raise OpenGradientError("Invalid inference mode %s: Inference mode must be VANILLA or TEE" % inference_mode)
|
|
472
479
|
|
|
473
|
-
if
|
|
474
|
-
raise OpenGradientError("That model CID is not
|
|
480
|
+
if model_cid not in [llm.value for llm in LLM]:
|
|
481
|
+
raise OpenGradientError("That model CID is not yet supported for inference")
|
|
482
|
+
|
|
483
|
+
model_name = model_cid
|
|
484
|
+
if model_cid in [llm.value for llm in TEE_LLM]:
|
|
485
|
+
model_name = model_cid.split('/')[1]
|
|
475
486
|
|
|
476
487
|
contract = self._blockchain.eth.contract(address=self._inference_hub_contract_address, abi=self._inference_abi)
|
|
477
488
|
|
|
478
489
|
llm_request = {
|
|
479
490
|
"mode": inference_mode.value,
|
|
480
|
-
"modelCID":
|
|
491
|
+
"modelCID": model_name,
|
|
481
492
|
"prompt": prompt,
|
|
482
493
|
"max_tokens": max_tokens,
|
|
483
494
|
"stop_sequence": stop_sequence or [],
|
|
@@ -525,7 +536,7 @@ class Client:
|
|
|
525
536
|
api_key = self._get_api_key_for_model(model)
|
|
526
537
|
|
|
527
538
|
if api_key:
|
|
528
|
-
|
|
539
|
+
logging.debug("External LLM completions using API key")
|
|
529
540
|
url = f"{self._llm_server_url}/v1/completions"
|
|
530
541
|
|
|
531
542
|
headers = {
|
|
@@ -573,8 +584,7 @@ class Client:
|
|
|
573
584
|
) as client:
|
|
574
585
|
headers = {
|
|
575
586
|
"Content-Type": "application/json",
|
|
576
|
-
|
|
577
|
-
"Authorization": "Bearer 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
|
|
587
|
+
"Authorization": f"Bearer {X402_PLACEHOLDER_API_KEY}"
|
|
578
588
|
}
|
|
579
589
|
|
|
580
590
|
payload = {
|
|
@@ -595,15 +605,11 @@ class Client:
|
|
|
595
605
|
result = json.loads(content.decode())
|
|
596
606
|
payment_hash = ""
|
|
597
607
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
if "X-Payment-Response" in response.headers:
|
|
602
|
-
payment_response = decode_x_payment_response(response.headers["X-Payment-Response"])
|
|
603
|
-
payment_hash = payment_response["transaction"]
|
|
608
|
+
if X402_PROCESSING_HASH_HEADER in response.headers:
|
|
609
|
+
payment_hash = response.headers[X402_PROCESSING_HASH_HEADER]
|
|
604
610
|
|
|
605
611
|
return TextGenerationOutput(
|
|
606
|
-
transaction_hash="external",
|
|
612
|
+
transaction_hash="external",
|
|
607
613
|
completion_output=result.get("completion"),
|
|
608
614
|
payment_hash=payment_hash
|
|
609
615
|
)
|
|
@@ -629,7 +635,7 @@ class Client:
|
|
|
629
635
|
|
|
630
636
|
def llm_chat(
|
|
631
637
|
self,
|
|
632
|
-
model_cid: str,
|
|
638
|
+
model_cid: str,
|
|
633
639
|
messages: List[Dict],
|
|
634
640
|
inference_mode: LlmInferenceMode = LlmInferenceMode.VANILLA,
|
|
635
641
|
max_tokens: int = 100,
|
|
@@ -662,9 +668,13 @@ class Client:
|
|
|
662
668
|
OpenGradientError: If the inference fails.
|
|
663
669
|
"""
|
|
664
670
|
# Check if this is a local model or external
|
|
665
|
-
|
|
671
|
+
# TODO (Kyle): separate TEE and Vanilla completion requests
|
|
672
|
+
if inference_mode == LlmInferenceMode.TEE:
|
|
673
|
+
if model_cid not in TEE_LLM:
|
|
674
|
+
return OpenGradientError("That model CID is not supported yet for TEE inference")
|
|
675
|
+
|
|
666
676
|
return self._external_llm_chat(
|
|
667
|
-
model=model_cid,
|
|
677
|
+
model=model_cid.split('/')[1],
|
|
668
678
|
messages=messages,
|
|
669
679
|
max_tokens=max_tokens,
|
|
670
680
|
stop_sequence=stop_sequence,
|
|
@@ -675,11 +685,15 @@ class Client:
|
|
|
675
685
|
|
|
676
686
|
# Original local model logic
|
|
677
687
|
def execute_transaction():
|
|
678
|
-
if inference_mode != LlmInferenceMode.VANILLA
|
|
688
|
+
if inference_mode != LlmInferenceMode.VANILLA:
|
|
679
689
|
raise OpenGradientError("Invalid inference mode %s: Inference mode must be VANILLA or TEE" % inference_mode)
|
|
680
|
-
|
|
681
|
-
if
|
|
682
|
-
raise OpenGradientError("That model CID is not
|
|
690
|
+
|
|
691
|
+
if model_cid not in [llm.value for llm in LLM]:
|
|
692
|
+
raise OpenGradientError("That model CID is not yet supported for inference")
|
|
693
|
+
|
|
694
|
+
model_name = model_cid
|
|
695
|
+
if model_cid in [llm.value for llm in TEE_LLM]:
|
|
696
|
+
model_name = model_cid.split('/')[1]
|
|
683
697
|
|
|
684
698
|
contract = self._blockchain.eth.contract(address=self._inference_hub_contract_address, abi=self._inference_abi)
|
|
685
699
|
|
|
@@ -707,7 +721,7 @@ class Client:
|
|
|
707
721
|
|
|
708
722
|
llm_request = {
|
|
709
723
|
"mode": inference_mode.value,
|
|
710
|
-
"modelCID":
|
|
724
|
+
"modelCID": model_name,
|
|
711
725
|
"messages": messages,
|
|
712
726
|
"max_tokens": max_tokens,
|
|
713
727
|
"stop_sequence": stop_sequence or [],
|
|
@@ -768,7 +782,7 @@ class Client:
|
|
|
768
782
|
api_key = self._get_api_key_for_model(model)
|
|
769
783
|
|
|
770
784
|
if api_key:
|
|
771
|
-
|
|
785
|
+
logging.debug("External LLM completion using API key")
|
|
772
786
|
url = f"{self._llm_server_url}/v1/chat/completions"
|
|
773
787
|
|
|
774
788
|
headers = {
|
|
@@ -821,7 +835,7 @@ class Client:
|
|
|
821
835
|
) as client:
|
|
822
836
|
headers = {
|
|
823
837
|
"Content-Type": "application/json",
|
|
824
|
-
"Authorization": "Bearer
|
|
838
|
+
"Authorization": f"Bearer {X402_PLACEHOLDER_API_KEY}"
|
|
825
839
|
}
|
|
826
840
|
|
|
827
841
|
payload = {
|
|
@@ -846,16 +860,17 @@ class Client:
|
|
|
846
860
|
result = json.loads(content.decode())
|
|
847
861
|
|
|
848
862
|
payment_hash = ""
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
863
|
+
if X402_PROCESSING_HASH_HEADER in response.headers:
|
|
864
|
+
payment_hash = response.headers[X402_PROCESSING_HASH_HEADER]
|
|
865
|
+
|
|
866
|
+
choices = result.get("choices")
|
|
867
|
+
if not choices:
|
|
868
|
+
raise OpenGradientError(f"Invalid response: 'choices' missing or empty in {result}")
|
|
854
869
|
|
|
855
870
|
return TextGenerationOutput(
|
|
856
871
|
transaction_hash="external",
|
|
857
|
-
finish_reason=
|
|
858
|
-
chat_output=
|
|
872
|
+
finish_reason=choices[0].get("finish_reason"),
|
|
873
|
+
chat_output=choices[0].get("message"),
|
|
859
874
|
payment_hash=payment_hash
|
|
860
875
|
)
|
|
861
876
|
|
opengradient/types.py
CHANGED
|
@@ -193,18 +193,65 @@ class Abi:
|
|
|
193
193
|
class LLM(str, Enum):
|
|
194
194
|
"""Enum for available LLM models"""
|
|
195
195
|
|
|
196
|
+
# Existing open-source OG hosted models
|
|
196
197
|
META_LLAMA_3_8B_INSTRUCT = "meta-llama/Meta-Llama-3-8B-Instruct"
|
|
197
198
|
LLAMA_3_2_3B_INSTRUCT = "meta-llama/Llama-3.2-3B-Instruct"
|
|
198
199
|
QWEN_2_5_72B_INSTRUCT = "Qwen/Qwen2.5-72B-Instruct"
|
|
199
200
|
META_LLAMA_3_1_70B_INSTRUCT = "meta-llama/Llama-3.1-70B-Instruct"
|
|
200
201
|
DOBBY_UNHINGED_3_1_8B = "SentientAGI/Dobby-Mini-Unhinged-Llama-3.1-8B"
|
|
201
202
|
DOBBY_LEASHED_3_1_8B = "SentientAGI/Dobby-Mini-Leashed-Llama-3.1-8B"
|
|
202
|
-
|
|
203
|
+
|
|
204
|
+
# OpenAI models via TEE
|
|
205
|
+
GPT_4_1_2025_04_14 = "OpenAI/gpt-4.1-2025-04-14"
|
|
206
|
+
GPT_4O = "OpenAI/gpt-4o"
|
|
207
|
+
O4_MINI = "OpenAI/o4-mini"
|
|
208
|
+
|
|
209
|
+
# Anthropic models via TEE
|
|
210
|
+
CLAUDE_3_7_SONNET = "Anthropic/claude-3.7-sonnet"
|
|
211
|
+
CLAUDE_3_5_HAIKU = "Anthropic/claude-3.5-haiku"
|
|
212
|
+
CLAUDE_4_0_SONNET = "Anthropic/claude-4.0-sonnet"
|
|
213
|
+
|
|
214
|
+
# Google models via TEE
|
|
215
|
+
GEMINI_2_5_FLASH = "Google/gemini-2.5-flash"
|
|
216
|
+
GEMINI_2_5_PRO = "Google/gemini-2.5-pro"
|
|
217
|
+
GEMINI_2_0_FLASH = "Google/gemini-2.0-flash"
|
|
218
|
+
|
|
219
|
+
# xAI Grok models via TEE
|
|
220
|
+
GROK_3_MINI_BETA = "xAI/grok-3-mini-beta"
|
|
221
|
+
GROK_3_BETA = "xAI/grok-3-beta"
|
|
222
|
+
GROK_2_1212 = "grok-2-1212"
|
|
223
|
+
GROK_2_VISION_LATEST = "xAI/grok-2-vision-latest"
|
|
224
|
+
GROK_4_1_FAST = "xAI/grok-4.1-fast"
|
|
225
|
+
GROK_4_1_FAST_NON_REASONING = "xAI/grok-4-1-fast-non-reasoning"
|
|
203
226
|
|
|
204
227
|
class TEE_LLM(str, Enum):
|
|
205
228
|
"""Enum for LLM models available for TEE execution"""
|
|
206
|
-
|
|
207
|
-
|
|
229
|
+
|
|
230
|
+
# Existing (Currently turned off)
|
|
231
|
+
# META_LLAMA_3_1_70B_INSTRUCT = "meta-llama/Llama-3.1-70B-Instruct"
|
|
232
|
+
|
|
233
|
+
# OpenAI models via TEE
|
|
234
|
+
GPT_4_1_2025_04_14 = "OpenAI/gpt-4.1-2025-04-14"
|
|
235
|
+
GPT_4O = "OpenAI/gpt-4o"
|
|
236
|
+
O4_MINI = "OpenAI/o4-mini"
|
|
237
|
+
|
|
238
|
+
# Anthropic models via TEE
|
|
239
|
+
CLAUDE_3_7_SONNET = "Anthropic/claude-3.7-sonnet"
|
|
240
|
+
CLAUDE_3_5_HAIKU = "Anthropic/claude-3.5-haiku"
|
|
241
|
+
CLAUDE_4_0_SONNET = "Anthropic/claude-4.0-sonnet"
|
|
242
|
+
|
|
243
|
+
# Google models via TEE
|
|
244
|
+
GEMINI_2_5_FLASH = "Google/gemini-2.5-flash"
|
|
245
|
+
GEMINI_2_5_PRO = "Google/gemini-2.5-pro"
|
|
246
|
+
GEMINI_2_0_FLASH = "Google/gemini-2.0-flash"
|
|
247
|
+
|
|
248
|
+
# xAI Grok models via TEE
|
|
249
|
+
GROK_3_MINI_BETA = "xAI/grok-3-mini-beta"
|
|
250
|
+
GROK_3_BETA = "xAI/grok-3-beta"
|
|
251
|
+
GROK_2_1212 = "xAI/grok-2-1212"
|
|
252
|
+
GROK_2_VISION_LATEST = "xAI/grok-2-vision-latest"
|
|
253
|
+
GROK_4_1_FAST = "xAI/grok-4.1-fast"
|
|
254
|
+
GROK_4_1_FAST_NON_REASONING = "xAI/grok-4-1-fast-non-reasoning"
|
|
208
255
|
|
|
209
256
|
|
|
210
257
|
@dataclass
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
opengradient/__init__.py,sha256=wVg0KTFNBl7RnZF9huR5-m_q1E7tO-YyQwY7AD9JFoc,12635
|
|
2
2
|
opengradient/account.py,sha256=5wrYpws_1lozjOFjLCTHtxgoxK-LmObDAaVy9eDcJY4,1145
|
|
3
3
|
opengradient/cli.py,sha256=QzjH_KS6TF8gm_L1otFWA-oHkJ5SSfizFoRn0xR0b70,29162
|
|
4
|
-
opengradient/client.py,sha256=
|
|
4
|
+
opengradient/client.py,sha256=Seid3raffwAcrc3qVIINu259iO-BdaGXGT5O2VaT6ac,62356
|
|
5
5
|
opengradient/defaults.py,sha256=w8-dr5ciF2TGnqbm_ib0Yz4U0YL5ikpNqkcPVpmXzP8,673
|
|
6
6
|
opengradient/exceptions.py,sha256=88tfegboGtlehQcwhxsl6ZzhLJWZWlkf_bkHTiCtXpo,3391
|
|
7
|
-
opengradient/types.py,sha256=
|
|
7
|
+
opengradient/types.py,sha256=ygnQXoGJPv9i3daS0oduUsmUNoPGx6Oozkt-Yy7Nn6s,7548
|
|
8
8
|
opengradient/utils.py,sha256=ZUq4OBIml2vsC0tRqus4Zwb_e3g4woo00apByrafuVw,8058
|
|
9
9
|
opengradient/abi/InferencePrecompile.abi,sha256=reepTHg6Q01UrFP0Gexc-JayplsvOLPfG7jrEZ-cV28,10197
|
|
10
10
|
opengradient/abi/PriceHistoryInference.abi,sha256=ZB3fZdx1kaFlp2wt1vTbTZZG1k8HPvmNtkG5Q8Bnajw,5098
|
|
@@ -27,9 +27,9 @@ opengradient/workflow_models/constants.py,sha256=viIkb_LGcfVprqQNaA80gBTj6cfYam0
|
|
|
27
27
|
opengradient/workflow_models/types.py,sha256=Z22hF6c8Y4D2GlzVEIBODGwsqSjSrQvUcpZ7R-mIJdI,409
|
|
28
28
|
opengradient/workflow_models/utils.py,sha256=ySfpuiOBqLTlfto6ZxZf2vc7K6RGIja0l4eaVm5AOzY,1503
|
|
29
29
|
opengradient/workflow_models/workflow_models.py,sha256=d4C_gs39DAfy4cdY9Ee6GMXpPfzwvKFpmxzK1A7LNgU,3900
|
|
30
|
-
opengradient-0.5.
|
|
31
|
-
opengradient-0.5.
|
|
32
|
-
opengradient-0.5.
|
|
33
|
-
opengradient-0.5.
|
|
34
|
-
opengradient-0.5.
|
|
35
|
-
opengradient-0.5.
|
|
30
|
+
opengradient-0.5.2.dist-info/licenses/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
|
|
31
|
+
opengradient-0.5.2.dist-info/METADATA,sha256=vKpBpoNs4RhhXcz275SIoYrIpL550Z7ykk_9zS0-CdA,3992
|
|
32
|
+
opengradient-0.5.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
33
|
+
opengradient-0.5.2.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
|
|
34
|
+
opengradient-0.5.2.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
|
|
35
|
+
opengradient-0.5.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|