opengradient 0.5.0__py3-none-any.whl → 0.5.0a1__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/__init__.py CHANGED
@@ -34,7 +34,6 @@ def new_client(
34
34
  rpc_url=DEFAULT_RPC_URL,
35
35
  api_url=DEFAULT_API_URL,
36
36
  contract_address=DEFAULT_INFERENCE_CONTRACT_ADDRESS,
37
- **kwargs,
38
37
  ) -> Client:
39
38
  """
40
39
  Creates a unique OpenGradient client instance with the given authentication and network settings.
@@ -47,7 +46,7 @@ def new_client(
47
46
  contract_address: Optional inference contract address
48
47
  """
49
48
 
50
- return Client(email=email, password=password, private_key=private_key, rpc_url=rpc_url, api_url=api_url, contract_address=contract_address, **kwargs)
49
+ return Client(email=email, password=password, private_key=private_key, rpc_url=rpc_url, api_url=api_url, contract_address=contract_address)
51
50
 
52
51
 
53
52
  def init(email: str, password: str, private_key: str, rpc_url=DEFAULT_RPC_URL, api_url=DEFAULT_API_URL, contract_address=DEFAULT_INFERENCE_CONTRACT_ADDRESS):
opengradient/client.py CHANGED
@@ -14,9 +14,6 @@ from web3 import Web3
14
14
  from web3.exceptions import ContractLogicError
15
15
  from web3.logs import DISCARD
16
16
  import urllib.parse
17
- import asyncio
18
- from x402.clients.httpx import x402HttpxClient
19
- from x402.clients.base import decode_x_payment_response, x402Client
20
17
 
21
18
  from .exceptions import OpenGradientError
22
19
  from .proto import infer_pb2, infer_pb2_grpc
@@ -33,12 +30,7 @@ from .types import (
33
30
  ModelRepository,
34
31
  FileUploadResult,
35
32
  )
36
- from .defaults import (
37
- DEFAULT_IMAGE_GEN_HOST,
38
- DEFAULT_IMAGE_GEN_PORT,
39
- DEFAULT_SCHEDULER_ADDRESS,
40
- DEFAULT_LLM_SERVER_URL,
41
- DEFAULT_OPENGRADIENT_LLM_SERVER_URL)
33
+ from .defaults import DEFAULT_IMAGE_GEN_HOST, DEFAULT_IMAGE_GEN_PORT, DEFAULT_SCHEDULER_ADDRESS, DEFAULT_LLM_SERVER_URL
42
34
  from .utils import convert_array_to_model_output, convert_to_model_input, convert_to_model_output
43
35
 
