Skip to content

Commit 978824f

Browse files
authored
Merge pull request #52 from SubstrateLabs/chris/multi-generate-code
python multi generate code
2 parents 8ec51fb + 4edb692 commit 978824f

File tree

6 files changed

+311
-34
lines changed

6 files changed

+311
-34
lines changed

substrate/GEN_VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20240617.20240814
1+
20240617.20240815

substrate/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
𐃏 Substrate Python SDK
33
4-
20240617.20240814
4+
20240617.20240815
55
"""
66

77
from .nodes import (
@@ -41,6 +41,7 @@
4141
InterpolateFrames,
4242
Llama3Instruct70B,
4343
Mistral7BInstruct,
44+
MultiGenerateCode,
4445
MultiInpaintImage,
4546
SegmentUnderPoint,
4647
MultiGenerateImage,
@@ -73,6 +74,7 @@
7374
"ComputeJSON",
7475
"MultiComputeJSON",
7576
"GenerateCode",
77+
"MultiGenerateCode",
7678
"Mistral7BInstruct",
7779
"Mixtral8x7BInstruct",
7880
"Llama3Instruct8B",

substrate/core/models.py

+75-8
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ class Config:
242242
"""
243243

244244

245+
class GenerateCodeChoice(BaseModel):
246+
class Config:
247+
extra = Extra.allow
248+
249+
code: str
250+
"""
251+
Code response.
252+
"""
253+
254+
245255
class GenerateCodeIn(BaseModel):
246256
class Config:
247257
extra = Extra.allow
@@ -251,18 +261,22 @@ class Config:
251261
Input prompt.
252262
"""
253263
language: Literal[
254-
"python",
255-
"java",
264+
"c",
256265
"c++",
257-
"javascript",
258-
"typescript",
259-
"php",
260-
"html",
261266
"c#",
262-
"sql",
267+
"css",
268+
"go",
269+
"html",
270+
"java",
271+
"javascript",
272+
"json",
273+
"python",
274+
"r",
263275
"ruby",
264-
"tex",
265276
"shell",
277+
"sql",
278+
"tex",
279+
"typescript",
266280
]
267281
"""
268282
Language of the code.
@@ -287,6 +301,59 @@ class Config:
287301
"""
288302

289303

304+
class MultiGenerateCodeIn(BaseModel):
305+
class Config:
306+
extra = Extra.allow
307+
308+
prompt: str
309+
"""
310+
Input prompt.
311+
"""
312+
language: Literal[
313+
"c",
314+
"c++",
315+
"c#",
316+
"css",
317+
"go",
318+
"html",
319+
"java",
320+
"javascript",
321+
"json",
322+
"python",
323+
"r",
324+
"ruby",
325+
"shell",
326+
"sql",
327+
"tex",
328+
"typescript",
329+
]
330+
"""
331+
Language of the code.
332+
"""
333+
num_choices: Annotated[int, Field(ge=1, le=8)] = 1
334+
"""
335+
Number of choices to generate.
336+
"""
337+
temperature: Annotated[Optional[float], Field(ge=0.0, le=1.0)] = None
338+
"""
339+
Higher values make the output more random, lower values make the output more deterministic.
340+
"""
341+
max_tokens: Optional[int] = None
342+
"""
343+
Maximum number of tokens to generate.
344+
"""
345+
346+
347+
class MultiGenerateCodeOut(BaseModel):
348+
class Config:
349+
extra = Extra.allow
350+
351+
choices: List[GenerateCodeChoice]
352+
"""
353+
Code response choices.
354+
"""
355+
356+
290357
class MultiComputeTextIn(BaseModel):
291358
class Config:
292359
extra = Extra.allow

substrate/future_dataclass_models.py

+88-8
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,19 @@ class FutureComputeJSONOut:
301301
"""
302302

303303

304+
@dataclass
305+
class GenerateCodeChoice:
306+
"""
307+
Future reference to GenerateCodeChoice
308+
"""
309+
310+
code: str
311+
"""
312+
(Future reference)
313+
Code response.
314+
"""
315+
316+
304317
@dataclass
305318
class FutureGenerateCodeIn:
306319
"""
@@ -313,18 +326,22 @@ class FutureGenerateCodeIn:
313326
Input prompt.
314327
"""
315328
language: Literal[
316-
"python",
317-
"java",
329+
"c",
318330
"c++",
319-
"javascript",
320-
"typescript",
321-
"php",
322-
"html",
323331
"c#",
324-
"sql",
332+
"css",
333+
"go",
334+
"html",
335+
"java",
336+
"javascript",
337+
"json",
338+
"python",
339+
"r",
325340
"ruby",
326-
"tex",
327341
"shell",
342+
"sql",
343+
"tex",
344+
"typescript",
328345
]
329346
"""
330347
(Future reference)
@@ -355,6 +372,69 @@ class FutureGenerateCodeOut:
355372
"""
356373

357374

