3131from agentstack import generation
3232from agentstack .utils import open_json_file , term_color , is_snake_case
3333from agentstack .update import AGENTSTACK_PACKAGE
34+ from agentstack .proj_templates import TemplateConfig
3435
3536
3637PREFERRED_MODELS = [
@@ -57,45 +58,34 @@ def init_project_builder(
5758
5859 template_data = None
5960 if template is not None :
60- url_start = "https://"
61- if template [: len (url_start )] == url_start :
62- # template is a url
63- response = requests .get (template )
64- if response .status_code == 200 :
65- template_data = response .json ()
66- else :
67- print (
68- term_color (
69- f"Failed to fetch template data from { template } . Status code: { response .status_code } " ,
70- 'red' ,
71- )
72- )
61+ if template .startswith ("https://" ):
62+ try :
63+ template_data = TemplateConfig .from_url (template )
64+ except Exception as e :
65+ print (term_color (f"Failed to fetch template data from { template } " , 'red' ))
7366 sys .exit (1 )
7467 else :
75- with importlib .resources .path (
76- 'agentstack.templates.proj_templates' , f'{ template } .json'
77- ) as template_path :
78- if template_path is None :
79- print (term_color (f"No such template { template } found" , 'red' ))
80- sys .exit (1 )
81- template_data = open_json_file (template_path )
68+ try :
69+ template_data = TemplateConfig .from_template_name (template )
70+ except Exception as e :
71+ print (term_color (f"Failed to load template { template } " , 'red' ))
72+ sys .exit (1 )
8273
8374 if template_data :
8475 project_details = {
85- "name" : slug_name or template_data [ ' name' ] ,
76+ "name" : slug_name or template_data . name ,
8677 "version" : "0.0.1" ,
87- "description" : template_data [ ' description' ] ,
78+ "description" : template_data . description ,
8879 "author" : "Name <Email>" ,
8980 "license" : "MIT" ,
9081 }
91- framework = template_data [ ' framework' ]
82+ framework = template_data . framework
9283 design = {
93- 'agents' : template_data [ ' agents' ] ,
94- 'tasks' : template_data [ ' tasks' ] ,
95- 'inputs' : template_data [ ' inputs' ] ,
84+ 'agents' : template_data . agents ,
85+ 'tasks' : template_data . tasks ,
86+ 'inputs' : template_data . inputs ,
9687 }
97-
98- tools = template_data ['tools' ]
88+ tools = template_data .tools
9989
10090 elif use_wizard :
10191 welcome_message ()
@@ -390,7 +380,7 @@ def insert_template(
390380 project_details : dict ,
391381 framework_name : str ,
392382 design : dict ,
393- template_data : Optional [dict ] = None ,
383+ template_data : Optional [TemplateConfig ] = None ,
394384):
395385 framework = FrameworkData (framework_name .lower ())
396386 project_metadata = ProjectMetadata (
@@ -400,8 +390,8 @@ def insert_template(
400390 version = "0.0.1" ,
401391 license = "MIT" ,
402392 year = datetime .now ().year ,
403- template = template_data [ ' name' ] if template_data else 'none' ,
404- template_version = template_data [ ' template_version' ] if template_data else '0' ,
393+ template = template_data . name if template_data else 'none' ,
394+ template_version = template_data . template_version if template_data else '0' ,
405395 )
406396
407397 project_structure = ProjectStructure ()
0 commit comments