Dockerfile / core /router.py
kkthakur's picture
Deploy Local Hybrid Engine
b336134
Raw
History Blame Contribute Delete
2.01 kB
"""
Router — maps a validated intent dict to the correct tool function.
Pure dict lookup, zero overhead. Each tool function has the signature:
tool(session_id: str, intent: dict) -> dict
and returns {"message": str, "diff": dict}.
"""
from __future__ import annotations
from typing import Callable, Optional
# Import all tools — they register themselves via TOOL_REGISTRY below
from core.a_to_z.student.update import execute_increase, execute_decrease
from core.a_to_z.student.filter_tool import execute_filter
from core.a_to_z.student.sort_tool import execute_sort
from core.a_to_z.student.aggregate import execute_sum, execute_average, execute_count, execute_min, execute_max
from core.a_to_z.student.column_ops import execute_delete_column, execute_rename_column, execute_add_column, execute_cast_type
from core.a_to_z.business.find_replace import execute_find_replace
from core.a_to_z.business.dedup import execute_remove_duplicates
TOOL_MAP: dict[str, Callable[[str, dict], dict]] = {
# Update
"increase": execute_increase,
"decrease": execute_decrease,
# Filter & Sort
"filter": execute_filter,
"sort_asc": execute_sort,
"sort_desc": execute_sort,
# Aggregate
"sum": execute_sum,
"average": execute_average,
"count": execute_count,
"min": execute_min,
"max": execute_max,
# Column operations
"delete_column": execute_delete_column,
"rename_column": execute_rename_column,
"add_column": execute_add_column,
"cast_type": execute_cast_type,
# Data cleaning
"find_replace": execute_find_replace,
"remove_duplicates": execute_remove_duplicates,
}
def dispatch(session_id: str, intent: dict) -> dict:
"""Route intent to the matching tool. Returns tool's result dict."""
op = intent["operation"]
tool_fn = TOOL_MAP.get(op)
if tool_fn is None:
return {
"message": f"'{op}' operation supported nahi hai",
"diff": {},
}
return tool_fn(session_id, intent)