375+
@dataclass
376+
class FutureMultiGenerateCodeIn:
377+
"""
378+
Future reference to FutureMultiGenerateCodeIn
379+
"""
380+
381+
prompt: str
382+
"""
383+
(Future reference)
384+
Input prompt.
385+
"""
386+
language: Literal[
387+
"c",
388+
"c++",
389+
"c#",
390+
"css",
391+
"go",
392+
"html",
393+
"java",
394+
"javascript",
395+
"json",
396+
"python",
397+
"r",
398+
"ruby",
399+
"shell",
400+
"sql",
401+
"tex",
402+
"typescript",
403+
]
404+
"""
405+
(Future reference)
406+
Language of the code.
407+
"""
408+
num_choices: int = 1
409+
"""
410+
(Future reference)
411+
Number of choices to generate.
412+
"""
413+
temperature: Optional[float] = None
414+
"""
415+
(Future reference)
416+
Higher values make the output more random, lower values make the output more deterministic.
417+
"""
418+
max_tokens: Optional[int] = None
419+
"""
420+
(Future reference)
421+
Maximum number of tokens to generate.
422+
"""
423+
424+
425+
@dataclass
426+
class FutureMultiGenerateCodeOut:
427+
"""
428+
Future reference to FutureMultiGenerateCodeOut
429+
"""
430+
431+
choices: List[GenerateCodeChoice]
432+
"""
433+
(Future reference)
434+
Code response choices.
435+
"""
436+
437+
358438
@dataclass
359439
class FutureMultiComputeTextIn:
360440
"""

substrate/nodes.py

+76-8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
InterpolateFramesOut,
5151
Llama3Instruct70BOut,
5252
Mistral7BInstructOut,
53+
MultiGenerateCodeOut,
5354
MultiInpaintImageOut,
5455
SegmentUnderPointOut,
5556
MultiGenerateImageOut,
@@ -102,6 +103,7 @@
102103
FutureInterpolateFramesOut,
103104
FutureLlama3Instruct70BOut,
104105
FutureMistral7BInstructOut,
106+
FutureMultiGenerateCodeOut,
105107
FutureMultiInpaintImageOut,
106108
FutureSegmentUnderPointOut,
107109
FutureMultiGenerateImageOut,
@@ -328,18 +330,22 @@ def __init__(
328330
self,
329331
prompt: str,
330332
language: Literal[
331-
"python",
332-
"java",
333+
"c",
333334
"c++",
334-
"javascript",
335-
"typescript",
336-
"php",
337-
"html",
338335
"c#",
339-
"sql",
336+
"css",
337+
"go",
338+
"html",
339+
"java",
340+
"javascript",
341+
"json",
342+
"python",
343+
"r",
340344
"ruby",
341-
"tex",
342345
"shell",
346+
"sql",
347+
"tex",
348+
"typescript",
343349
],
344350
temperature: Optional[float] = None,
345351
max_tokens: Optional[int] = None,
@@ -376,6 +382,68 @@ def future(self) -> FutureGenerateCodeOut: # type: ignore
376382
return super().future # type: ignore
377383

378384

385+
class MultiGenerateCode(CoreNode[MultiGenerateCodeOut]):
386+
"""https://substrate.run/nodes#MultiGenerateCode"""
387+
388+
def __init__(
389+
self,
390+
prompt: str,
391+
language: Literal[
392+
"c",
393+
"c++",
394+
"c#",
395+
"css",
396+
"go",
397+
"html",
398+
"java",
399+
"javascript",
400+
"json",
401+
"python",
402+
"r",
403+
"ruby",
404+
"shell",
405+
"sql",
406+
"tex",
407+
"typescript",
408+
],
409+
num_choices: int = 1,
410+
temperature: Optional[float] = None,
411+
max_tokens: Optional[int] = None,
412+
hide: bool = False,
413+
**kwargs,
414+
):
415+
"""
416+
Args:
417+
prompt: Input prompt.
418+
language: Language of the code.
419+
num_choices: Number of choices to generate.
420+
temperature: Higher values make the output more random, lower values make the output more deterministic.
421+
max_tokens: Maximum number of tokens to generate.
422+
423+
https://substrate.run/nodes#MultiGenerateCode
424+
"""
425+
super().__init__(
426+
prompt=prompt,
427+
language=language,
428+
num_choices=num_choices,
429+
temperature=temperature,
430+
max_tokens=max_tokens,
431+
hide=hide,
432+
out_type=MultiGenerateCodeOut,
433+
**kwargs,
434+
)
435+
self.node = "MultiGenerateCode"
436+
437+
@property
438+
def future(self) -> FutureMultiGenerateCodeOut: # type: ignore
439+
"""
440+
Future reference to this node's output.
441+
442+
https://substrate.run/nodes#MultiGenerateCode
443+
"""
444+
return super().future # type: ignore
445+
446+
379447
class MultiComputeText(CoreNode[MultiComputeTextOut]):
380448
"""https://substrate.run/nodes#MultiComputeText"""
381449

0 commit comments

Comments
 (0)