File size: 2,481 Bytes
8fd6d25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
Python Code Generating Wizard
Deterministic, extensible, Codex-compatible
"""

from typing import List

class CodeWizard:
    def __init__(self):
        self.spec = {}

    def ask(self, prompt: str, options: List[str] | None = None) -> str:
        print("\n" + prompt)
        if options:
            for i, opt in enumerate(options, 1):
                print(f"  {i}. {opt}")
            choice = int(input("Select option: ")) - 1
            return options[choice]
        return input("> ")

    def collect_intent(self):
        self.spec["program_type"] = self.ask(
            "What type of program do you want?",
            ["function", "class", "script"]
        )

        self.spec["task"] = self.ask(
            "Describe what the program should do (one sentence):"
        )

        self.spec["inputs"] = self.ask(
            "What inputs does it take? (comma separated, or 'none')"
        )

        self.spec["outputs"] = self.ask(
            "What should it return or produce?"
        )

        self.spec["logic"] = self.ask(
            "Select a logic pattern:",
            ["calculation", "iteration", "condition", "data processing"]
        )

    def generate_code(self) -> str:
        name = "generated_function"

        inputs = self.spec["inputs"]
        params = "" if inputs == "none" else inputs

        body = "    pass\n"

        if self.spec["logic"] == "calculation":
            body = "    result = 0\n    return result\n"
        elif self.spec["logic"] == "iteration":
            body = "    for item in []:\n        pass\n"
        elif self.spec["logic"] == "condition":
            body = "    if True:\n        pass\n"
        elif self.spec["logic"] == "data processing":
            body = "    data = []\n    return data\n"

        if self.spec["program_type"] == "function":
            return f"""def {name}({params}):
    \"\"\"{self.spec['task']}\"\"\"
{body}"""

        if self.spec["program_type"] == "class":
            return f"""class GeneratedClass:
    \"\"\"{self.spec['task']}\"\"\"

    def __init__(self):
        pass
"""

        return f"""# {self.spec['task']}
def main():
{body}

if __name__ == "__main__":
    main()
"""

    def run(self):
        print("🧙 Python Code Generating Wizard")
        self.collect_intent()
        code = self.generate_code()
        print("\n=== GENERATED CODE ===\n")
        print(code)
        return code


if __name__ == "__main__":
    CodeWizard().run()