Skip to content

Commit

Permalink
python generate code
Browse files Browse the repository at this point in the history
  • Loading branch information
csreesan committed Aug 15, 2024
1 parent 8ec51fb commit cbb78d4
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 32 deletions.
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
134 changes: 127 additions & 7 deletions substrate/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class Config:
"""


class GenerateCodeIn(BaseModel):
class DeepseekIn(BaseModel):
class Config:
extra = Extra.allow

Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -2217,3 +2327,13 @@ class Config:
"""
Document chunks
"""


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

choices: List[GenerateCodeChoice]
"""
Code response choices.
"""
159 changes: 151 additions & 8 deletions substrate/future_dataclass_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ class FutureComputeJSONOut:


@dataclass
class FutureGenerateCodeIn:
class FutureDeepseekIn:
"""
Future reference to FutureGenerateCodeIn
Future reference to FutureDeepseekIn
"""

prompt: str
Expand All @@ -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)
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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.
"""
Loading

0 comments on commit cbb78d4

Please sign in to comment.