Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python multi generate code #52

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion substrate/GEN_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240617.20240814
20240617.20240815
4 changes: 3 additions & 1 deletion substrate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
𐃏 Substrate Python SDK

20240617.20240814
20240617.20240815
"""

from .nodes import (
Expand Down Expand Up @@ -41,6 +41,7 @@
InterpolateFrames,
Llama3Instruct70B,
Mistral7BInstruct,
MultiGenerateCode,
MultiInpaintImage,
SegmentUnderPoint,
MultiGenerateImage,
Expand Down Expand Up @@ -73,6 +74,7 @@
"ComputeJSON",
"MultiComputeJSON",
"GenerateCode",
"MultiGenerateCode",
"Mistral7BInstruct",
"Mixtral8x7BInstruct",
"Llama3Instruct8B",
Expand Down
83 changes: 75 additions & 8 deletions substrate/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ class Config:
"""


class GenerateCodeChoice(BaseModel):
class Config:
extra = Extra.allow

code: str
"""
Code response.
"""


class GenerateCodeIn(BaseModel):
class Config:
extra = Extra.allow
Expand All @@ -251,18 +261,22 @@ class Config:
Input prompt.
"""
language: Literal[
"python",
"java",
"c",
"c++",
"javascript",
"typescript",
"php",
"html",
"c#",
"sql",
"css",
"go",
"html",
"java",
"javascript",
"json",
"python",
"r",
"ruby",
"tex",
"shell",
"sql",
"tex",
"typescript",
]
"""
Language of the code.
Expand All @@ -287,6 +301,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
Expand Down
96 changes: 88 additions & 8 deletions substrate/future_dataclass_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,19 @@ class FutureComputeJSONOut:
"""


@dataclass
class GenerateCodeChoice:
"""
Future reference to GenerateCodeChoice
"""

code: str
"""
(Future reference)
Code response.
"""


@dataclass
class FutureGenerateCodeIn:
"""
Expand All @@ -313,18 +326,22 @@ class FutureGenerateCodeIn:
Input prompt.
"""
language: Literal[
"python",
"java",
"c",
"c++",
"javascript",
"typescript",
"php",
"html",
"c#",
"sql",
"css",
"go",
"html",
"java",
"javascript",
"json",
"python",
"r",
"ruby",
"tex",
"shell",
"sql",
"tex",
"typescript",
]
"""
(Future reference)
Expand Down Expand Up @@ -355,6 +372,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:
"""
Expand Down
84 changes: 76 additions & 8 deletions substrate/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
InterpolateFramesOut,
Llama3Instruct70BOut,
Mistral7BInstructOut,
MultiGenerateCodeOut,
MultiInpaintImageOut,
SegmentUnderPointOut,
MultiGenerateImageOut,
Expand Down Expand Up @@ -102,6 +103,7 @@
FutureInterpolateFramesOut,
FutureLlama3Instruct70BOut,
FutureMistral7BInstructOut,
FutureMultiGenerateCodeOut,
FutureMultiInpaintImageOut,
FutureSegmentUnderPointOut,
FutureMultiGenerateImageOut,
Expand Down Expand Up @@ -328,18 +330,22 @@ def __init__(
self,
prompt: str,
language: Literal[
"python",
"java",
"c",
"c++",
"javascript",
"typescript",
"php",
"html",
"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,
Expand Down Expand Up @@ -376,6 +382,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"""

Expand Down
Loading
Loading