From b92884b12b06fe09f9c8596c976d9b6281bb83c6 Mon Sep 17 00:00:00 2001 From: Chris Sreesangkom Date: Wed, 14 Aug 2024 17:54:48 -0400 Subject: [PATCH] generate code codegen --- substrate/GEN_VERSION | 2 +- substrate/__init__.py | 120 +++++++++------------------ substrate/core/models.py | 53 +++++++++++- substrate/future_dataclass_models.py | 62 +++++++++++++- substrate/nodes.py | 63 +++++++++++++- substrate/typeddict_models.py | 51 +++++++++++- 6 files changed, 264 insertions(+), 87 deletions(-) diff --git a/substrate/GEN_VERSION b/substrate/GEN_VERSION index 766f9e7..bf0b572 100644 --- a/substrate/GEN_VERSION +++ b/substrate/GEN_VERSION @@ -1 +1 @@ -20240617.20240806 \ No newline at end of file +20240617.20240814 \ No newline at end of file diff --git a/substrate/__init__.py b/substrate/__init__.py index d5458ae..49f30ed 100644 --- a/substrate/__init__.py +++ b/substrate/__init__.py @@ -1,103 +1,59 @@ """ 𐃏 Substrate Python SDK -20240617.20240806 +20240617.20240814 """ -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, - - StableVideoDiffusion, - - InterpolateFrames, - - 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, + InterpolateFrames, + Llama3Instruct70B, + Mistral7BInstruct, + MultiInpaintImage, + SegmentUnderPoint, + MultiGenerateImage, + Mixtral8x7BInstruct, + StableVideoDiffusion, + FindOrCreateVectorStore, + StableDiffusionXLInpaint, + StableDiffusionXLLightning, + StableDiffusionXLControlNet, +) from .core.sb import sb from ._version import __version__ from .substrate import Secrets, Substrate, SubstrateResponse +from .run_python import RunPython __all__ = [ "__version__", @@ -150,4 +106,4 @@ "FetchVectors", "UpdateVectors", "DeleteVectors", - ] \ No newline at end of file +] diff --git a/substrate/core/models.py b/substrate/core/models.py index 9006cec..4d079d6 100644 --- a/substrate/core/models.py +++ b/substrate/core/models.py @@ -216,7 +216,13 @@ class Config: """ Maximum number of tokens to generate. """ - model: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B" + model: Literal[ + "Mistral7BInstruct", + "Mixtral8x7BInstruct", + "Llama3Instruct8B", + "Llama3Instruct70B", + "gpt-4o", + ] = "Llama3Instruct8B" """ Selected model. """ @@ -236,6 +242,51 @@ class Config: """ +class GenerateCodeIn(BaseModel): + class Config: + extra = Extra.allow + + prompt: str + """ + Input prompt. + """ + language: Literal[ + "python", + "java", + "c++", + "javascript", + "typescript", + "php", + "html", + "c#", + "sql", + "ruby", + "tex", + "shell", + ] + """ + Language of the code. + """ + temperature: Annotated[Optional[float], Field(ge=0.0, le=1.0)] = None + """ + Higher values make the output more random, lower values make the output more deterministic. + """ + max_tokens: Optional[int] = None + """ + Maximum number of tokens to generate. + """ + + +class GenerateCodeOut(BaseModel): + class Config: + extra = Extra.allow + + code: str + """ + Code response. + """ + + class MultiComputeTextIn(BaseModel): class Config: extra = Extra.allow diff --git a/substrate/future_dataclass_models.py b/substrate/future_dataclass_models.py index eceb3e8..00e24b9 100644 --- a/substrate/future_dataclass_models.py +++ b/substrate/future_dataclass_models.py @@ -270,7 +270,13 @@ class FutureComputeJSONIn: (Future reference) Maximum number of tokens to generate. """ - model: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B" + model: Literal[ + "Mistral7BInstruct", + "Mixtral8x7BInstruct", + "Llama3Instruct8B", + "Llama3Instruct70B", + "gpt-4o", + ] = "Llama3Instruct8B" """ (Future reference) Selected model. @@ -295,6 +301,60 @@ class FutureComputeJSONOut: """ +@dataclass +class FutureGenerateCodeIn: + """ + Future reference to FutureGenerateCodeIn + """ + + prompt: str + """ + (Future reference) + Input prompt. + """ + language: Literal[ + "python", + "java", + "c++", + "javascript", + "typescript", + "php", + "html", + "c#", + "sql", + "ruby", + "tex", + "shell", + ] + """ + (Future reference) + Language of the code. + """ + temperature: Optional[float] = None + """ + (Future reference) + Higher values make the output more random, lower values make the output more deterministic. + """ + max_tokens: Optional[int] = None + """ + (Future reference) + Maximum number of tokens to generate. + """ + + +@dataclass +class FutureGenerateCodeOut: + """ + Future reference to FutureGenerateCodeOut + """ + + code: str + """ + (Future reference) + Code response. + """ + + @dataclass class FutureMultiComputeTextIn: """ diff --git a/substrate/nodes.py b/substrate/nodes.py index ec288b4..67564a1 100644 --- a/substrate/nodes.py +++ b/substrate/nodes.py @@ -277,7 +277,13 @@ def __init__( json_schema: Dict[str, Any], temperature: float = 0.4, max_tokens: Optional[int] = None, - model: Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"] = "Llama3Instruct8B", + model: Literal[ + "Mistral7BInstruct", + "Mixtral8x7BInstruct", + "Llama3Instruct8B", + "Llama3Instruct70B", + "gpt-4o", + ] = "Llama3Instruct8B", hide: bool = False, **kwargs, ): @@ -313,6 +319,61 @@ def future(self) -> FutureComputeJSONOut: # type: ignore return super().future # type: ignore +class GenerateCode(CoreNode[GenerateCodeOut]): + """https://substrate.run/nodes#GenerateCode""" + + def __init__( + self, + prompt: str, + language: Literal[ + "python", + "java", + "c++", + "javascript", + "typescript", + "php", + "html", + "c#", + "sql", + "ruby", + "tex", + "shell", + ], + temperature: Optional[float] = None, + max_tokens: Optional[int] = None, + hide: bool = False, + **kwargs, + ): + """ + Args: + prompt: Input prompt. + language: Language of the code. + temperature: Higher values make the output more random, lower values make the output more deterministic. + max_tokens: Maximum number of tokens to generate. + + https://substrate.run/nodes#GenerateCode + """ + super().__init__( + prompt=prompt, + language=language, + temperature=temperature, + max_tokens=max_tokens, + hide=hide, + out_type=GenerateCodeOut, + **kwargs, + ) + self.node = "GenerateCode" + + @property + def future(self) -> FutureGenerateCodeOut: # type: ignore + """ + Future reference to this node's output. + + https://substrate.run/nodes#GenerateCode + """ + return super().future # type: ignore + + class MultiComputeText(CoreNode[MultiComputeTextOut]): """https://substrate.run/nodes#MultiComputeText""" diff --git a/substrate/typeddict_models.py b/substrate/typeddict_models.py index 775720c..baf97e1 100644 --- a/substrate/typeddict_models.py +++ b/substrate/typeddict_models.py @@ -180,7 +180,15 @@ class ComputeJSONIn(TypedDict): """ Maximum number of tokens to generate. """ - model: NotRequired[Literal["Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B"]] + model: NotRequired[ + Literal[ + "Mistral7BInstruct", + "Mixtral8x7BInstruct", + "Llama3Instruct8B", + "Llama3Instruct70B", + "gpt-4o", + ] + ] """ Selected model. """ @@ -197,6 +205,47 @@ class ComputeJSONOut(TypedDict): """ +class GenerateCodeIn(TypedDict): + prompt: NotRequired[str] + """ + Input prompt. + """ + language: NotRequired[ + Literal[ + "python", + "java", + "c++", + "javascript", + "typescript", + "php", + "html", + "c#", + "sql", + "ruby", + "tex", + "shell", + ] + ] + """ + Language of the code. + """ + temperature: NotRequired[float] + """ + Higher values make the output more random, lower values make the output more deterministic. + """ + max_tokens: NotRequired[int] + """ + Maximum number of tokens to generate. + """ + + +class GenerateCodeOut(TypedDict): + code: NotRequired[str] + """ + Code response. + """ + + class MultiComputeTextIn(TypedDict): prompt: NotRequired[str] """