feat: add code in skill instead of steps

pull/38/head
Shiven Mian 11 months ago
parent 6f540fc07c
commit e366f3825b

@ -7,6 +7,7 @@ from tkinter import messagebox
from ..utils.accumulator import Accumulator
import time
import os
import textwrap
setup_logging()
accumulator = Accumulator()
@ -14,16 +15,18 @@ class Skill:
def __init__(self, name: str):
self.skill_name = name
self.steps = []
self.code = ""
def to_camel_case(text):
words = text.split()
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):
def generate_python_code(function_name, steps, code):
code_string = f'def {to_camel_case(function_name)}():\n'
code_string += f' """{function_name}"""\n'
code_string += f' print({steps})\n'
indented_code = textwrap.indent(code, ' ')
code_string += indented_code + '\n'
return code_string
def teach():
@ -38,11 +41,13 @@ def teach():
if step == "end":
break
chunk_code = ""
for chunk in interpreter.chat(step, stream=True, display=False):
if "format" in chunk and chunk["format"] == "execution":
content = chunk["content"]
language = content["format"]
code = content["content"]
chunk_code += code
interpreter.computer.run(code, language)
time.sleep(0.05)
accumulator.accumulate(chunk)
@ -50,9 +55,9 @@ def teach():
isCorrect = messagebox.askyesno("To Proceed?", "Did I do this step right?")
if isCorrect:
skill.steps.append(step)
skill.code += chunk_code
print(skill.skill_name, skill.steps)
python_code = generate_python_code(skill.skill_name, skill.steps)
python_code = generate_python_code(skill.skill_name, skill.steps, 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:

Loading…
Cancel
Save