Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
0thernet committed Jun 11, 2024
1 parent 3d478fa commit ee793e6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 66 deletions.
2 changes: 1 addition & 1 deletion substrate/GEN_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240604.20240607
20240604.20240611
4 changes: 2 additions & 2 deletions substrate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
𐃏 Substrate Python SDK
20240604.20240607
20240604.20240611
"""

from .nodes import (
Expand All @@ -10,7 +10,6 @@
JinaV2,
FillMask,
EmbedText,
RunPython,
EmbedImage,
Experimental,
FetchVectors,
Expand Down Expand Up @@ -51,6 +50,7 @@
from .core.sb import sb
from ._version import __version__
from .substrate import Substrate, SubstrateResponse
from .run_python import RunPython

__all__ = [
"__version__",
Expand Down
28 changes: 20 additions & 8 deletions substrate/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ class ExperimentalOut(BaseModel):


class RunPythonIn(BaseModel):
code: str
pkl_function: Optional[str] = None
"""
Python code to execute. In your code, access values from the `input` parameter using the `SB_IN` variable. Update the `SB_OUT` variable with results you want returned in `output`.
Pickled function.
"""
input: Optional[Dict[str, Any]] = None
kwargs: Dict[str, Any]
"""
Input to your code, accessible using the preloaded `SB_IN` variable.
Keyword arguments to your function.
"""
python_version: Optional[str] = None
"""
Python version.
"""
pip_install: Optional[List[str]] = None
"""
Expand All @@ -62,13 +66,17 @@ class RunPythonIn(BaseModel):


class RunPythonOut(BaseModel):
stdout: str
output: Optional[Any] = None
"""
Everything printed to stdout while running your code.
Return value of your function.
"""
output: Dict[str, Any]
pkl_output: Optional[str] = None
"""
Pickled return value.
"""
Contents of the `SB_OUT` variable after running your code.
stdout: str
"""
Everything printed to stdout while running your code.
"""
stderr: str
"""
Expand Down Expand Up @@ -914,6 +922,10 @@ class DISISNetOut(BaseModel):


class UpscaleImageIn(BaseModel):
prompt: Optional[str] = None
"""
Prompt to guide model on the content of image to upscale.
"""
image_uri: str
"""
Input image.
Expand Down
31 changes: 23 additions & 8 deletions substrate/future_dataclass_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,20 @@ class FutureRunPythonIn:
Future reference to FutureRunPythonIn
"""

code: str
kwargs: Dict[str, Any]
"""
(Future reference)
Python code to execute. In your code, access values from the `input` parameter using the `SB_IN` variable. Update the `SB_OUT` variable with results you want returned in `output`.
Keyword arguments to your function.
"""
input: Optional[Dict[str, Any]] = None
pkl_function: Optional[str] = None
"""
(Future reference)
Input to your code, accessible using the preloaded `SB_IN` variable.
Pickled function.
"""
python_version: Optional[str] = None
"""
(Future reference)
Python version.
"""
pip_install: Optional[List[str]] = None
"""
Expand All @@ -100,15 +105,20 @@ class FutureRunPythonOut:
(Future reference)
Everything printed to stdout while running your code.
"""
output: Dict[str, Any]
stderr: str
"""
(Future reference)
Contents of the `SB_OUT` variable after running your code.
Contents of stderr if your code did not run successfully.
"""
stderr: str
output: Optional[Any] = None
"""
(Future reference)
Contents of stderr if your code did not run successfully.
Return value of your function.
"""
pkl_output: Optional[str] = None
"""
(Future reference)
Pickled return value.
"""


Expand Down Expand Up @@ -1409,6 +1419,11 @@ class FutureUpscaleImageIn:
(Future reference)
Input image.
"""
prompt: Optional[str] = None
"""
(Future reference)
Prompt to guide model on the content of image to upscale.
"""
output_resolution: int = 1024
"""
(Future reference)
Expand Down
42 changes: 3 additions & 39 deletions substrate/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
XTTSV2Out,
FillMaskOut,
EmbedTextOut,
RunPythonOut,
EmbedImageOut,
ExperimentalOut,
FetchVectorsOut,
Expand Down Expand Up @@ -58,7 +57,6 @@
FutureXTTSV2Out,
FutureFillMaskOut,
FutureEmbedTextOut,
FutureRunPythonOut,
FutureEmbedImageOut,
FutureExperimentalOut,
FutureFetchVectorsOut,
Expand Down Expand Up @@ -123,43 +121,6 @@ def future(self) -> FutureExperimentalOut: # type: ignore
return super().future # type: ignore


class RunPython(CoreNode[RunPythonOut]):
"""https://substrate.run/nodes#RunPython"""