44
36
  _FIREBASE_CONFIG = {
@@ -61,9 +53,6 @@ DEFAULT_RETRY_DELAY_SEC = 1
61
53
 
62
54
  PRECOMPILE_CONTRACT_ADDRESS = "0x00000000000000000000000000000000000000F4"
63
55
 
64
- X402_PROCESSING_HASH_HEADER = "x-processing-hash"
65
- X402_PLACEHOLDER_API_KEY = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
66
-
67
56
  class Client:
68
57
  _inference_hub_contract_address: str
69
58
  _blockchain: Web3
@@ -84,7 +73,6 @@ class Client:
84
73
  email: Optional[str] = None,
85
74
  password: Optional[str] = None,
86
75
  llm_server_url: Optional[str] = DEFAULT_LLM_SERVER_URL,
87
- og_llm_server_url: Optional[str] = DEFAULT_OPENGRADIENT_LLM_SERVER_URL,
88
76
  openai_api_key: Optional[str] = None,
89
77
  anthropic_api_key: Optional[str] = None,
90
78
  google_api_key: Optional[str] = None,
@@ -118,7 +106,6 @@ class Client:
118
106
  self._hub_user = None
119
107
 
120
108
  self._llm_server_url = llm_server_url
121
- self._og_llm_server_url = og_llm_server_url
122
109
 
123
110
  self._external_api_keys = {}
124
111
  if openai_api_key or os.getenv("OPENAI_API_KEY"):
@@ -417,15 +404,6 @@ class Client:
417
404
 
418
405
  return run_with_retry(execute_transaction, max_retries)
419
406
 
420
- def _og_payment_selector(self, accepts, network_filter=None, scheme_filter=None, max_value=None):
421
- """Custom payment selector for OpenGradient network (og-devnet)."""
422
- return x402Client.default_payment_requirements_selector(
423
- accepts,
424
- network_filter="og-devnet",
425
- scheme_filter=scheme_filter,
426
- max_value=max_value,
427
- )
428
-
429
407
  def llm_completion(
430
408
  self,
431
409
  model_cid: str, # Changed from LLM to str to accept any model
@@ -510,7 +488,7 @@ class Client:
510
488
  temperature: float = 0.0,
511
489
  ) -> TextGenerationOutput:
512
490
  """
513
- Route completion request to external LLM server with x402 payments.
491
+ Route completion request to external LLM server.
514
492
 
515
493
  Args:
516
494
  model: Model identifier
@@ -525,96 +503,35 @@ class Client:
525
503
  Raises:
526
504
  OpenGradientError: If request fails
527
505
  """
506
+ url = f"{self._llm_server_url}/v1/completions"
507
+
508
+ headers = {"Content-Type": "application/json"}
528
509
  api_key = self._get_api_key_for_model(model)
529
-
530
510
  if api_key:
531
- logging.debug("External LLM completions using API key")
532
- url = f"{self._llm_server_url}/v1/completions"
533
-
534
- headers = {
535
- "Content-Type": "application/json",
536
- "Authorization": f"Bearer {api_key}"
537
- }
511
+ headers["Authorization"] = f"Bearer {api_key}"
512
+
513
+ payload = {
514
+ "model": model,
515
+ "prompt": prompt,
516
+ "max_tokens": max_tokens,
517
+ "temperature": temperature,
518
+ }
519
+
520
+ if stop_sequence:
521
+ payload["stop"] = stop_sequence
522
+
523
+ try:
524
+ response = requests.post(url, json=payload, headers=headers, timeout=60)
525
+ response.raise_for_status()
538
526
 
539
- payload = {
540
- "model": model,
541
- "prompt": prompt,
542
- "max_tokens": max_tokens,
543
- "temperature": temperature,
544
- }
527
+ result = response.json()
545
528
 
546
- if stop_sequence:
547
- payload["stop"] = stop_sequence
529
+ return TextGenerationOutput(
530
+ transaction_hash="external", # No blockchain transaction for external
531
+ completion_output=result["completion"]
532
+ )
548
533
 
549
- try:
550
- response = requests.post(url, json=payload, headers=headers, timeout=60)
551
- response.raise_for_status()
552
-
553
- result = response.json()
554
-
555
- return TextGenerationOutput(
556
- transaction_hash="external",
557
- completion_output=result.get("completion")
558
- )
559
-
560
- except requests.RequestException as e:
561
- error_msg = f"External LLM completion failed: {str(e)}"
562
- if hasattr(e, 'response') and e.response is not None:
563
- try:
564
- error_detail = e.response.json()
565
- error_msg += f" - {error_detail}"
566
- except:
567
- error_msg += f" - {e.response.text}"
568
- logging.error(error_msg)
569
- raise OpenGradientError(error_msg)
570
-
571
- async def make_request():
572
- async with x402HttpxClient(
573
- account=self._wallet_account,
574
- base_url=self._og_llm_server_url,
575
- payment_requirements_selector=self._og_payment_selector,
576
- ) as client:
577
- headers = {
578
- "Content-Type": "application/json",
579
- "Authorization": f"Bearer {X402_PLACEHOLDER_API_KEY}"
580
- }
581
-
582
- payload = {
583
- "model": model,
584
- "prompt": prompt,
585
- "max_tokens": max_tokens,
586
- "temperature": temperature,
587
- }
588
-
589
- if stop_sequence:
590
- payload["stop"] = stop_sequence
591
-
592
- try:
593
- response = await client.post("/v1/completions", json=payload, headers=headers, timeout=60)
594
-
595
- # Read the response content
596
- content = await response.aread()
597
- result = json.loads(content.decode())
598
- payment_hash = ""
599
-
600
- if X402_PROCESSING_HASH_HEADER in response.headers:
601
- payment_hash = response.headers[X402_PROCESSING_HASH_HEADER]
602
-
603
- return TextGenerationOutput(
604
- transaction_hash="external",
605
- completion_output=result.get("completion"),
606
- payment_hash=payment_hash
607
- )
608
-
609
- except Exception as e:
610
- error_msg = f"External LLM completion request failed: {str(e)}"
611
- logging.error(error_msg)
612
- raise OpenGradientError(error_msg)
613
-
614
- try:
615
- # Run the async function in a sync context
616
- return asyncio.run(make_request())
617
- except Exception as e:
534
+ except requests.RequestException as e:
618
535
  error_msg = f"External LLM completion failed: {str(e)}"
619
536
  if hasattr(e, 'response') and e.response is not None:
620
537
  try:
@@ -746,7 +663,7 @@ class Client:
746
663
  tool_choice: Optional[str] = None,
747
664
  ) -> TextGenerationOutput:
