CodeInstructionToCodeGenerator
About 233 wordsLess than 1 minute
2025-10-09
CodeInstructionToCodeGenerator is an operator that takes a natural language instruction and uses an LLM to generate a corresponding code snippet. This is often used as a step in a 'self-instruct' style data synthesis pipeline for code.
__init__ function
def __init__(self, llm_serving: LLMServingABC, prompt_template=None)| Parameter | Type | Default | Description |
|---|---|---|---|
| llm_serving | LLMServingABC | Required | Large language model serving instance for inference and generation. |
| prompt_template | PromptABC, str, None | None | Prompt template object. If None, uses CodeInstructionToCodeGeneratorPrompt. If str, uses DiyCodePrompt. |
Prompt Template Descriptions
| Prompt Template Name | Primary Use | Applicable Scenarios | Feature Description |
|---|---|---|---|
run function
def run(self, storage: DataFlowStorage, input_key: str = "instruction", output_key: str = "generated_code")| Name | Type | Default | Description |
|---|---|---|---|
| storage | DataFlowStorage | Required | DataFlow storage instance for reading and writing data. |
| input_key | str | "instruction" | Input column name, corresponding to the natural language instruction field. |
| output_key | str | "generated_code" | Output column name, corresponding to the generated code field. |
🧠 Example Usage
🧾 Default Output Format (Output Format)
| Field | Type | Description |
|---|---|---|
| instruction | str | The input natural language instruction. |
| generated_code | str | The code snippet generated by the model. |
Example Input:
{
"instruction": "Write a Python function to calculate the factorial of a number."
}Example Output:
{
"instruction": "Write a Python function to calculate the factorial of a number.",
"generated_code": "def factorial(n):\n if n == 0:\n return 1\n else:\n return n * factorial(n-1)"
}
