Skip to content

Iterate Code

IterateCode Singleton

Inputs

Field Type Description
code str The code to iterate over
instruction str The instruction to generate code for
language str The programming language to generate code for

Outputs

Field Type Description
instruction str The original instruction (echoed from input)
language str The programming language used
code str The original code
iterated_code str The improved version of the code
model str The AI model used for generation

Usage

from dria.factory import IterateCode

iterator = IterateCode(
    code="existing_code",
    instruction="Optimize the function",
    language="python"
)

Expected output

{
   "instruction":"Add error handling for empty name input",
   "language":"python",
   "iterated_code":"def greet(name):\n    # Check if the input is not None and strip leading/trailing whitespace characters\n    if name and name.strip():\n        print(\"Hello, \" + name)\n    else:\n        raise ValueError(\\'Name cannot be empty\\')  # Raise an error if the name is empty or contains only spaces",
   "code":"\n    def greet(name):\n        print(\"Hello, \" + name)\n    ",
   "model":"deepseek-coder:6.7b"
}