(no commit message)
This commit is contained in:
30
agent/utils.py
Normal file
30
agent/utils.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from typing import Dict, Any
|
||||
import re
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
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")
|
||||
|
||||
OPENROUTER_API_BASE = "https://openrouter.ai/api/v1"
|
||||
OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
|
||||
Reference in New Issue
Block a user