Skip to content

Commit

Permalink
format string operator
Browse files Browse the repository at this point in the history
  • Loading branch information
csreesan committed Jul 24, 2024
1 parent acd4190 commit a93d596
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 101 deletions.
2 changes: 1 addition & 1 deletion substrate/GEN_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240617.20240718
20240617.20240719
114 changes: 36 additions & 78 deletions substrate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,99 +1,57 @@
"""
𐃏 Substrate Python SDK
20240617.20240718
20240617.20240719
"""

from .run_python import RunPython
from .nodes import (

Experimental,

Box,

CLIP,
If,

ComputeText,

MultiComputeText,

BatchComputeText,

BatchComputeJSON,

Box,
JinaV2,
EmbedText,
EmbedImage,
EraseImage,
ComputeJSON,

MultiComputeJSON,

Mistral7BInstruct,

Mixtral8x7BInstruct,

Llama3Instruct8B,

Llama3Instruct70B,

ComputeText,
Experimental,
FetchVectors,
Firellava13B,

GenerateImage,

MultiGenerateImage,

InpaintImage,

MultiInpaintImage,

StableDiffusionXLLightning,

StableDiffusionXLInpaint,

StableDiffusionXLControlNet,

TranscribeSpeech,

GenerateSpeech,

RemoveBackground,

EraseImage,

UpscaleImage,

SegmentUnderPoint,

SegmentAnything,

DeleteVectors,
GenerateImage,
SplitDocument,

EmbedText,

UpdateVectors,
GenerateSpeech,
MultiEmbedText,

EmbedImage,

MultiEmbedImage,

JinaV2,

CLIP,

FindOrCreateVectorStore,

SegmentAnything,
BatchComputeJSON,
BatchComputeText,
ListVectorStores,

DeleteVectorStore,

Llama3Instruct8B,
MultiComputeJSON,
MultiComputeText,
QueryVectorStore,

FetchVectors,

UpdateVectors,

DeleteVectors,
)
RemoveBackground,
TranscribeSpeech,
DeleteVectorStore,
Llama3Instruct70B,
Mistral7BInstruct,
MultiInpaintImage,
SegmentUnderPoint,
MultiGenerateImage,
Mixtral8x7BInstruct,
FindOrCreateVectorStore,
StableDiffusionXLInpaint,
StableDiffusionXLLightning,
StableDiffusionXLControlNet,
)
from .core.sb import sb
from ._version import __version__
from .substrate import Substrate, SubstrateResponse
from .run_python import RunPython

__all__ = [
"__version__",
Expand Down Expand Up @@ -143,4 +101,4 @@
"FetchVectors",
"UpdateVectors",
"DeleteVectors",
]
]
27 changes: 25 additions & 2 deletions substrate/core/future_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from dataclasses import asdict, dataclass

OpType = Literal["trace", "string-concat", "jq", "jinja"]
OpType = Literal["trace", "string-concat", "jq", "jinja", "format"]


class BaseDirective(ABC):
Expand Down Expand Up @@ -63,7 +63,7 @@ class JinjaTemplate:
class JinjaDirective(BaseDirective):
template: JinjaTemplate
variables: Dict[str, Any]
type: Literal["jq"] = "jinja"
type: Literal["jinja"] = "jinja"

def to_dict(self) -> Dict:
from .base_future import BaseFuture
Expand All @@ -75,6 +75,29 @@ def to_dict(self) -> Dict:
"variables": replaced,
}

@dataclass
class FString:
future_id: Optional[str]
val: Optional[str]


@dataclass
class FormatDirective(BaseDirective):
f_string: FString
variables: Dict[str, Any]
type: Literal["format"] = "format"

def to_dict(self) -> Dict:
from .base_future import BaseFuture

replaced = BaseFuture.replace_futures_with_placeholder(self.variables)
return {
"type": self.type,
"f_string": asdict(self.f_string),
"variables": replaced,
}



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

Expand Down
39 changes: 21 additions & 18 deletions substrate/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ class Config:
"Llama3Instruct8B",
"Llama3Instruct70B",
"Firellava13B",
"gpt-4o",
"gpt-4o-mini",
"claude-3-5-sonnet-20240620",
] = "Llama3Instruct8B"
"""
Selected model. `Firellava13B` is automatically selected when `image_uris` is provided.
Expand Down Expand Up @@ -691,7 +694,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -719,7 +722,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -755,7 +758,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""
height: Annotated[int, Field(ge=256, le=1536)] = 1024
"""
Expand Down Expand Up @@ -817,7 +820,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""
height: Annotated[int, Field(ge=256, le=1536)] = 1024
"""
Expand Down Expand Up @@ -869,7 +872,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""
width: Annotated[int, Field(ge=640, le=1536)] = 1024
"""
Expand Down Expand Up @@ -925,7 +928,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""
conditioning_scale: Annotated[float, Field(ge=0.0, le=1.0)] = 0.5
"""
Expand Down Expand Up @@ -969,7 +972,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -1005,7 +1008,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -1049,7 +1052,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""
strength: Annotated[float, Field(ge=0.0, le=1.0)] = 0.8
"""
Expand Down Expand Up @@ -1121,7 +1124,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -1149,7 +1152,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -1185,7 +1188,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand All @@ -1209,7 +1212,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -1241,7 +1244,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -1269,7 +1272,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -1301,7 +1304,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an image URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the image data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -1439,7 +1442,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an audio URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the audio data will be returned as a base64-encoded string.
"""


Expand Down Expand Up @@ -1471,7 +1474,7 @@ class Config:
"""
store: Optional[str] = None
"""
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.
Use "hosted" to return an audio URL hosted on Substrate. You can also provide a URL to a registered [file store](https://docs.substrate.run/reference/external-files). If unset, the audio data will be returned as a base64-encoded string.
"""


Expand Down
Loading

0 comments on commit a93d596

Please sign in to comment.