Skip to content

Commit 45b6fa1

Browse files
authored
Merge pull request #46 from SubstrateLabs/chris/openai-and-anthropic-api-keys
Secrets field for OpenAI and Anthropic keys
2 parents a0a3207 + b268ac8 commit 45b6fa1

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

substrate/GEN_VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20240617.20240727
1+
20240617.20240802

substrate/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
𐃏 Substrate Python SDK
33
4-
20240617.20240727
4+
20240617.20240802
55
"""
66

77
from .nodes import (
@@ -51,11 +51,12 @@
5151
)
5252
from .core.sb import sb
5353
from ._version import __version__
54-
from .substrate import Substrate, SubstrateResponse
54+
from .substrate import Secrets, Substrate, SubstrateResponse
5555
from .run_python import RunPython
5656

5757
__all__ = [
5858
"__version__",
59+
"Secrets",
5960
"SubstrateResponse",
6061
"sb",
6162
"Substrate",

substrate/core/sb.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
22
CORE ꩜ SUBSTRATE
33
"""
4-
from typing import Any, Union
4+
from re import template
5+
from typing import Any, Dict, Union
56

67
from .client.future import Future
78
from .future_directive import (

substrate/nodes.py

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import warnings
88

9+
from .substrate import SubstrateResponse
910
from .core.corenode import CoreNode
1011

1112
# filter pydantic v2 deprecation warnings
@@ -17,6 +18,7 @@
1718
CLIPOut,
1819
JinaV2Out,
1920
EmbedTextOut,
21+
RunPythonOut,
2022
EmbedImageOut,
2123
EraseImageOut,
2224
ComputeJSONOut,
@@ -57,6 +59,7 @@
5759
StableDiffusionXLControlNetOut,
5860
)
5961
from typing import Any, Dict, List, Optional
62+
from dataclasses import dataclass
6063
from typing_extensions import Literal
6164

6265
from .future_dataclass_models import (
@@ -65,6 +68,7 @@
6568
FutureCLIPOut,
6669
FutureJinaV2Out,
6770
FutureEmbedTextOut,
71+
FutureRunPythonOut,
6872
FutureEmbedImageOut,
6973
FutureEraseImageOut,
7074
FutureComputeJSONOut,

substrate/substrate.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import zlib
33
import base64
4+
import dataclasses
45
from typing import Any, Dict, Optional
56

67
from substrate.streaming import SubstrateStreamingResponse
@@ -11,6 +12,12 @@
1112
from .substrate_response import SubstrateResponse
1213

1314

15+
@dataclasses.dataclass
16+
class Secrets:
17+
openai: Optional[str] = None
18+
anthropic: Optional[str] = None
19+
20+
1421
class Substrate:
1522
"""
1623
Substrate client.
@@ -21,6 +28,7 @@ def __init__(
2128
api_key: str,
2229
base_url: str = "https://api.substrate.run",
2330
timeout: float = 60 * 5.0,
31+
secrets: Optional[Secrets] = None,
2432
additional_headers: Optional[Dict[str, Any]] = None,
2533
):
2634
"""
@@ -29,6 +37,11 @@ def __init__(
2937
if additional_headers is None:
3038
additional_headers = {}
3139
self.api_key = api_key
40+
if secrets is not None:
41+
if secrets.openai is not None:
42+
additional_headers["x-substrate-openai-api-key"] = secrets.openai
43+
if secrets.anthropic is not None:
44+
additional_headers["x-substrate-anthropic-api-key"] = secrets.anthropic
3245
self._client = APIClient(
3346
api_key=api_key,
3447
base_url=base_url,

0 commit comments

Comments
 (0)