From 0dc52430f6eb7e522cd8ba495237d78621a64ab9 Mon Sep 17 00:00:00 2001 From: Farouk Adeleke Date: Wed, 29 Oct 2025 20:38:01 -0400 Subject: [PATCH] (no commit message) --- agent/modules.py | 1 + agent/utils.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 agent/utils.py diff --git a/agent/modules.py b/agent/modules.py index d6e3615..f55f4ff 100644 --- a/agent/modules.py +++ b/agent/modules.py @@ -1,6 +1,7 @@ from enum import Enum from typing import Any, Dict, List, Optional, Literal from pydantic import BaseModel, Field, ValidationError +from .utils import * import dspy diff --git a/agent/utils.py b/agent/utils.py new file mode 100644 index 0000000..d13d469 --- /dev/null +++ b/agent/utils.py @@ -0,0 +1,24 @@ +from typing import Dict, Any +import re + + +def to_snake_case(name: str) -> str: + """Convert PascalCase or camelCase string to snake_case.""" + s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name) + return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower() + + +def save_signature_to_file( + result: Dict[str, Any], output_path: str | None = None +) -> str: + """Save generated signature code to a Python file""" + if not output_path: + signature_name = result.get("signature_name", "generated_signature") + output_path = f"{to_snake_case(signature_name)}.py" + + if result.get("code"): + with open(output_path, "w") as f: + f.write(result["code"]) + return output_path + else: + raise ValueError("No code to save")