748
665
  """
749
- Route chat request to external LLM server with x402 payments.
666
+ Route chat request to external LLM server.
750
667
 
751
668
  Args:
752
669
  model: Model identifier
@@ -763,110 +680,40 @@ class Client:
763
680
  Raises:
764
681
  OpenGradientError: If request fails
765
682
  """
683
+ url = f"{self._llm_server_url}/v1/chat/completions"
684
+
685
+ headers = {"Content-Type": "application/json"}
766
686
  api_key = self._get_api_key_for_model(model)
767
-
768
687
  if api_key:
769
- logging.debug("External LLM completion using API key")
770
- url = f"{self._llm_server_url}/v1/chat/completions"
771
-
772
- headers = {
773
- "Content-Type": "application/json",
774
- "Authorization": f"Bearer {api_key}"
775
- }
776
-
777
- payload = {
778
- "model": model,
779
- "messages": messages,
780
- "max_tokens": max_tokens,
781
- "temperature": temperature,
782
- }
688
+ headers["Authorization"] = f"Bearer {api_key}"
689
+
690
+ payload = {
691
+ "model": model,
692
+ "messages": messages,
693
+ "max_tokens": max_tokens,
694
+ "temperature": temperature,
695
+ }
696
+
697
+ if stop_sequence:
698
+ payload["stop"] = stop_sequence
699
+
700
+ if tools:
701
+ payload["tools"] = tools
702
+ payload["tool_choice"] = tool_choice or "auto"
703
+
704
+ try:
705
+ response = requests.post(url, json=payload, headers=headers, timeout=60)
706
+ response.raise_for_status()
783
707
 
784
- if stop_sequence:
785
- payload["stop"] = stop_sequence
708
+ result = response.json()
786
709
 
787
- if tools:
788
- payload["tools"] = tools
789
- payload["tool_choice"] = tool_choice or "auto"
710
+ return TextGenerationOutput(
711
+ transaction_hash="external", # No blockchain transaction for external
712
+ finish_reason=result["finish_reason"],
713
+ chat_output=result["message"]
714
+ )
790
715
 
