Skip to content

Commit

Permalink
make sync
Browse files Browse the repository at this point in the history
  • Loading branch information
0thernet committed May 3, 2024
1 parent 29be43b commit f309ea7
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 278 deletions.
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
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 only_if(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 `only_if` 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
60 changes: 0 additions & 60 deletions substrate/future_dataclass_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ class FutureBatchGenerateTextIn:
(Future reference)
Maximum number of tokens to generate.
"""
node: Literal["Mistral7BInstruct"] = "Mistral7BInstruct"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -342,11 +337,6 @@ class FutureBatchGenerateJSONIn:
(Future reference)
Maximum number of tokens to generate.
"""
node: Literal["Mistral7BInstruct"] = "Mistral7BInstruct"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -619,11 +609,6 @@ class FutureGenerateTextVisionIn:
(Future reference)
Maximum number of tokens to generate.
"""
node: Literal["Firellava13B"] = "Firellava13B"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -691,11 +676,6 @@ class FutureGenerateImageIn:
(Future reference)
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"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -732,11 +712,6 @@ class FutureMultiGenerateImageIn:
(Future reference)
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"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -1050,11 +1025,6 @@ class FutureGenerativeEditImageIn:
(Future reference)
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"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -1101,11 +1071,6 @@ class FutureMultiGenerativeEditImageIn:
(Future reference)
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"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -1254,11 +1219,6 @@ class FutureFillMaskIn:
(Future reference)
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"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -1336,11 +1296,6 @@ class FutureRemoveBackgroundIn:
(Future reference)
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"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -1403,11 +1358,6 @@ class FutureUpscaleImageIn:
(Future reference)
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"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -1475,11 +1425,6 @@ class FutureSegmentUnderPointIn:
(Future reference)
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"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down Expand Up @@ -1697,11 +1642,6 @@ class FutureGenerateSpeechIn:
(Future reference)
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"
"""
(Future reference)
Selected node.
"""


@dataclass
Expand Down
Loading

0 comments on commit f309ea7

Please sign in to comment.