|
from pathlib import Path |
|
import subprocess |
|
import sys |
|
|
|
|
|
ROOT_DIR = Path(__file__).resolve().parent.parent |
|
sys.path.insert(0, str(ROOT_DIR)) |
|
|
|
from src.llm_client import prompt_llm |
|
|
|
|
|
prompt_base = ROOT_DIR / "prompts" / "base_instruction.txt" |
|
|
|
GEN_SCRIPT = ROOT_DIR / "generated" / "result_script.py" |
|
RUN_SCRIPT = ROOT_DIR / "src" / "run_freecad.py" |
|
|
|
|
|
GUI_SNIPPET = """ |
|
import FreeCADGui |
|
FreeCADGui.activeDocument().activeView().viewAxometric() |
|
FreeCADGui.SendMsgToActiveView("ViewFit") |
|
""" |
|
|
|
def main(): |
|
|
|
user_input = input("Describe your FreeCAD part: ") |
|
|
|
|
|
base_prompt = prompt_base.read_text(encoding="utf-8").strip() |
|
|
|
full_prompt = f"{base_prompt}\n\nExamples:\n\nUser instruction: {user_input.strip()}" |
|
|
|
|
|
generated_code = prompt_llm(full_prompt) |
|
|
|
|
|
if generated_code.startswith("```"): |
|
generated_code = generated_code.strip("`\n ") |
|
if generated_code.lower().startswith("python"): |
|
generated_code = generated_code[len("python"):].lstrip() |
|
|
|
|
|
generated_code += "\n\n" + GUI_SNIPPET |
|
|
|
|
|
GEN_SCRIPT.write_text(generated_code, encoding="utf-8") |
|
print(f"\n Code generated and written to {GEN_SCRIPT}") |
|
|