Skip to content

Commit

Permalink
Merge pull request #19 from SubstrateLabs/run-function
Browse files Browse the repository at this point in the history
RunPython v2
  • Loading branch information
0thernet authored Jun 11, 2024
2 parents 28d17c0 + 5844a98 commit f13d377
Show file tree
Hide file tree
Showing 10 changed files with 314 additions and 472 deletions.
317 changes: 164 additions & 153 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 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 = "220240530.0.0"
version = "220240604.0.0"
description = "Substrate Python SDK"
readme = "README.md"
authors = [ "vprtwn <[email protected]>", "liamgriffiths <[email protected]>",]
Expand Down Expand Up @@ -44,6 +44,7 @@ exclude = [ "examples/notebooks",]

[tool.poetry.dependencies]
python = ">=3.9"
cloudpickle = "3.0.0"
networkx = ">=3.2.1"
httpx = ">=0.26.0"
distro = ">=1.8.0"
Expand Down
2 changes: 1 addition & 1 deletion substrate/GEN_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240530.20240531
20240604.20240610
12 changes: 4 additions & 8 deletions substrate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
𐃏 Substrate Python SDK
20240530.20240531
20240604.20240610
"""

from .nodes import (
Expand All @@ -10,7 +10,6 @@
JinaV2,
FillMask,
EmbedText,
RunPython,
EmbedImage,
Experimental,
FetchVectors,
Expand All @@ -32,27 +31,26 @@
RemoveBackground,
BatchGenerateJSON,
BatchGenerateText,
CreateVectorStore,
DeleteVectorStore,
Llama3Instruct70B,
Mistral7BInstruct,
MultiGenerateJSON,
MultiGenerateText,
SegmentUnderPoint,
StableDiffusionXL,
GenerateTextVision,
MultiGenerateImage,
GenerativeEditImage,
Mixtral8x7BInstruct,
FindOrCreateVectorStore,
MultiGenerativeEditImage,
StableDiffusionXLInpaint,
StableDiffusionXLIPAdapter,
StableDiffusionXLLightning,
StableDiffusionXLControlNet,
)
from .core.sb import sb
from ._version import __version__
from .substrate import Substrate, SubstrateResponse
from .run_python import RunPython

__all__ = [
"__version__",
Expand All @@ -77,11 +75,9 @@
"MultiGenerateImage",
"GenerativeEditImage",
"MultiGenerativeEditImage",
"StableDiffusionXL",
"StableDiffusionXLLightning",
"StableDiffusionXLInpaint",
"StableDiffusionXLControlNet",
"StableDiffusionXLIPAdapter",
"TranscribeMedia",
"GenerateSpeech",
"XTTSV2",
Expand All @@ -96,7 +92,7 @@
"MultiEmbedImage",
"JinaV2",
"CLIP",
"CreateVectorStore",
"FindOrCreateVectorStore",
"ListVectorStores",
"DeleteVectorStore",
"QueryVectorStore",
Expand Down
2 changes: 1 addition & 1 deletion substrate/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "220240530.0.0"
__version__ = "220240604.0.0"
75 changes: 26 additions & 49 deletions substrate/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -54,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 @@ -69,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 All @@ -101,7 +102,7 @@ class GenerateTextIn(BaseModel):
"Mixtral8x7BInstruct",
"Llama3Instruct8B",
"Llama3Instruct70B",
] = "Mistral7BInstruct"
] = "Llama3Instruct8B"
"""
Selected node.
"""
Expand Down Expand Up @@ -131,7 +132,7 @@ class GenerateJSONIn(BaseModel):
"""
Maximum number of tokens to generate.
"""
node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct"
node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B"
"""
Selected node.
"""
Expand Down Expand Up @@ -170,7 +171,7 @@ class MultiGenerateTextIn(BaseModel):
"Mixtral8x7BInstruct",
"Llama3Instruct8B",
"Llama3Instruct70B",
] = "Mistral7BInstruct"
] = "Llama3Instruct8B"
"""
Selected node.
"""
Expand Down Expand Up @@ -226,7 +227,7 @@ class MultiGenerateJSONIn(BaseModel):
"""
Maximum number of tokens to generate.
"""
node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct"
node: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B"
"""
Selected node.
"""
Expand All @@ -240,7 +241,7 @@ class MultiGenerateJSONOut(BaseModel):


class BatchGenerateJSONIn(BaseModel):
node: Literal["Mistral7BInstruct", "Llama3Instruct8B"] = "Mistral7BInstruct"
node: Literal["Mistral7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B"
"""
Selected node.
"""
Expand Down Expand Up @@ -1355,7 +1356,7 @@ class CLIPOut(BaseModel):
"""


class CreateVectorStoreIn(BaseModel):
class FindOrCreateVectorStoreIn(BaseModel):
collection_name: Annotated[str, Field(max_length=63, min_length=1)]
"""
Vector store name.
Expand All @@ -1364,21 +1365,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.
Expand All @@ -1387,26 +1376,14 @@ 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):
pass


class ListVectorStoresOut(BaseModel):
items: Optional[List[CreateVectorStoreOut]] = None
items: Optional[List[FindOrCreateVectorStoreOut]] = None
"""
List of vector stores.
"""
Expand Down
Loading

0 comments on commit f13d377

Please sign in to comment.