From cbb78d4e69c31de631241eb0c0cbb984225365c7 Mon Sep 17 00:00:00 2001 From: Chris Sreesangkom Date: Thu, 15 Aug 2024 12:21:36 -0400 Subject: [PATCH 1/2] python generate code --- substrate/GEN_VERSION | 2 +- substrate/__init__.py | 4 +- substrate/core/models.py | 134 ++++++++++++++++++++-- substrate/future_dataclass_models.py | 159 +++++++++++++++++++++++++-- substrate/nodes.py | 146 ++++++++++++++++++++++-- substrate/typeddict_models.py | 123 +++++++++++++++++++-- 6 files changed, 536 insertions(+), 32 deletions(-) diff --git a/substrate/GEN_VERSION b/substrate/GEN_VERSION index bf0b572..710ae09 100644 --- a/substrate/GEN_VERSION +++ b/substrate/GEN_VERSION @@ -1 +1 @@ -20240617.20240814 \ No newline at end of file +20240617.20240815 \ No newline at end of file diff --git a/substrate/__init__.py b/substrate/__init__.py index ea93af4..cb40647 100644 --- a/substrate/__init__.py +++ b/substrate/__init__.py @@ -1,7 +1,7 @@ """ 𐃏 Substrate Python SDK -20240617.20240814 +20240617.20240815 """ from .nodes import ( @@ -41,6 +41,7 @@ InterpolateFrames, Llama3Instruct70B, Mistral7BInstruct, + MultiGenerateCode, MultiInpaintImage, SegmentUnderPoint, MultiGenerateImage, @@ -73,6 +74,7 @@ "ComputeJSON", "MultiComputeJSON", "GenerateCode", + "MultiGenerateCode", "Mistral7BInstruct", "Mixtral8x7BInstruct", "Llama3Instruct8B", diff --git a/substrate/core/models.py b/substrate/core/models.py index 4d079d6..1cfd4cd 100644 --- a/substrate/core/models.py +++ b/substrate/core/models.py @@ -242,7 +242,7 @@ class Config: """ -class GenerateCodeIn(BaseModel): +class DeepseekIn(BaseModel): class Config: extra = Extra.allow @@ -251,18 +251,75 @@ class Config: Input prompt. """ language: Literal[ - "python", - "java", + "c", "c++", + "c#", + "css", + "go", + "html", + "java", "javascript", + "json", + "python", + "r", + "ruby", + "shell", + "sql", + "tex", "typescript", - "php", - "html", + ] + """ + Language of the code. + """ + num_choices: Annotated[int, Field(ge=1, le=8)] = 1 + """ + Number of choices to generate. + """ + 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 GenerateCodeChoice(BaseModel): + class Config: + extra = Extra.allow + + code: str + """ + Code response. + """ + + +class GenerateCodeIn(BaseModel): + class Config: + extra = Extra.allow + + prompt: str + """ + Input prompt. + """ + language: Literal[ + "c", + "c++", "c#", - "sql", + "css", + "go", + "html", + "java", + "javascript", + "json", + "python", + "r", "ruby", - "tex", "shell", + "sql", + "tex", + "typescript", ] """ Language of the code. @@ -287,6 +344,59 @@ class Config: """ +class MultiGenerateCodeIn(BaseModel): + class Config: + extra = Extra.allow + + prompt: str + """ + Input prompt. + """ + language: Literal[ + "c", + "c++", + "c#", + "css", + "go", + "html", + "java", + "javascript", + "json", + "python", + "r", + "ruby", + "shell", + "sql", + "tex", + "typescript", + ] + """ + Language of the code. + """ + num_choices: Annotated[int, Field(ge=1, le=8)] = 1 + """ + Number of choices to generate. + """ + 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 MultiGenerateCodeOut(BaseModel): + class Config: + extra = Extra.allow + + choices: List[GenerateCodeChoice] + """ + Code response choices. + """ + + class MultiComputeTextIn(BaseModel): class Config: extra = Extra.allow @@ -2217,3 +2327,13 @@ class Config: """ Document chunks """ + + +class DeepseekOut(BaseModel): + class Config: + extra = Extra.allow + + choices: List[GenerateCodeChoice] + """ + Code response choices. + """ diff --git a/substrate/future_dataclass_models.py b/substrate/future_dataclass_models.py index 00e24b9..9bed3a5 100644 --- a/substrate/future_dataclass_models.py +++ b/substrate/future_dataclass_models.py @@ -302,9 +302,9 @@ class FutureComputeJSONOut: @dataclass -class FutureGenerateCodeIn: +class FutureDeepseekIn: """ - Future reference to FutureGenerateCodeIn + Future reference to FutureDeepseekIn """ prompt: str @@ -313,18 +313,85 @@ class FutureGenerateCodeIn: Input prompt. """ language: Literal[ - "python", - "java", + "c", "c++", + "c#", + "css", + "go", + "html", + "java", "javascript", + "json", + "python", + "r", + "ruby", + "shell", + "sql", + "tex", "typescript", - "php", - "html", + ] + """ + (Future reference) + Language of the code. + """ + num_choices: int = 1 + """ + (Future reference) + Number of choices to generate. + """ + 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 GenerateCodeChoice: + """ + Future reference to GenerateCodeChoice + """ + + code: str + """ + (Future reference) + Code response. + """ + + +@dataclass +class FutureGenerateCodeIn: + """ + Future reference to FutureGenerateCodeIn + """ + + prompt: str + """ + (Future reference) + Input prompt. + """ + language: Literal[ + "c", + "c++", "c#", - "sql", + "css", + "go", + "html", + "java", + "javascript", + "json", + "python", + "r", "ruby", - "tex", "shell", + "sql", + "tex", + "typescript", ] """ (Future reference) @@ -355,6 +422,69 @@ class FutureGenerateCodeOut: """ +@dataclass +class FutureMultiGenerateCodeIn: + """ + Future reference to FutureMultiGenerateCodeIn + """ + + prompt: str + """ + (Future reference) + Input prompt. + """ + language: Literal[ + "c", + "c++", + "c#", + "css", + "go", + "html", + "java", + "javascript", + "json", + "python", + "r", + "ruby", + "shell", + "sql", + "tex", + "typescript", + ] + """ + (Future reference) + Language of the code. + """ + num_choices: int = 1 + """ + (Future reference) + Number of choices to generate. + """ + 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 FutureMultiGenerateCodeOut: + """ + Future reference to FutureMultiGenerateCodeOut + """ + + choices: List[GenerateCodeChoice] + """ + (Future reference) + Code response choices. + """ + + @dataclass class FutureMultiComputeTextIn: """ @@ -2814,3 +2944,16 @@ class FutureSplitDocumentOut: (Future reference) Document chunks """ + + +@dataclass +class FutureDeepseekOut: + """ + Future reference to FutureDeepseekOut + """ + + choices: List[GenerateCodeChoice] + """ + (Future reference) + Code response choices. + """ diff --git a/substrate/nodes.py b/substrate/nodes.py index 368ed3a..ec8add3 100644 --- a/substrate/nodes.py +++ b/substrate/nodes.py @@ -50,6 +50,7 @@ InterpolateFramesOut, Llama3Instruct70BOut, Mistral7BInstructOut, + MultiGenerateCodeOut, MultiInpaintImageOut, SegmentUnderPointOut, MultiGenerateImageOut, @@ -102,6 +103,7 @@ FutureInterpolateFramesOut, FutureLlama3Instruct70BOut, FutureMistral7BInstructOut, + FutureMultiGenerateCodeOut, FutureMultiInpaintImageOut, FutureSegmentUnderPointOut, FutureMultiGenerateImageOut, @@ -321,25 +323,91 @@ def future(self) -> FutureComputeJSONOut: # type: ignore return super().future # type: ignore -class GenerateCode(CoreNode[GenerateCodeOut]): - """https://substrate.run/nodes#GenerateCode""" +class Deepseek(CoreNode[DeepseekOut]): + """https://substrate.run/nodes#Deepseek""" def __init__( self, prompt: str, language: Literal[ - "python", - "java", + "c", "c++", + "c#", + "css", + "go", + "html", + "java", "javascript", + "json", + "python", + "r", + "ruby", + "shell", + "sql", + "tex", "typescript", - "php", - "html", + ], + num_choices: int = 1, + temperature: Optional[float] = None, + max_tokens: Optional[int] = None, + hide: bool = False, + **kwargs, + ): + """ + Args: + prompt: Input prompt. + language: Language of the code. + num_choices: Number of choices to generate. + 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#Deepseek + """ + super().__init__( + prompt=prompt, + language=language, + num_choices=num_choices, + temperature=temperature, + max_tokens=max_tokens, + hide=hide, + out_type=DeepseekOut, + **kwargs, + ) + self.node = "Deepseek" + + @property + def future(self) -> FutureDeepseekOut: # type: ignore + """ + Future reference to this node's output. + + https://substrate.run/nodes#Deepseek + """ + return super().future # type: ignore + + +class GenerateCode(CoreNode[GenerateCodeOut]): + """https://substrate.run/nodes#GenerateCode""" + + def __init__( + self, + prompt: str, + language: Literal[ + "c", + "c++", "c#", - "sql", + "css", + "go", + "html", + "java", + "javascript", + "json", + "python", + "r", "ruby", - "tex", "shell", + "sql", + "tex", + "typescript", ], temperature: Optional[float] = None, max_tokens: Optional[int] = None, @@ -376,6 +444,68 @@ def future(self) -> FutureGenerateCodeOut: # type: ignore return super().future # type: ignore +class MultiGenerateCode(CoreNode[MultiGenerateCodeOut]): + """https://substrate.run/nodes#MultiGenerateCode""" + + def __init__( + self, + prompt: str, + language: Literal[ + "c", + "c++", + "c#", + "css", + "go", + "html", + "java", + "javascript", + "json", + "python", + "r", + "ruby", + "shell", + "sql", + "tex", + "typescript", + ], + num_choices: int = 1, + temperature: Optional[float] = None, + max_tokens: Optional[int] = None, + hide: bool = False, + **kwargs, + ): + """ + Args: + prompt: Input prompt. + language: Language of the code. + num_choices: Number of choices to generate. + 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#MultiGenerateCode + """ + super().__init__( + prompt=prompt, + language=language, + num_choices=num_choices, + temperature=temperature, + max_tokens=max_tokens, + hide=hide, + out_type=MultiGenerateCodeOut, + **kwargs, + ) + self.node = "MultiGenerateCode" + + @property + def future(self) -> FutureMultiGenerateCodeOut: # type: ignore + """ + Future reference to this node's output. + + https://substrate.run/nodes#MultiGenerateCode + """ + 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 baf97e1..1b7896e 100644 --- a/substrate/typeddict_models.py +++ b/substrate/typeddict_models.py @@ -205,25 +205,78 @@ class ComputeJSONOut(TypedDict): """ -class GenerateCodeIn(TypedDict): +class DeepseekIn(TypedDict): prompt: NotRequired[str] """ Input prompt. """ language: NotRequired[ Literal[ - "python", - "java", + "c", "c++", + "c#", + "css", + "go", + "html", + "java", "javascript", + "json", + "python", + "r", + "ruby", + "shell", + "sql", + "tex", "typescript", - "php", - "html", + ] + ] + """ + Language of the code. + """ + num_choices: NotRequired[int] + """ + Number of choices to generate. + """ + 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 GenerateCodeChoice(TypedDict): + code: NotRequired[str] + """ + Code response. + """ + + +class GenerateCodeIn(TypedDict): + prompt: NotRequired[str] + """ + Input prompt. + """ + language: NotRequired[ + Literal[ + "c", + "c++", "c#", - "sql", + "css", + "go", + "html", + "java", + "javascript", + "json", + "python", + "r", "ruby", - "tex", "shell", + "sql", + "tex", + "typescript", ] ] """ @@ -246,6 +299,55 @@ class GenerateCodeOut(TypedDict): """ +class MultiGenerateCodeIn(TypedDict): + prompt: NotRequired[str] + """ + Input prompt. + """ + language: NotRequired[ + Literal[ + "c", + "c++", + "c#", + "css", + "go", + "html", + "java", + "javascript", + "json", + "python", + "r", + "ruby", + "shell", + "sql", + "tex", + "typescript", + ] + ] + """ + Language of the code. + """ + num_choices: NotRequired[int] + """ + Number of choices to generate. + """ + 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 MultiGenerateCodeOut(TypedDict): + choices: NotRequired[List[GenerateCodeChoice]] + """ + Code response choices. + """ + + class MultiComputeTextIn(TypedDict): prompt: NotRequired[str] """ @@ -1863,3 +1965,10 @@ class SplitDocumentOut(TypedDict): """ Document chunks """ + + +class DeepseekOut(TypedDict): + choices: NotRequired[List[GenerateCodeChoice]] + """ + Code response choices. + """ From 4edb6921b55ec5a852c37797d17f6540fe492885 Mon Sep 17 00:00:00 2001 From: Chris Sreesangkom Date: Thu, 15 Aug 2024 12:49:36 -0400 Subject: [PATCH 2/2] remove deepseek --- substrate/core/models.py | 53 ----------------------- substrate/future_dataclass_models.py | 63 ---------------------------- substrate/nodes.py | 62 --------------------------- substrate/typeddict_models.py | 49 ---------------------- 4 files changed, 227 deletions(-) diff --git a/substrate/core/models.py b/substrate/core/models.py index 1cfd4cd..170ceac 100644 --- a/substrate/core/models.py +++ b/substrate/core/models.py @@ -242,49 +242,6 @@ class Config: """ -class DeepseekIn(BaseModel): - class Config: - extra = Extra.allow - - prompt: str - """ - Input prompt. - """ - language: Literal[ - "c", - "c++", - "c#", - "css", - "go", - "html", - "java", - "javascript", - "json", - "python", - "r", - "ruby", - "shell", - "sql", - "tex", - "typescript", - ] - """ - Language of the code. - """ - num_choices: Annotated[int, Field(ge=1, le=8)] = 1 - """ - Number of choices to generate. - """ - 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 GenerateCodeChoice(BaseModel): class Config: extra = Extra.allow @@ -2327,13 +2284,3 @@ class Config: """ Document chunks """ - - -class DeepseekOut(BaseModel): - class Config: - extra = Extra.allow - - choices: List[GenerateCodeChoice] - """ - Code response choices. - """ diff --git a/substrate/future_dataclass_models.py b/substrate/future_dataclass_models.py index 9bed3a5..f3f2032 100644 --- a/substrate/future_dataclass_models.py +++ b/substrate/future_dataclass_models.py @@ -301,56 +301,6 @@ class FutureComputeJSONOut: """ -@dataclass -class FutureDeepseekIn: - """ - Future reference to FutureDeepseekIn - """ - - prompt: str - """ - (Future reference) - Input prompt. - """ - language: Literal[ - "c", - "c++", - "c#", - "css", - "go", - "html", - "java", - "javascript", - "json", - "python", - "r", - "ruby", - "shell", - "sql", - "tex", - "typescript", - ] - """ - (Future reference) - Language of the code. - """ - num_choices: int = 1 - """ - (Future reference) - Number of choices to generate. - """ - 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 GenerateCodeChoice: """ @@ -2944,16 +2894,3 @@ class FutureSplitDocumentOut: (Future reference) Document chunks """ - - -@dataclass -class FutureDeepseekOut: - """ - Future reference to FutureDeepseekOut - """ - - choices: List[GenerateCodeChoice] - """ - (Future reference) - Code response choices. - """ diff --git a/substrate/nodes.py b/substrate/nodes.py index ec8add3..27037fa 100644 --- a/substrate/nodes.py +++ b/substrate/nodes.py @@ -323,68 +323,6 @@ def future(self) -> FutureComputeJSONOut: # type: ignore return super().future # type: ignore -class Deepseek(CoreNode[DeepseekOut]): - """https://substrate.run/nodes#Deepseek""" - - def __init__( - self, - prompt: str, - language: Literal[ - "c", - "c++", - "c#", - "css", - "go", - "html", - "java", - "javascript", - "json", - "python", - "r", - "ruby", - "shell", - "sql", - "tex", - "typescript", - ], - num_choices: int = 1, - temperature: Optional[float] = None, - max_tokens: Optional[int] = None, - hide: bool = False, - **kwargs, - ): - """ - Args: - prompt: Input prompt. - language: Language of the code. - num_choices: Number of choices to generate. - 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#Deepseek - """ - super().__init__( - prompt=prompt, - language=language, - num_choices=num_choices, - temperature=temperature, - max_tokens=max_tokens, - hide=hide, - out_type=DeepseekOut, - **kwargs, - ) - self.node = "Deepseek" - - @property - def future(self) -> FutureDeepseekOut: # type: ignore - """ - Future reference to this node's output. - - https://substrate.run/nodes#Deepseek - """ - return super().future # type: ignore - - class GenerateCode(CoreNode[GenerateCodeOut]): """https://substrate.run/nodes#GenerateCode""" diff --git a/substrate/typeddict_models.py b/substrate/typeddict_models.py index 1b7896e..71e57eb 100644 --- a/substrate/typeddict_models.py +++ b/substrate/typeddict_models.py @@ -205,48 +205,6 @@ class ComputeJSONOut(TypedDict): """ -class DeepseekIn(TypedDict): - prompt: NotRequired[str] - """ - Input prompt. - """ - language: NotRequired[ - Literal[ - "c", - "c++", - "c#", - "css", - "go", - "html", - "java", - "javascript", - "json", - "python", - "r", - "ruby", - "shell", - "sql", - "tex", - "typescript", - ] - ] - """ - Language of the code. - """ - num_choices: NotRequired[int] - """ - Number of choices to generate. - """ - 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 GenerateCodeChoice(TypedDict): code: NotRequired[str] """ @@ -1965,10 +1923,3 @@ class SplitDocumentOut(TypedDict): """ Document chunks """ - - -class DeepseekOut(TypedDict): - choices: NotRequired[List[GenerateCodeChoice]] - """ - Code response choices. - """