791
- try:
792
- response = requests.post(url, json=payload, headers=headers, timeout=60)
793
- response.raise_for_status()
794
-
795
- result = response.json()
796
-
797
- return TextGenerationOutput(
798
- transaction_hash="external",
799
- finish_reason=result.get("finish_reason"),
800
- chat_output=result.get("message")
801
- )
802
-
803
- except requests.RequestException as e:
804
- error_msg = f"External LLM chat failed: {str(e)}"
805
- if hasattr(e, 'response') and e.response is not None:
806
- try:
807
- error_detail = e.response.json()
808
- error_msg += f" - {error_detail}"
809
- except:
810
- error_msg += f" - {e.response.text}"
811
- logging.error(error_msg)
812
- raise OpenGradientError(error_msg)
813
-
814
- async def make_request():
815
- async with x402HttpxClient(
816
- account=self._wallet_account,
817
- base_url=self._og_llm_server_url,
818
- payment_requirements_selector=self._og_payment_selector,
819
- ) as client:
820
- headers = {
821
- "Content-Type": "application/json",
822
- "Authorization": f"Bearer {X402_PLACEHOLDER_API_KEY}"
823
- }
824
-
825
- payload = {
826
- "model": model,
827
- "messages": messages,
828
- "max_tokens": max_tokens,
829
- "temperature": temperature,
830
- }
831
-
832
- if stop_sequence:
833
- payload["stop"] = stop_sequence
834
-
835
- if tools:
836
- payload["tools"] = tools
837
- payload["tool_choice"] = tool_choice or "auto"
838
-
839
- try:
840
- response = await client.post("/v1/chat/completions", json=payload, headers=headers, timeout=60)
841
-
842
- # Read the response content
843
- content = await response.aread()
844
- result = json.loads(content.decode())
845
-
846
- payment_hash = ""
847
- if X402_PROCESSING_HASH_HEADER in response.headers:
848
- payment_hash = response.headers[X402_PROCESSING_HASH_HEADER]
849
-
850
- choices = result.get("choices")
851
- if not choices:
852
- raise OpenGradientError(f"Invalid response: 'choices' missing or empty in {result}")
853
-
854
- return TextGenerationOutput(
855
- transaction_hash="external",
856
- finish_reason=choices[0].get("finish_reason"),
857
- chat_output=choices[0].get("message"),
858
- payment_hash=payment_hash
859
- )
860
-
861
- except Exception as e:
862
- error_msg = f"External LLM chat request failed: {str(e)}"
863
- logging.error(error_msg)
864
- raise OpenGradientError(error_msg)
865
-
866
- try:
867
- # Run the async function in a sync context
868
- return asyncio.run(make_request())
869
- except Exception as e:
716
+ except requests.RequestException as e:
870
717
  error_msg = f"External LLM chat failed: {str(e)}"
871
718
  if hasattr(e, 'response') and e.response is not None:
872
719
  try:
opengradient/defaults.py CHANGED
@@ -8,5 +8,4 @@ DEFAULT_SCHEDULER_ADDRESS = "0x7179724De4e7FF9271FA40C0337c7f90C0508eF6"
8
8
  DEFAULT_BLOCKCHAIN_EXPLORER = "https://explorer.opengradient.ai/tx/"
9
9
  DEFAULT_IMAGE_GEN_HOST = "18.217.25.69"
10
10
  DEFAULT_IMAGE_GEN_PORT = 5125
11
- DEFAULT_LLM_SERVER_URL = "http://35.225.197.84:8000"
12
- DEFAULT_OPENGRADIENT_LLM_SERVER_URL = "https://llm.opengradient.ai"
11
+ DEFAULT_LLM_SERVER_URL = "http://35.225.197.84:8000"
@@ -3,15 +3,13 @@ from typing import Any, Dict, List, Optional, Sequence, Union, Callable
3
3
  from typing_extensions import override
4
4
 
5
5
  from langchain.chat_models.base import BaseChatModel
