Skip to content

Commit

Permalink
120240502.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
0thernet committed May 6, 2024
1 parent 574d330 commit 347ab48
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 326 deletions.
118 changes: 73 additions & 45 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "substrate"
version = "120240430.0.1"
version = "120240502.0.0"
description = "Substrate Python SDK"
readme = "README.md"
authors = [ "vprtwn <[email protected]>", "liamgriffiths <[email protected]>",]
Expand Down
2 changes: 1 addition & 1 deletion scripts/sync_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def ok(message):
print("\033[32m✓\033[0m", message)


SDK_VERSION = "1.0.1"
SDK_VERSION = "1.0.0"

# Update version
version_path = "substrate/GEN_VERSION"
Expand Down
2 changes: 1 addition & 1 deletion substrate/GEN_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240430.20240430
20240502.20240502
8 changes: 1 addition & 7 deletions substrate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
"""
꩜ Substrate Python SDK
20240430.20240430
20240502.20240502
"""

from .nodes import (
CLIP,
XTTSV2,
JinaV2,
BigLaMa,
RunCode,
DISISNet,
FillMask,
EmbedText,
EmbedImage,
RealESRGAN,
FetchVectors,
Firellava13B,
GenerateJSON,
Expand Down Expand Up @@ -90,9 +87,6 @@
"FillMask",
"UpscaleImage",
"SegmentUnderPoint",
"DISISNet",
"BigLaMa",
"RealESRGAN",
"SegmentAnything",
"EmbedText",
"MultiEmbedText",
Expand Down
2 changes: 1 addition & 1 deletion substrate/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(
api_key: str,
base_url: str,
backend: str,
timeout: float = 60 * 5.0,
timeout: float,
additional_headers: Dict[str, Any] = {},
) -> None:
self._api_key = api_key
Expand Down
22 changes: 20 additions & 2 deletions substrate/core/future_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
)
from dataclasses import asdict, dataclass

OpType = Literal["trace", "string-concat", "jq"]
ConcatDirection = Literal["left", "right"]
OpType = Literal["trace", "string-concat", "jq", "short-circuit"]


class BaseDirective(ABC):
Expand Down Expand Up @@ -51,6 +50,25 @@ class JQDirective(BaseDirective):
type: Literal["jq"] = "jq"


@dataclass
class ShortCircuitConditionTarget:
future_id: Optional[str]
val: Optional[bool]


@dataclass
class ShortCircuitInputTarget:
future_id: Optional[str]
val: Optional[bool]


@dataclass
class ShortCircuitDirective(BaseDirective):
condition: ShortCircuitConditionTarget
input: ShortCircuitInputTarget
type: Literal["short-circuit"] = "short-circuit"


TraceType = Literal["attr", "item"]


Expand Down
48 changes: 0 additions & 48 deletions substrate/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ class BatchGenerateTextIn(BaseModel):
"""
Maximum number of tokens to generate.
"""
node: Literal["Mistral7BInstruct"] = "Mistral7BInstruct"
"""
Selected node.
"""


class BatchGenerateTextOut(BaseModel):
Expand Down Expand Up @@ -231,10 +227,6 @@ class BatchGenerateJSONIn(BaseModel):
"""
Maximum number of tokens to generate.
"""
node: Literal["Mistral7BInstruct"] = "Mistral7BInstruct"
"""
Selected node.
"""


class BatchGenerateJSONOut(BaseModel):
Expand Down Expand Up @@ -405,10 +397,6 @@ class GenerateTextVisionIn(BaseModel):
"""
Maximum number of tokens to generate.
"""
node: Literal["Firellava13B"] = "Firellava13B"
"""
Selected node.
"""


class GenerateTextVisionOut(BaseModel):
Expand Down Expand Up @@ -449,10 +437,6 @@ class GenerateImageIn(BaseModel):
"""
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://guides.substrate.run/guides/external-file-storage). If unset, the image data will be returned as a base64-encoded string.
"""
node: Literal["StableDiffusionXL"] = "StableDiffusionXL"
"""
Selected node.
"""


class GenerateImageOut(BaseModel):
Expand All @@ -475,10 +459,6 @@ class MultiGenerateImageIn(BaseModel):
"""
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://guides.substrate.run/guides/external-file-storage). If unset, the image data will be returned as a base64-encoded string.
"""
node: Literal["StableDiffusionXL"] = "StableDiffusionXL"
"""
Selected node.
"""


