From 6e3993d0c29665a37b8751fea36a4842572a4d23 Mon Sep 17 00:00:00 2001 From: Shiven Mian Date: Sat, 17 Feb 2024 14:01:52 -0800 Subject: [PATCH] feat: add function to add steps instead, force task completion --- 01OS/01OS/server/teach.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/01OS/01OS/server/teach.py b/01OS/01OS/server/teach.py index ea9aa8a..78f7a88 100644 --- a/01OS/01OS/server/teach.py +++ b/01OS/01OS/server/teach.py @@ -22,13 +22,19 @@ def to_camel_case(text): camel_case_string = words[0].lower() + ''.join(word.title() for word in words[1:]) return camel_case_string -def generate_python_code(function_name, steps, code): +def generate_python_code(function_name, code): code_string = f'def {to_camel_case(function_name)}():\n' code_string += f' """{function_name}"""\n' indented_code = textwrap.indent(code, ' ') code_string += indented_code + '\n' return code_string +def generate_python_steps(function_name, steps): + code_string = f'def {to_camel_case(function_name)}():\n' + code_string += f' """{function_name}"""\n' + code_string += f' print({steps})\n' + return code_string + def teach(): root = tk.Tk() root.withdraw() @@ -42,6 +48,8 @@ def teach(): break chunk_code = "" + interpreter.computer.languages = [l for l in interpreter.computer.languages if l.name.lower() == "python"] + interpreter.force_task_completion = True for chunk in interpreter.chat(step, stream=True, display=False): if "format" in chunk and chunk["format"] == "execution": content = chunk["content"] @@ -57,7 +65,10 @@ def teach(): skill.steps.append(step) skill.code += chunk_code - python_code = generate_python_code(skill.skill_name, skill.steps, skill.code) + # Uncomment this incase you want steps instead of code + #python_code = generate_python_steps(skill.skill_name, skill.steps) + + python_code = generate_python_code(skill.skill_name, skill.code) SKILLS_DIR = os.path.dirname(__file__) + "/skills" filename = os.path.join(SKILLS_DIR, f"{skill.skill_name.replace(' ', '_')}.py") with open(filename, "w") as file: