From 4ea727c703a82ad7fdf2b20537f7169b8d89bfb2 Mon Sep 17 00:00:00 2001 From: bmacer Date: Wed, 11 Dec 2024 16:38:23 -0500 Subject: [PATCH 1/3] improve template arg to accept remote and local json files --- agentstack/proj_templates.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/agentstack/proj_templates.py b/agentstack/proj_templates.py index c96000c5..1687be8e 100644 --- a/agentstack/proj_templates.py +++ b/agentstack/proj_templates.py @@ -47,9 +47,24 @@ class TemplateConfig(pydantic.BaseModel): @classmethod def from_template_name(cls, name: str) -> 'TemplateConfig': + if name.startswith('https://'): + return cls.from_url(name) + if name.endswith('.json'): + path = os.getcwd() / Path(name) + if not path.exists(): + print(term_color(f'Template file does not exist: {path}', 'red')) + sys.exit(1) + return cls.from_json(path) path = get_package_path() / f'templates/proj_templates/{name}.json' - if not os.path.exists(path): # TODO raise exceptions and handle message/exit in cli - print(term_color(f'No known agentstack tool: {name}', 'red')) + if not os.path.exists(path): + print(term_color(f'No known built-in template: {name}', 'red')) + template_names = get_all_template_names() + if not template_names: + print(term_color(f'No built-in templates found at {path}', 'red')) + else: + print(term_color('Available built-in templates:', 'green')) + for template in template_names: + print(term_color(f' {template}', 'green')) sys.exit(1) return cls.from_json(path) From bb1da05ee42662753e1e9ffb0fb68c8b91b596af Mon Sep 17 00:00:00 2001 From: Brandon Macer Date: Wed, 11 Dec 2024 23:53:21 -0500 Subject: [PATCH 2/3] fix so test passes again --- agentstack/proj_templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agentstack/proj_templates.py b/agentstack/proj_templates.py index 853bee7b..5b84a5c6 100644 --- a/agentstack/proj_templates.py +++ b/agentstack/proj_templates.py @@ -91,7 +91,7 @@ def from_template_name(cls, name: str) -> 'TemplateConfig': print(term_color('Available built-in templates:', 'green')) for template in template_names: print(term_color(f' {template}', 'green')) - sys.exit(1) + raise ValidationError(f"Template {name} not found.") return cls.from_json(path) @classmethod From a5cafb59a72fddc914d59030ce21390f842bceca Mon Sep 17 00:00:00 2001 From: Braelyn Boynton Date: Thu, 2 Jan 2025 01:12:51 +0000 Subject: [PATCH 3/3] remove unused imports --- agentstack/proj_templates.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agentstack/proj_templates.py b/agentstack/proj_templates.py index c823b15b..5989c1f6 100644 --- a/agentstack/proj_templates.py +++ b/agentstack/proj_templates.py @@ -1,11 +1,11 @@ -from typing import Optional, Literal +from typing import Literal import os, sys from pathlib import Path import pydantic import requests import json from agentstack.exceptions import ValidationError -from agentstack.utils import get_package_path, term_color, open_json_file +from agentstack.utils import get_package_path class TemplateConfig_v1(pydantic.BaseModel):