class MultiGenerateImageOut(BaseModel):
Expand Down Expand Up @@ -692,10 +672,6 @@ class GenerativeEditImageIn(BaseModel):
"""
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://guides.substrate.run/guides/external-file-storage). If unset, the image data will be returned as a base64-encoded string.
"""
node: Literal["StableDiffusionXLInpaint"] = "StableDiffusionXLInpaint"
"""
Selected node.
"""


class GenerativeEditImageOut(BaseModel):
Expand Down Expand Up @@ -726,10 +702,6 @@ class MultiGenerativeEditImageIn(BaseModel):
"""
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://guides.substrate.run/guides/external-file-storage). If unset, the image data will be returned as a base64-encoded string.
"""
node: Literal["StableDiffusionXLInpaint"] = "StableDiffusionXLInpaint"
"""
Selected node.
"""


class MultiGenerativeEditImageOut(BaseModel):
Expand Down Expand Up @@ -828,10 +800,6 @@ class FillMaskIn(BaseModel):
"""
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://guides.substrate.run/guides/external-file-storage). If unset, the image data will be returned as a base64-encoded string.
"""
node: Literal["BigLaMa"] = "BigLaMa"
"""
Selected node.
"""


class FillMaskOut(BaseModel):
Expand Down Expand Up @@ -880,10 +848,6 @@ class RemoveBackgroundIn(BaseModel):
"""
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://guides.substrate.run/guides/external-file-storage). If unset, the image data will be returned as a base64-encoded string.
"""
node: Literal["DISISNet"] = "DISISNet"
"""
Selected node.
"""


class RemoveBackgroundOut(BaseModel):
Expand Down Expand Up @@ -920,10 +884,6 @@ class UpscaleImageIn(BaseModel):
"""
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://guides.substrate.run/guides/external-file-storage). If unset, the image data will be returned as a base64-encoded string.
"""
node: Literal["RealESRGAN"] = "RealESRGAN"
"""
Selected node.
"""


class UpscaleImageOut(BaseModel):
Expand Down Expand Up @@ -964,10 +924,6 @@ class SegmentUnderPointIn(BaseModel):
"""
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://guides.substrate.run/guides/external-file-storage). If unset, the image data will be returned as a base64-encoded string.
"""
node: Literal["SegmentAnything"] = "SegmentAnything"
"""
Selected node.
"""


class SegmentUnderPointOut(BaseModel):
Expand Down Expand Up @@ -1111,10 +1067,6 @@ class GenerateSpeechIn(BaseModel):
"""
Use "hosted" to return an audio URL hosted on Substrate. You can also provide a URL to a registered [file store](https://guides.substrate.run/guides/external-file-storage). If unset, the audio data will be returned as a base64-encoded string.
"""
node: Literal["XTTSV2"] = "XTTSV2"
"""
Selected node.
"""


class GenerateSpeechOut(BaseModel):
Expand Down
30 changes: 30 additions & 0 deletions substrate/core/sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
ConcatDirective,
JQDirectiveTarget,
ConcatDirectiveItem,
ShortCircuitDirective,
ShortCircuitInputTarget,
ShortCircuitConditionTarget,
)

StringConcatable = Union[str, None, Future]
JQCompatible = Union[Future, JQTargetType]
ConditionCompatible = Union[Future, bool]


class sb:
Expand Down Expand Up @@ -64,3 +68,29 @@ def jq(cls, target: JQCompatible, query: str) -> Any:
if isinstance(target, Future):
result.FutureG.add_edge(target, result)
return result # type: ignore

@classmethod
def when(cls, condition: ConditionCompatible, input: Union[Future, Any]) -> Any:
"""
Short-circuiting conditional edge.
Only evaluate the subsequent node with the provided input if the condition is true.
:param condition: A boolean or a future reference to a boolean.
:param input: A future reference to the output of another node.
:return: A future reference to the short-circuiting `when` operator.
"""
c_future_id = condition.id if isinstance(condition, Future) else None
c_val = condition if not isinstance(condition, Future) else None
i_future_id = input.id if isinstance(input, Future) else None
i_val = input if not isinstance(input, Future) else None
directive = ShortCircuitDirective(
condition=ShortCircuitConditionTarget(future_id=c_future_id, val=c_val),
input=ShortCircuitInputTarget(future_id=i_future_id, val=i_val),
)
result = Future(directive=directive)
# add edge to the condition future
if isinstance(condition, Future):
result.FutureG.add_edge(condition, result)
# add edge to the input future
if isinstance(input, Future):
result.FutureG.add_edge(input, result)
return result # type: ignore
Loading

0 comments on commit 347ab48

Please sign in to comment.