better error handling in main if any of error occurs during setup

This commit is contained in:
2025-10-29 23:05:21 +01:00
parent 20f97f6e43
commit e0a58e4873
2 changed files with 29 additions and 22 deletions

View File

@@ -6,27 +6,31 @@ from app.interface import *
if __name__ == "__main__": if __name__ == "__main__":
# =====================
load_dotenv()
configs = AppConfig.load()
# =====================
chat = ChatManager()
gradio = chat.gradio_build_interface()
_app, local_url, share_url = gradio.launch(server_name="0.0.0.0", server_port=configs.port, quiet=True, prevent_thread_lock=True, share=configs.gradio_share)
logging.info(f"UPO AppAI Chat is running on {share_url or local_url}")
try: try:
telegram = TelegramApp() # =====================
telegram.add_miniapp_url(share_url) load_dotenv()
telegram.run() configs = AppConfig.load()
except AssertionError as e: # =====================
chat = ChatManager()
gradio = chat.gradio_build_interface()
_app, local_url, share_url = gradio.launch(server_name="0.0.0.0", server_port=configs.port, quiet=True, prevent_thread_lock=True, share=configs.gradio_share)
logging.info(f"UPO AppAI Chat is running on {share_url or local_url}")
try: try:
logging.warning(f"Telegram bot could not be started: {e}") telegram = TelegramApp()
loop = asyncio.new_event_loop() telegram.add_miniapp_url(share_url)
asyncio.set_event_loop(loop) telegram.run()
loop.run_forever() except AssertionError as e:
except KeyboardInterrupt: try:
logging.info("Shutting down due to KeyboardInterrupt") logging.warning(f"Telegram bot could not be started: {e}")
finally: loop = asyncio.new_event_loop()
gradio.close() asyncio.set_event_loop(loop)
loop.run_forever()
except KeyboardInterrupt:
logging.info("Shutting down due to KeyboardInterrupt")
finally:
gradio.close()
except Exception as e:
logging.error(f"Application failed to start: {e}")

View File

@@ -152,9 +152,12 @@ class AgentsConfigs(BaseModel):
def validate_defaults(self, configs: 'AppConfig') -> None: def validate_defaults(self, configs: 'AppConfig') -> None:
""" """
Validate that the default models and strategy exist in the provided configurations. Validate that the default models and strategy exist in the provided configurations.
If any default is not found, a ValueError is raised.
Args: Args:
models: ModelsConfig instance containing all available models. models: ModelsConfig instance containing all available models.
strategies: list of Strategy instances containing all available strategies. strategies: list of Strategy instances containing all available strategies.
Raises:
ValueError if any default model or strategy is not found.
""" """
try: try:
configs.get_strategy_by_name(self.strategy) configs.get_strategy_by_name(self.strategy)