RemiFabre
commited on
Commit
Β·
e209e05
1
Parent(s):
57aa732
print->logger on tool and demo init. Added local logging config since the main one is not loaded at import level
Browse files
src/reachy_mini_conversation_app/tools.py
CHANGED
|
@@ -18,6 +18,18 @@ from reachy_mini_conversation_app.config import config # noqa: F401
|
|
| 18 |
|
| 19 |
logger = logging.getLogger(__name__)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Initialize dance and emotion libraries
|
| 22 |
try:
|
| 23 |
from reachy_mini.motion.recorded_move import RecordedMoves
|
|
@@ -461,29 +473,44 @@ def _load_demo_tools() -> None:
|
|
| 461 |
"""Load demo-specific tools if DEMO env variable is set."""
|
| 462 |
demo = os.getenv("DEMO")
|
| 463 |
if not demo:
|
| 464 |
-
|
| 465 |
return
|
| 466 |
try:
|
| 467 |
importlib.import_module(f"demos.{demo}")
|
| 468 |
-
|
| 469 |
except ModuleNotFoundError as e:
|
| 470 |
# Check if the demo module itself is missing or if it's a dependency
|
| 471 |
if e.name == f"demos.{demo}":
|
| 472 |
-
|
| 473 |
sys.exit(1)
|
| 474 |
else:
|
| 475 |
-
|
| 476 |
sys.exit(1)
|
| 477 |
except Exception as e:
|
| 478 |
-
|
| 479 |
sys.exit(1)
|
| 480 |
|
| 481 |
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
ALL_TOOLS
|
| 485 |
-
|
| 486 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 487 |
|
| 488 |
|
| 489 |
def get_tool_specs(exclusion_list : list[str] = []) -> list[Dict[str, Any]]:
|
|
|
|
| 18 |
|
| 19 |
logger = logging.getLogger(__name__)
|
| 20 |
|
| 21 |
+
if not logger.handlers:
|
| 22 |
+
handler = logging.StreamHandler()
|
| 23 |
+
formatter = logging.Formatter("%(asctime)s %(levelname)s %(name)s:%(lineno)d | %(message)s")
|
| 24 |
+
handler.setFormatter(formatter)
|
| 25 |
+
logger.addHandler(handler)
|
| 26 |
+
logger.setLevel(logging.INFO)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
ALL_TOOLS: Dict[str, "Tool"] = {}
|
| 30 |
+
ALL_TOOL_SPECS: List[Dict[str, Any]] = []
|
| 31 |
+
_TOOLS_INITIALIZED = False
|
| 32 |
+
|
| 33 |
# Initialize dance and emotion libraries
|
| 34 |
try:
|
| 35 |
from reachy_mini.motion.recorded_move import RecordedMoves
|
|
|
|
| 473 |
"""Load demo-specific tools if DEMO env variable is set."""
|
| 474 |
demo = os.getenv("DEMO")
|
| 475 |
if not demo:
|
| 476 |
+
logger.info("No DEMO env variable set; using default.")
|
| 477 |
return
|
| 478 |
try:
|
| 479 |
importlib.import_module(f"demos.{demo}")
|
| 480 |
+
logger.info(f"β Demo '{demo}' loaded successfully.")
|
| 481 |
except ModuleNotFoundError as e:
|
| 482 |
# Check if the demo module itself is missing or if it's a dependency
|
| 483 |
if e.name == f"demos.{demo}":
|
| 484 |
+
logger.info(f"β Demo '{demo}' not found in src/demos/")
|
| 485 |
sys.exit(1)
|
| 486 |
else:
|
| 487 |
+
logger.info(f"β Demo '{demo}' failed due to missing dependency: {e.name}")
|
| 488 |
sys.exit(1)
|
| 489 |
except Exception as e:
|
| 490 |
+
logger.info(f"β Failed to load demo '{demo}': {e}")
|
| 491 |
sys.exit(1)
|
| 492 |
|
| 493 |
|
| 494 |
+
def _initialize_tools() -> None:
|
| 495 |
+
"""Populate registry once, even if module is imported repeatedly."""
|
| 496 |
+
global ALL_TOOLS, ALL_TOOL_SPECS, _TOOLS_INITIALIZED
|
| 497 |
+
|
| 498 |
+
if _TOOLS_INITIALIZED:
|
| 499 |
+
logger.debug("Tools already initialized; skipping reinitialization.")
|
| 500 |
+
return
|
| 501 |
+
|
| 502 |
+
_load_demo_tools()
|
| 503 |
+
|
| 504 |
+
ALL_TOOLS = {cls.name: cls() for cls in get_concrete_subclasses(Tool)} # type: ignore[type-abstract]
|
| 505 |
+
ALL_TOOL_SPECS = [tool.spec() for tool in ALL_TOOLS.values()]
|
| 506 |
+
|
| 507 |
+
for tool_name, tool in ALL_TOOLS.items():
|
| 508 |
+
logger.info(f"tool registered: {tool_name} - {tool.description}")
|
| 509 |
+
|
| 510 |
+
_TOOLS_INITIALIZED = True
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
_initialize_tools()
|
| 514 |
|
| 515 |
|
| 516 |
def get_tool_specs(exclusion_list : list[str] = []) -> list[Dict[str, Any]]:
|