Skip to content

Secrets field for OpenAI and Anthropic keys #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion substrate/GEN_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240617.20240727
20240617.20240802
5 changes: 3 additions & 2 deletions substrate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
𐃏 Substrate Python SDK

20240617.20240727
20240617.20240802
"""

from .nodes import (
Expand Down Expand Up @@ -51,11 +51,12 @@
)
from .core.sb import sb
from ._version import __version__
from .substrate import Substrate, SubstrateResponse
from .substrate import Secrets, Substrate, SubstrateResponse
from .run_python import RunPython

__all__ = [
"__version__",
"Secrets",
"SubstrateResponse",
"sb",
"Substrate",
Expand Down
3 changes: 2 additions & 1 deletion substrate/core/sb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
CORE ꩜ SUBSTRATE
"""
from typing import Any, Union
from re import template
from typing import Any, Dict, Union

from .client.future import Future
from .future_directive import (
Expand Down
4 changes: 4 additions & 0 deletions substrate/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import warnings

from .substrate import SubstrateResponse
from .core.corenode import CoreNode

# filter pydantic v2 deprecation warnings
Expand All @@ -17,6 +18,7 @@
CLIPOut,
JinaV2Out,
EmbedTextOut,
RunPythonOut,
EmbedImageOut,
EraseImageOut,
ComputeJSONOut,
Expand Down Expand Up @@ -57,6 +59,7 @@
StableDiffusionXLControlNetOut,
)
from typing import Any, Dict, List, Optional
from dataclasses import dataclass
from typing_extensions import Literal

from .future_dataclass_models import (
Expand All @@ -65,6 +68,7 @@
FutureCLIPOut,
FutureJinaV2Out,
FutureEmbedTextOut,
FutureRunPythonOut,
FutureEmbedImageOut,
FutureEraseImageOut,
FutureComputeJSONOut,
Expand Down
13 changes: 13 additions & 0 deletions substrate/substrate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import zlib
import base64
import dataclasses
from typing import Any, Dict, Optional

from substrate.streaming import SubstrateStreamingResponse
Expand All @@ -11,6 +12,12 @@
from .substrate_response import SubstrateResponse


@dataclasses.dataclass
class Secrets:
openai: Optional[str] = None
anthropic: Optional[str] = None


class Substrate:
"""
Substrate client.
Expand All @@ -21,6 +28,7 @@ def __init__(
api_key: str,
base_url: str = "https://api.substrate.run",
timeout: float = 60 * 5.0,
secrets: Optional[Secrets] = None,
additional_headers: Optional[Dict[str, Any]] = None,
):
"""
Expand All @@ -29,6 +37,11 @@ def __init__(
if additional_headers is None:
additional_headers = {}
self.api_key = api_key
if secrets is not None:
if secrets.openai is not None:
additional_headers["x-substrate-openai-api-key"] = secrets.openai
if secrets.anthropic is not None:
additional_headers["x-substrate-anthropic-api-key"] = secrets.anthropic
self._client = APIClient(
api_key=api_key,
base_url=base_url,
Expand Down
Loading