Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: launch magent-ui when product start #136

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions agentuniverse_product/agentuniverse_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ def start(self, config_path: str = None):
# scan and register the product components
self.__scan_and_register_product(self.__config_container.app_configer)

# TODO difizen initialization
try:
from magent_ui import launch
launch()
except ImportError as e:
raise ImportError(
"Could not start product server provided by magent-ui."
"Please install it with `pip install magent-ui."
)

def __init_product_tables(self):
system_sqldb_wrapper = SQLDBWrapperManager().get_instance_obj('__system_db__')
Expand All @@ -66,10 +73,12 @@ def __init_product_tables(self):
with system_sqldb_wrapper.sql_database._engine.connect() as conn:
# init session db
if not conn.dialect.has_table(conn, SESSION_TABLE_NAME):
SessionORM.metadata.create_all(system_sqldb_wrapper.sql_database._engine)
SessionORM.metadata.create_all(
system_sqldb_wrapper.sql_database._engine)
# init message db
if not conn.dialect.has_table(conn, MESSAGE_TABLE_NAME):
MessageORM.metadata.create_all(system_sqldb_wrapper.sql_database._engine)
MessageORM.metadata.create_all(
system_sqldb_wrapper.sql_database._engine)

def __scan_and_register_product(self, app_configer: AppConfiger):
"""Scan the product component directory and register the product components.
Expand All @@ -92,9 +101,12 @@ def __register(self, product_configer_list: list[ComponentConfiger]):
product_configer_list(list): the product component configer list
"""
for product_configer in product_configer_list:
configer_instance: ProductConfiger = ProductConfiger().load_by_configer(product_configer.configer)
component_clz = ComponentConfigerUtil.get_component_object_clz_by_component_configer(configer_instance)
product_instance: Product = component_clz().initialize_by_component_configer(configer_instance)
configer_instance: ProductConfiger = ProductConfiger(
).load_by_configer(product_configer.configer)
component_clz = ComponentConfigerUtil.get_component_object_clz_by_component_configer(
configer_instance)
product_instance: Product = component_clz(
).initialize_by_component_configer(configer_instance)
if product_instance is None:
continue
product_instance.component_config_path = product_configer.configer.path
Expand Down