diff --git a/substrate/GEN_VERSION b/substrate/GEN_VERSION index 9674ffc..820eb52 100644 --- a/substrate/GEN_VERSION +++ b/substrate/GEN_VERSION @@ -1 +1 @@ -20240530.20240531 \ No newline at end of file +20240604.20240610 \ No newline at end of file diff --git a/substrate/__init__.py b/substrate/__init__.py index 267c4af..b108a50 100644 --- a/substrate/__init__.py +++ b/substrate/__init__.py @@ -1,7 +1,7 @@ """ 𐃏 Substrate Python SDK -20240530.20240531 +20240604.20240610 """ from .nodes import ( @@ -32,21 +32,19 @@ RemoveBackground, BatchGenerateJSON, BatchGenerateText, - CreateVectorStore, DeleteVectorStore, Llama3Instruct70B, Mistral7BInstruct, MultiGenerateJSON, MultiGenerateText, SegmentUnderPoint, - StableDiffusionXL, GenerateTextVision, MultiGenerateImage, GenerativeEditImage, Mixtral8x7BInstruct, + FindOrCreateVectorStore, MultiGenerativeEditImage, StableDiffusionXLInpaint, - StableDiffusionXLIPAdapter, StableDiffusionXLLightning, StableDiffusionXLControlNet, ) @@ -77,11 +75,9 @@ "MultiGenerateImage", "GenerativeEditImage", "MultiGenerativeEditImage", - "StableDiffusionXL", "StableDiffusionXLLightning", "StableDiffusionXLInpaint", "StableDiffusionXLControlNet", - "StableDiffusionXLIPAdapter", "TranscribeMedia", "GenerateSpeech", "XTTSV2", @@ -96,7 +92,7 @@ "MultiEmbedImage", "JinaV2", "CLIP", - "CreateVectorStore", + "FindOrCreateVectorStore", "ListVectorStores", "DeleteVectorStore", "QueryVectorStore", diff --git a/substrate/core/models.py b/substrate/core/models.py index 89ef25f..a95a2ef 100644 --- a/substrate/core/models.py +++ b/substrate/core/models.py @@ -7,18 +7,11 @@ from __future__ import annotations -import os from typing import Any, Dict, List, Optional - -use_pydantic_v1 = os.getenv("USE_PYDANTIC_V1", "0").lower() == "1" - -if use_pydantic_v1: - from pydantic.v1 import Field, BaseModel -else: - from pydantic import Field, BaseModel - from typing_extensions import Literal, Annotated +from pydantic import Field, BaseModel + class ErrorOut(BaseModel): type: Literal["api_error", "invalid_request_error"] @@ -54,13 +47,17 @@ class ExperimentalOut(BaseModel): class RunPythonIn(BaseModel): - code: str + function: str + """ + Pickled function. """ - 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`. + arguments: str """ - input: Optional[Dict[str, Any]] = None + Pickled arguments. """ - Input to your code, accessible using the preloaded `SB_IN` variable. + python_version: Optional[str] = None + """ + Python version. """ pip_install: Optional[List[str]] = None """ @@ -73,9 +70,9 @@ class RunPythonOut(BaseModel): """ Everything printed to stdout while running your code. """ - output: Dict[str, Any] + output: Optional[Dict[str, Any]] = None """ - Contents of the `SB_OUT` variable after running your code. + Return value of your function. """ stderr: str """ @@ -101,7 +98,7 @@ class GenerateTextIn(BaseModel): "Mixtral8x7BInstruct", "Llama3Instruct8B", "Llama3Instruct70B", - ] = "Mistral7BInstruct" + ] = "Llama3Instruct8B" """ Selected node. """ @@ -131,7 +128,7 @@ class GenerateJSONIn(BaseModel): """ Maximum number of tokens to generate. """ - node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct" + node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B" """ Selected node. """ @@ -170,7 +167,7 @@ class MultiGenerateTextIn(BaseModel): "Mixtral8x7BInstruct", "Llama3Instruct8B", "Llama3Instruct70B", - ] = "Mistral7BInstruct" + ] = "Llama3Instruct8B" """ Selected node. """ @@ -226,7 +223,7 @@ class MultiGenerateJSONIn(BaseModel): """ Maximum number of tokens to generate. """ - node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct" + node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B" """ Selected node. """ @@ -240,7 +237,7 @@ class MultiGenerateJSONOut(BaseModel): class BatchGenerateJSONIn(BaseModel): - node: Literal["Mistral7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct" + node: Literal["Mistral7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B" """ Selected node. """ @@ -1355,7 +1352,7 @@ class CLIPOut(BaseModel): """ -class CreateVectorStoreIn(BaseModel): +class FindOrCreateVectorStoreIn(BaseModel): collection_name: Annotated[str, Field(max_length=63, min_length=1)] """ Vector store name. @@ -1364,21 +1361,9 @@ class CreateVectorStoreIn(BaseModel): """ Selected embedding model. """ - m: Annotated[int, Field(ge=1, le=64)] = 16 - """ - The max number of connections per layer for the index. - """ - ef_construction: Annotated[int, Field(ge=1, le=128)] = 64 - """ - The size of the dynamic candidate list for constructing the index graph. - """ - metric: Literal["cosine", "l2", "inner"] = "inner" - """ - The distance metric to construct the index with. - """ -class CreateVectorStoreOut(BaseModel): +class FindOrCreateVectorStoreOut(BaseModel): collection_name: Annotated[str, Field(max_length=63, min_length=1)] """ Vector store name. @@ -1387,18 +1372,6 @@ class CreateVectorStoreOut(BaseModel): """ Selected embedding model. """ - m: Annotated[int, Field(ge=1, le=64)] - """ - The max number of connections per layer for the index. - """ - ef_construction: Annotated[int, Field(ge=1, le=128)] - """ - The size of the dynamic candidate list for constructing the index graph. - """ - metric: Literal["cosine", "l2", "inner"] - """ - The distance metric to construct the index with. - """ class ListVectorStoresIn(BaseModel): @@ -1406,7 +1379,7 @@ class ListVectorStoresIn(BaseModel): class ListVectorStoresOut(BaseModel): - items: Optional[List[CreateVectorStoreOut]] = None + items: Optional[List[FindOrCreateVectorStoreOut]] = None """ List of vector stores. """ diff --git a/substrate/future_dataclass_models.py b/substrate/future_dataclass_models.py index 31e0f4a..06a126a 100644 --- a/substrate/future_dataclass_models.py +++ b/substrate/future_dataclass_models.py @@ -72,15 +72,20 @@ class FutureRunPythonIn: Future reference to FutureRunPythonIn """ - code: str + function: str """ (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`. + Pickled function. """ - input: Optional[Dict[str, Any]] = None + arguments: str """ (Future reference) - Input to your code, accessible using the preloaded `SB_IN` variable. + Pickled arguments. + """ + python_version: Optional[str] = None + """ + (Future reference) + Python version. """ pip_install: Optional[List[str]] = None """ @@ -100,15 +105,15 @@ 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[Dict[str, Any]] = None """ (Future reference) - Contents of stderr if your code did not run successfully. + Return value of your function. """ @@ -138,7 +143,7 @@ class FutureGenerateTextIn: "Mixtral8x7BInstruct", "Llama3Instruct8B", "Llama3Instruct70B", - ] = "Mistral7BInstruct" + ] = "Llama3Instruct8B" """ (Future reference) Selected node. @@ -184,7 +189,7 @@ class FutureGenerateJSONIn: (Future reference) Maximum number of tokens to generate. """ - node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct" + node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B" """ (Future reference) Selected node. @@ -240,7 +245,7 @@ class FutureMultiGenerateTextIn: "Mixtral8x7BInstruct", "Llama3Instruct8B", "Llama3Instruct70B", - ] = "Mistral7BInstruct" + ] = "Llama3Instruct8B" """ (Future reference) Selected node. @@ -327,7 +332,7 @@ class FutureMultiGenerateJSONIn: (Future reference) Maximum number of tokens to generate. """ - node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct" + node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B" """ (Future reference) Selected node. @@ -363,7 +368,7 @@ class FutureBatchGenerateJSONIn: (Future reference) JSON schema to guide `json_object` response. """ - node: Literal["Mistral7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct" + node: Literal["Mistral7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B" """ (Future reference) Selected node. @@ -2083,9 +2088,9 @@ class FutureCLIPOut: @dataclass -class FutureCreateVectorStoreIn: +class FutureFindOrCreateVectorStoreIn: """ - Future reference to FutureCreateVectorStoreIn + Future reference to FutureFindOrCreateVectorStoreIn """ collection_name: str @@ -2098,27 +2103,12 @@ class FutureCreateVectorStoreIn: (Future reference) Selected embedding model. """ - m: int = 16 - """ - (Future reference) - The max number of connections per layer for the index. - """ - ef_construction: int = 64 - """ - (Future reference) - The size of the dynamic candidate list for constructing the index graph. - """ - metric: Literal["cosine", "l2", "inner"] = "inner" - """ - (Future reference) - The distance metric to construct the index with. - """ @dataclass -class FutureCreateVectorStoreOut: +class FutureFindOrCreateVectorStoreOut: """ - Future reference to FutureCreateVectorStoreOut + Future reference to FutureFindOrCreateVectorStoreOut """ collection_name: str @@ -2131,21 +2121,6 @@ class FutureCreateVectorStoreOut: (Future reference) Selected embedding model. """ - m: int - """ - (Future reference) - The max number of connections per layer for the index. - """ - ef_construction: int - """ - (Future reference) - The size of the dynamic candidate list for constructing the index graph. - """ - metric: Literal["cosine", "l2", "inner"] - """ - (Future reference) - The distance metric to construct the index with. - """ @dataclass @@ -2163,7 +2138,7 @@ class FutureListVectorStoresOut: Future reference to FutureListVectorStoresOut """ - items: Optional[List[FutureCreateVectorStoreOut]] = None + items: Optional[List[FutureFindOrCreateVectorStoreOut]] = None """ (Future reference) List of vector stores. diff --git a/substrate/nodes.py b/substrate/nodes.py index 2291d57..f1247b3 100644 --- a/substrate/nodes.py +++ b/substrate/nodes.py @@ -35,21 +35,19 @@ RemoveBackgroundOut, BatchGenerateJSONOut, BatchGenerateTextOut, - CreateVectorStoreOut, DeleteVectorStoreOut, Llama3Instruct70BOut, Mistral7BInstructOut, MultiGenerateJSONOut, MultiGenerateTextOut, SegmentUnderPointOut, - StableDiffusionXLOut, GenerateTextVisionOut, MultiGenerateImageOut, GenerativeEditImageOut, Mixtral8x7BInstructOut, + FindOrCreateVectorStoreOut, MultiGenerativeEditImageOut, StableDiffusionXLInpaintOut, - StableDiffusionXLIPAdapterOut, StableDiffusionXLLightningOut, StableDiffusionXLControlNetOut, ) @@ -82,21 +80,19 @@ FutureRemoveBackgroundOut, FutureBatchGenerateJSONOut, FutureBatchGenerateTextOut, - FutureCreateVectorStoreOut, FutureDeleteVectorStoreOut, FutureLlama3Instruct70BOut, FutureMistral7BInstructOut, FutureMultiGenerateJSONOut, FutureMultiGenerateTextOut, FutureSegmentUnderPointOut, - FutureStableDiffusionXLOut, FutureGenerateTextVisionOut, FutureMultiGenerateImageOut, FutureGenerativeEditImageOut, FutureMixtral8x7BInstructOut, + FutureFindOrCreateVectorStoreOut, FutureMultiGenerativeEditImageOut, FutureStableDiffusionXLInpaintOut, - FutureStableDiffusionXLIPAdapterOut, FutureStableDiffusionXLLightningOut, FutureStableDiffusionXLControlNetOut, ) @@ -132,22 +128,25 @@ class RunPython(CoreNode[RunPythonOut]): def __init__( self, - code: str, - input: Optional[Dict[str, Any]] = None, + function: str, + arguments: str, + python_version: Optional[str] = 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. + function: Pickled function. + arguments: Pickled arguments. + python_version: Python version. pip_install: Python packages to install. You must import them in your code. https://substrate.run/nodes#RunPython """ super().__init__( - code=code, - input=input, + function=function, + arguments=arguments, + python_version=python_version, pip_install=pip_install, hide=hide, out_type=RunPythonOut, @@ -177,7 +176,7 @@ def __init__( "Mixtral8x7BInstruct", "Llama3Instruct8B", "Llama3Instruct70B", - ] = "Mistral7BInstruct", + ] = "Llama3Instruct8B", hide: bool = False, ): """ @@ -218,7 +217,7 @@ def __init__( json_schema: Dict[str, Any], temperature: float = 0.4, max_tokens: Optional[int] = None, - node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct", + node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B", hide: bool = False, ): """ @@ -266,7 +265,7 @@ def __init__( "Mixtral8x7BInstruct", "Llama3Instruct8B", "Llama3Instruct70B", - ] = "Mistral7BInstruct", + ] = "Llama3Instruct8B", hide: bool = False, ): """ @@ -347,7 +346,7 @@ def __init__( num_choices: int, temperature: float = 0.4, max_tokens: Optional[int] = None, - node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct", + node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B", hide: bool = False, ): """ @@ -390,7 +389,7 @@ def __init__( self, prompts: List[str], json_schema: Dict[str, Any], - node: Literal["Mistral7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct", + node: Literal["Mistral7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B", temperature: float = 0.4, max_tokens: Optional[int] = None, hide: bool = False, @@ -834,61 +833,6 @@ def future(self) -> FutureStableDiffusionXLLightningOut: # type: ignore return super().future # type: ignore -class StableDiffusionXLIPAdapter(CoreNode[StableDiffusionXLIPAdapterOut]): - """https://substrate.run/nodes#StableDiffusionXLIPAdapter""" - - def __init__( - self, - prompt: str, - image_prompt_uri: str, - num_images: int, - ip_adapter_scale: float = 0.5, - negative_prompt: Optional[str] = None, - store: Optional[str] = None, - width: int = 1024, - height: int = 1024, - seeds: Optional[List[int]] = None, - hide: bool = False, - ): - """ - Args: - prompt: Text prompt. - image_prompt_uri: Image prompt. - num_images: Number of images to generate. - ip_adapter_scale: Controls the influence of the image prompt on the generated output. - negative_prompt: Negative input prompt. - 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. - width: Width of output image, in pixels. - height: Height of output image, in pixels. - seeds: Random noise seeds. Default is random seeds for each generation. - - https://substrate.run/nodes#StableDiffusionXLIPAdapter - """ - super().__init__( - prompt=prompt, - image_prompt_uri=image_prompt_uri, - num_images=num_images, - ip_adapter_scale=ip_adapter_scale, - negative_prompt=negative_prompt, - store=store, - width=width, - height=height, - seeds=seeds, - hide=hide, - out_type=StableDiffusionXLIPAdapterOut, - ) - self.node = "StableDiffusionXLIPAdapter" - - @property - def future(self) -> FutureStableDiffusionXLIPAdapterOut: # type: ignore - """ - Future reference to this node's output. - - https://substrate.run/nodes#StableDiffusionXLIPAdapter - """ - return super().future # type: ignore - - class StableDiffusionXLControlNet(CoreNode[StableDiffusionXLControlNetOut]): """https://substrate.run/nodes#StableDiffusionXLControlNet""" @@ -1610,45 +1554,36 @@ def future(self) -> FutureCLIPOut: # type: ignore return super().future # type: ignore -class CreateVectorStore(CoreNode[CreateVectorStoreOut]): - """https://substrate.run/nodes#CreateVectorStore""" +class FindOrCreateVectorStore(CoreNode[FindOrCreateVectorStoreOut]): + """https://substrate.run/nodes#FindOrCreateVectorStore""" def __init__( self, collection_name: str, model: Literal["jina-v2", "clip"], - m: int = 16, - ef_construction: int = 64, - metric: Literal["cosine", "l2", "inner"] = "inner", hide: bool = False, ): """ Args: collection_name: Vector store name. model: Selected embedding model. - m: The max number of connections per layer for the index. - ef_construction: The size of the dynamic candidate list for constructing the index graph. - metric: The distance metric to construct the index with. - https://substrate.run/nodes#CreateVectorStore + https://substrate.run/nodes#FindOrCreateVectorStore """ super().__init__( collection_name=collection_name, model=model, - m=m, - ef_construction=ef_construction, - metric=metric, hide=hide, - out_type=CreateVectorStoreOut, + out_type=FindOrCreateVectorStoreOut, ) - self.node = "CreateVectorStore" + self.node = "FindOrCreateVectorStore" @property - def future(self) -> FutureCreateVectorStoreOut: # type: ignore + def future(self) -> FutureFindOrCreateVectorStoreOut: # type: ignore """ Future reference to this node's output. - https://substrate.run/nodes#CreateVectorStore + https://substrate.run/nodes#FindOrCreateVectorStore """ return super().future # type: ignore diff --git a/substrate/typeddict_models.py b/substrate/typeddict_models.py index 124dd65..f7a4b22 100644 --- a/substrate/typeddict_models.py +++ b/substrate/typeddict_models.py @@ -45,13 +45,17 @@ class ExperimentalOut(TypedDict): class RunPythonIn(TypedDict): - code: NotRequired[str] + 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]] + arguments: NotRequired[str] """ - Input to your code, accessible using the preloaded `SB_IN` variable. + Pickled arguments. + """ + python_version: NotRequired[str] + """ + Python version. """ pip_install: NotRequired[List[str]] """ @@ -66,7 +70,7 @@ class RunPythonOut(TypedDict): """ output: NotRequired[Dict[str, Any]] """ - Contents of the `SB_OUT` variable after running your code. + Return value of your function. """ stderr: NotRequired[str] """ @@ -1350,7 +1354,7 @@ class CLIPOut(TypedDict): """ -class CreateVectorStoreIn(TypedDict): +class FindOrCreateVectorStoreIn(TypedDict): collection_name: NotRequired[str] """ Vector store name. @@ -1359,21 +1363,9 @@ class CreateVectorStoreIn(TypedDict): """ Selected embedding model. """ - m: NotRequired[int] - """ - The max number of connections per layer for the index. - """ - ef_construction: NotRequired[int] - """ - The size of the dynamic candidate list for constructing the index graph. - """ - metric: NotRequired[Literal["cosine", "l2", "inner"]] - """ - The distance metric to construct the index with. - """ -class CreateVectorStoreOut(TypedDict): +class FindOrCreateVectorStoreOut(TypedDict): collection_name: NotRequired[str] """ Vector store name. @@ -1382,18 +1374,6 @@ class CreateVectorStoreOut(TypedDict): """ Selected embedding model. """ - m: NotRequired[int] - """ - The max number of connections per layer for the index. - """ - ef_construction: NotRequired[int] - """ - The size of the dynamic candidate list for constructing the index graph. - """ - metric: NotRequired[Literal["cosine", "l2", "inner"]] - """ - The distance metric to construct the index with. - """ class ListVectorStoresIn(TypedDict): @@ -1401,7 +1381,7 @@ class ListVectorStoresIn(TypedDict): class ListVectorStoresOut(TypedDict): - items: NotRequired[List[CreateVectorStoreOut]] + items: NotRequired[List[FindOrCreateVectorStoreOut]] """ List of vector stores. """