def __init__(
self,
code: str,
input: Optional[Dict[str, Any]] = None,
pip_install: Optional[List[str]] = None,
hide: bool = False,
):
"""
Args:
code: Python code to execute. In your code, access values from the `input` parameter using the `SB_IN` variable. Update the `SB_OUT` variable with results you want returned in `output`.
input: Input to your code, accessible using the preloaded `SB_IN` variable.
pip_install: Python packages to install. You must import them in your code.
https://substrate.run/nodes#RunPython
"""
super().__init__(
code=code,
input=input,
pip_install=pip_install,
hide=hide,
out_type=RunPythonOut,
)
self.node = "RunPython"

@property
def future(self) -> FutureRunPythonOut: # type: ignore
"""
Future reference to this node's output.
https://substrate.run/nodes#RunPython
"""
return super().future # type: ignore


class GenerateText(CoreNode[GenerateTextOut]):
"""https://substrate.run/nodes#GenerateText"""

Expand Down Expand Up @@ -1054,20 +1015,23 @@ class UpscaleImage(CoreNode[UpscaleImageOut]):
def __init__(
self,
image_uri: str,
prompt: Optional[str] = None,
output_resolution: int = 1024,
store: Optional[str] = None,
hide: bool = False,
):
"""
Args:
image_uri: Input image.
prompt: Prompt to guide model on the content of image to upscale.
output_resolution: Resolution of the output image, in pixels.
store: 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.
https://substrate.run/nodes#UpscaleImage
"""
super().__init__(
image_uri=image_uri,
prompt=prompt,
output_resolution=output_resolution,
store=store,
hide=hide,
Expand Down
28 changes: 20 additions & 8 deletions substrate/typeddict_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ class ExperimentalOut(TypedDict):


class RunPythonIn(TypedDict):
code: NotRequired[str]
pkl_function: NotRequired[str]
"""
Python code to execute. In your code, access values from the `input` parameter using the `SB_IN` variable. Update the `SB_OUT` variable with results you want returned in `output`.
Pickled function.
"""
input: NotRequired[Dict[str, Any]]
kwargs: NotRequired[Dict[str, Any]]
"""
Input to your code, accessible using the preloaded `SB_IN` variable.
Keyword arguments to your function.
"""
python_version: NotRequired[str]
"""
Python version.
"""
pip_install: NotRequired[List[str]]
"""
Expand All @@ -60,13 +64,17 @@ class RunPythonIn(TypedDict):


class RunPythonOut(TypedDict):
stdout: NotRequired[str]
output: NotRequired[Any]
"""
Everything printed to stdout while running your code.
Return value of your function.
"""
output: NotRequired[Dict[str, Any]]
pkl_output: NotRequired[str]
"""
Pickled return value.
"""
Contents of the `SB_OUT` variable after running your code.
stdout: NotRequired[str]
"""
Everything printed to stdout while running your code.
"""
stderr: NotRequired[str]
"""
Expand Down Expand Up @@ -916,6 +924,10 @@ class DISISNetOut(TypedDict):


class UpscaleImageIn(TypedDict):
prompt: NotRequired[str]
"""
Prompt to guide model on the content of image to upscale.
"""
image_uri: NotRequired[str]
"""
Input image.
Expand Down

0 comments on commit ee793e6

Please sign in to comment.