6
- from langchain_core.messages import (
6
+ from langchain.schema import (
7
7
  AIMessage,
8
8
  BaseMessage,
9
- HumanMessage,
10
- SystemMessage,
11
- )
12
- from langchain_core.outputs import (
13
9
  ChatGeneration,
14
10
  ChatResult,
11
+ HumanMessage,
12
+ SystemMessage,
15
13
  )
16
14
  from langchain_core.callbacks.manager import CallbackManagerForLLMRun
17
15
  from langchain_core.messages import ToolCall
opengradient/types.py CHANGED
@@ -151,9 +151,6 @@ class TextGenerationOutput:
151
151
  completion_output: Optional[str] = None
152
152
  """Raw text output from completion-style generation. Empty string if not applicable."""
153
153
 
154
- payment_hash: Optional[str] = None
155
- """Payment hash for x402 transaction"""
156
-
157
154
 
158
155
  @dataclass
159
156
  class AbiFunction:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opengradient
3
- Version: 0.5.0
3
+ Version: 0.5.0a1
4
4
  Summary: Python SDK for OpenGradient decentralized model management & inference services
5
5
  Author-email: OpenGradient <kyle@vannalabs.ai>
6
6
  License-Expression: MIT
@@ -23,7 +23,6 @@ Requires-Dist: requests>=2.32.3
23
23
  Requires-Dist: langchain>=0.3.7
24
24
  Requires-Dist: openai>=1.58.1
25
25
  Requires-Dist: pydantic>=2.9.2
26
- Requires-Dist: og-test-x402==0.0.1
27
26
  Dynamic: license-file
28
27
 
29
28
  # OpenGradient Python SDK
@@ -1,10 +1,10 @@
1
- opengradient/__init__.py,sha256=wVg0KTFNBl7RnZF9huR5-m_q1E7tO-YyQwY7AD9JFoc,12635
1
+ opengradient/__init__.py,sha256=hFvN9sCEIQGWjT4Qnel6oQjadgAhDXMti72tdrP3sIo,12611
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=0SykYpfDqfbef1Y1ThvmZnWM9ezUy8egLltWZTeSXa8,61822
5
- opengradient/defaults.py,sha256=w8-dr5ciF2TGnqbm_ib0Yz4U0YL5ikpNqkcPVpmXzP8,673
4
+ opengradient/client.py,sha256=mcI4xC8XnOFQdROexSJojvTlEu6HiWzVJVquOOXcDms,55278
5
+ opengradient/defaults.py,sha256=TuaFLZ-sb9v0YOE9oKmPUCYHuXG7FbUZXxdGUIaaZ4w,605
6
6
  opengradient/exceptions.py,sha256=88tfegboGtlehQcwhxsl6ZzhLJWZWlkf_bkHTiCtXpo,3391
7
- opengradient/types.py,sha256=b7vdrC7R4mZYNWOChFzhkBzTSBlMXZxQ13mztlITDbE,5799
7
+ opengradient/types.py,sha256=JH8hjpcq4H7gQki74cuJpH4PcyQpwivLiqn9iq0evrI,5715
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
@@ -16,7 +16,7 @@ opengradient/alphasense/run_model_tool.py,sha256=wlDqXVHa1xpqQy_hmht_wWegxtqdYgY
16
16
  opengradient/alphasense/types.py,sha256=uxk4JQKbaS2cM3ZiKpdHQb234OJ5ylprNR5vi01QFzA,220
17
17
  opengradient/bin/PriceHistoryInference.bin,sha256=nU2FZpGHIKBZ7NSK9Sr-p9lr-nXja_40ISPN9yckDq8,41276
18
18
  opengradient/llm/__init__.py,sha256=eYFBrOf1GZr0VGbIw-gSFr8hM3Rbw74ye8l-pnBPNuA,1104
19
- opengradient/llm/og_langchain.py,sha256=inJmu28aWA1RAWJx8G0h8w4FGXSKMCzJVOBGUwiKqnI,4904
19
+ opengradient/llm/og_langchain.py,sha256=8qWYvF0Wr9BheTn8ErbCJKXnCRwYrzEI5pf9DnDjNIM,4858
20
20
  opengradient/llm/og_openai.py,sha256=26W_NDnLaICIaWbi9aou40v5ZJXLlmLdztDrdFoDGAU,3789
21
21
  opengradient/proto/__init__.py,sha256=AhaSmrqV0TXGzCKaoPV8-XUvqs2fGAJBM2aOmDpkNbE,55
22
22
  opengradient/proto/infer.proto,sha256=13eaEMcppxkBF8yChptsX9HooWFwJKze7oLZNl-LEb8,1217
@@ -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.0.dist-info/licenses/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
31
- opengradient-0.5.0.dist-info/METADATA,sha256=yMPCfWUMK3yEsvPeHmhcnr6BKma6_tHZIXDXnVg6H88,3992
32
- opengradient-0.5.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
- opengradient-0.5.0.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
34
- opengradient-0.5.0.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
35
- opengradient-0.5.0.dist-info/RECORD,,
30
+ opengradient-0.5.0a1.dist-info/licenses/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
31
+ opengradient-0.5.0a1.dist-info/METADATA,sha256=EnQ7ZzcjIeci9WUgxbtCCmHxR7VyAKfLG44kr3BHTsw,3959
32
+ opengradient-0.5.0a1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
+ opengradient-0.5.0a1.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
34
+ opengradient-0.5.0a1.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
35
+ opengradient-0.5.0a1.dist-info/RECORD,,