1616 ProjectStructure ,
1717 CookiecutterData ,
1818)
19- from agentstack .logger import log
20- from agentstack import conf
19+ from agentstack import conf , log
2120from agentstack .conf import ConfigFile
2221from agentstack .utils import get_package_path
2322from agentstack .generation .files import ProjectFile
@@ -60,14 +59,12 @@ def init_project_builder(
6059 try :
6160 template_data = TemplateConfig .from_url (template )
6261 except Exception as e :
63- print (term_color (f"Failed to fetch template data from { template } .\n { e } " , 'red' ))
64- sys .exit (1 )
62+ raise Exception (f"Failed to fetch template data from { template } .\n { e } " )
6563 else :
6664 try :
6765 template_data = TemplateConfig .from_template_name (template )
6866 except Exception as e :
69- print (term_color (f"Failed to load template { template } .\n { e } " , 'red' ))
70- sys .exit (1 )
67+ raise Exception (f"Failed to load template { template } .\n { e } " )
7168
7269 if template_data :
7370 project_details = {
@@ -118,35 +115,37 @@ def init_project_builder(
118115
119116
120117def welcome_message ():
121- os .system ("cls" if os .name == "nt" else "clear" )
118+ # os.system("cls" if os.name == "nt" else "clear")
122119 title = text2art ("AgentStack" , font = "smisome1" )
123120 tagline = "The easiest way to build a robust agent application!"
124121 border = "-" * len (tagline )
125122
126123 # Print the welcome message with ASCII art
127- print (title )
128- print (border )
129- print (tagline )
130- print (border )
124+ log . info (title )
125+ log . info (border )
126+ log . info (tagline )
127+ log . info (border )
131128
132129
133130def configure_default_model ():
134131 """Set the default model"""
135132 agentstack_config = ConfigFile ()
136133 if agentstack_config .default_model :
134+ log .debug ("Using default model from project config." )
137135 return # Default model already set
138136
139- print ("Project does not have a default model configured." )
137+ log . info ("Project does not have a default model configured." )
140138 other_msg = "Other (enter a model name)"
141139 model = inquirer .list_input (
142140 message = "Which model would you like to use?" ,
143141 choices = PREFERRED_MODELS + [other_msg ],
144142 )
145143
146144 if model == other_msg : # If the user selects "Other", prompt for a model name
147- print ('A list of available models is available at: "https://docs.litellm.ai/docs/providers"' )
145+ log . info ('A list of available models is available at: "https://docs.litellm.ai/docs/providers"' )
148146 model = inquirer .text (message = "Enter the model name" )
149147
148+ log .debug ("Writing default model to project config." )
150149 with ConfigFile () as agentstack_config :
151150 agentstack_config .default_model = model
152151
@@ -172,7 +171,7 @@ def ask_framework() -> str:
172171 # choices=["CrewAI", "Autogen", "LiteLLM"],
173172 # )
174173
175- print ("Congrats! Your project is ready to go! Quickly add features now or skip to do it later.\n \n " )
174+ log . success ("Congrats! Your project is ready to go! Quickly add features now or skip to do it later.\n \n " )
176175
177176 return framework
178177
@@ -192,16 +191,13 @@ def get_validated_input(
192191 snake_case: Whether to enforce snake_case naming
193192 """
194193 while True :
195- try :
196- value = inquirer .text (
197- message = message ,
198- validate = validate_func or validator_not_empty (min_length ) if min_length else None ,
199- )
200- if snake_case and not is_snake_case (value ):
201- raise ValidationError ("Input must be in snake_case" )
202- return value
203- except ValidationError as e :
204- print (term_color (f"Error: { str (e )} " , 'red' ))
194+ value = inquirer .text (
195+ message = message ,
196+ validate = validate_func or validator_not_empty (min_length ) if min_length else None ,
197+ )
198+ if snake_case and not is_snake_case (value ):
199+ raise ValidationError ("Input must be in snake_case" )
200+ return value
205201
206202
207203def ask_agent_details ():
@@ -331,10 +327,10 @@ def ask_tools() -> list:
331327
332328 tools_to_add .append (tool_selection .split (' - ' )[0 ])
333329
334- print ("Adding tools:" )
330+ log . info ("Adding tools:" )
335331 for t in tools_to_add :
336- print (f' - { t } ' )
337- print ('' )
332+ log . info (f' - { t } ' )
333+ log . info ('' )
338334 adding_tools = inquirer .confirm ("Add another tool?" )
339335
340336 return tools_to_add
@@ -344,7 +340,7 @@ def ask_project_details(slug_name: Optional[str] = None) -> dict:
344340 name = inquirer .text (message = "What's the name of your project (snake_case)" , default = slug_name or '' )
345341
346342 if not is_snake_case (name ):
347- print ( term_color ( "Project name must be snake case" , 'red' ) )
343+ log . error ( "Project name must be snake case" )
348344 return ask_project_details (slug_name )
349345
350346 questions = inquirer .prompt (
@@ -404,16 +400,7 @@ def insert_template(
404400 f'{ template_path } /{ "{{cookiecutter.project_metadata.project_slug}}" } /.env.example' ,
405401 f'{ template_path } /{ "{{cookiecutter.project_metadata.project_slug}}" } /.env' ,
406402 )
407-
408- # if os.path.isdir(project_details['name']):
409- # print(
410- # term_color(
411- # f"Directory {template_path} already exists. Please check this and try again",
412- # "red",
413- # )
414- # )
415- # sys.exit(1)
416-
403+
417404 cookiecutter (str (template_path ), no_input = True , extra_context = None )
418405
419406 # TODO: inits a git repo in the directory the command was run in
@@ -434,8 +421,7 @@ def export_template(output_filename: str):
434421 try :
435422 metadata = ProjectFile ()
436423 except Exception as e :
437- print (term_color (f"Failed to load project metadata: { e } " , 'red' ))
438- sys .exit (1 )
424+ raise Exception (f"Failed to load project metadata: { e } " )
439425
440426 # Read all the agents from the project's agents.yaml file
441427 agents : list [TemplateConfig .Agent ] = []
@@ -497,7 +483,6 @@ def export_template(output_filename: str):
497483
498484 try :
499485 template .write_to_file (conf .PATH / output_filename )
500- print ( term_color ( f"Template saved to: { conf .PATH / output_filename } " , 'green' ) )
486+ log . success ( f"Template saved to: { conf .PATH / output_filename } " )
501487 except Exception as e :
502- print (term_color (f"Failed to write template to file: { e } " , 'red' ))
503- sys .exit (1 )
488+ raise Exception (f"Failed to write template to file: { e } " )
0 commit comments