Commit
·
11f308c
1
Parent(s):
d761f8e
Process flow visualizer + key skills [for validation only) V3
Browse files
app.py
CHANGED
|
@@ -768,10 +768,10 @@ async def process_message_async(message: str, history: Optional[List], session_i
|
|
| 768 |
|
| 769 |
return error_history, "", reasoning_data, {}, {}, session_id, ""
|
| 770 |
|
| 771 |
-
def process_message(message: str, history: Optional[List], session_id: Optional[str] = None) -> Tuple[List, str, dict, dict, dict, str, str]:
|
| 772 |
"""
|
| 773 |
Synchronous wrapper for async processing
|
| 774 |
-
Returns (history, empty_string, reasoning_data, performance_data, context_data, session_id, skills_html)
|
| 775 |
"""
|
| 776 |
import asyncio
|
| 777 |
|
|
@@ -784,7 +784,29 @@ def process_message(message: str, history: Optional[List], session_id: Optional[
|
|
| 784 |
loop = asyncio.new_event_loop()
|
| 785 |
asyncio.set_event_loop(loop)
|
| 786 |
result = loop.run_until_complete(process_message_async(message, history, session_id))
|
| 787 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
except Exception as e:
|
| 789 |
logger.error(f"Error in process_message: {e}", exc_info=True)
|
| 790 |
error_history = list(history) if history else []
|
|
@@ -813,7 +835,24 @@ def process_message(message: str, history: Optional[List], session_id: Optional[
|
|
| 813 |
"confidence_calibration": {"overall_confidence": 0.2, "sync_error": True}
|
| 814 |
}
|
| 815 |
|
| 816 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 817 |
|
| 818 |
# Decorate the chat handler with GPU if available
|
| 819 |
if SPACES_GPU_AVAILABLE and GPU is not None:
|
|
@@ -824,10 +863,8 @@ if SPACES_GPU_AVAILABLE and GPU is not None:
|
|
| 824 |
if not session_id:
|
| 825 |
session_id = str(uuid.uuid4())[:8]
|
| 826 |
result = process_message(message, history, session_id)
|
| 827 |
-
#
|
| 828 |
-
|
| 829 |
-
skills_content, skills_visible = _update_skills_display(skills_html)
|
| 830 |
-
return result[0], result[1], result[2], result[3], result[4], result[5], skills_content, gr.update(visible=skills_visible)
|
| 831 |
chat_handler_fn = gpu_chat_handler
|
| 832 |
else:
|
| 833 |
def chat_handler_wrapper(message, history, session_id=None):
|
|
@@ -904,7 +941,7 @@ else:
|
|
| 904 |
if process_flow_available and flow_updates:
|
| 905 |
return (
|
| 906 |
result[0], result[1], result[2], result[3], result[4], result[5],
|
| 907 |
-
skills_content, gr.update(visible=skills_visible),
|
| 908 |
flow_updates.get("flow_display", ""),
|
| 909 |
flow_updates.get("flow_stats", {}),
|
| 910 |
flow_updates.get("performance_metrics", {}),
|
|
@@ -913,7 +950,7 @@ else:
|
|
| 913 |
flow_updates.get("safety_details", {})
|
| 914 |
)
|
| 915 |
else:
|
| 916 |
-
return result
|
| 917 |
chat_handler_fn = chat_handler_wrapper
|
| 918 |
|
| 919 |
# Initialize orchestrator on module load
|
|
|
|
| 768 |
|
| 769 |
return error_history, "", reasoning_data, {}, {}, session_id, ""
|
| 770 |
|
| 771 |
+
def process_message(message: str, history: Optional[List], session_id: Optional[str] = None) -> Tuple[List, str, dict, dict, dict, str, str, str, gr.update, str, dict, dict, dict, dict, dict]:
|
| 772 |
"""
|
| 773 |
Synchronous wrapper for async processing
|
| 774 |
+
Returns (history, empty_string, reasoning_data, performance_data, context_data, session_id, skills_html, skills_content, skills_visible_update, flow_display, flow_stats, performance_metrics, intent_details, synthesis_details, safety_details)
|
| 775 |
"""
|
| 776 |
import asyncio
|
| 777 |
|
|
|
|
| 784 |
loop = asyncio.new_event_loop()
|
| 785 |
asyncio.set_event_loop(loop)
|
| 786 |
result = loop.run_until_complete(process_message_async(message, history, session_id))
|
| 787 |
+
|
| 788 |
+
# Extract skills_html from result and determine visibility
|
| 789 |
+
skills_html = result[6]
|
| 790 |
+
skills_content, skills_visible = _update_skills_display(skills_html)
|
| 791 |
+
|
| 792 |
+
# Return all required outputs (15 total)
|
| 793 |
+
return (
|
| 794 |
+
result[0], # history
|
| 795 |
+
result[1], # empty_string
|
| 796 |
+
result[2], # reasoning_data
|
| 797 |
+
result[3], # performance_data
|
| 798 |
+
result[4], # context_data
|
| 799 |
+
result[5], # session_id
|
| 800 |
+
result[6], # skills_html
|
| 801 |
+
skills_content, # skills_content
|
| 802 |
+
gr.update(visible=skills_visible), # skills_visible_update
|
| 803 |
+
"", # flow_display
|
| 804 |
+
{}, # flow_stats
|
| 805 |
+
{}, # performance_metrics
|
| 806 |
+
{}, # intent_details
|
| 807 |
+
{}, # synthesis_details
|
| 808 |
+
{} # safety_details
|
| 809 |
+
)
|
| 810 |
except Exception as e:
|
| 811 |
logger.error(f"Error in process_message: {e}", exc_info=True)
|
| 812 |
error_history = list(history) if history else []
|
|
|
|
| 835 |
"confidence_calibration": {"overall_confidence": 0.2, "sync_error": True}
|
| 836 |
}
|
| 837 |
|
| 838 |
+
# Return all required outputs for error case
|
| 839 |
+
return (
|
| 840 |
+
error_history, # history
|
| 841 |
+
"", # empty_string
|
| 842 |
+
reasoning_data, # reasoning_data
|
| 843 |
+
{}, # performance_data
|
| 844 |
+
{}, # context_data
|
| 845 |
+
session_id, # session_id
|
| 846 |
+
"", # skills_html
|
| 847 |
+
"", # skills_content
|
| 848 |
+
gr.update(visible=False), # skills_visible_update
|
| 849 |
+
"", # flow_display
|
| 850 |
+
{}, # flow_stats
|
| 851 |
+
{}, # performance_metrics
|
| 852 |
+
{}, # intent_details
|
| 853 |
+
{}, # synthesis_details
|
| 854 |
+
{} # safety_details
|
| 855 |
+
)
|
| 856 |
|
| 857 |
# Decorate the chat handler with GPU if available
|
| 858 |
if SPACES_GPU_AVAILABLE and GPU is not None:
|
|
|
|
| 863 |
if not session_id:
|
| 864 |
session_id = str(uuid.uuid4())[:8]
|
| 865 |
result = process_message(message, history, session_id)
|
| 866 |
+
# Return all 15 values directly
|
| 867 |
+
return result
|
|
|
|
|
|
|
| 868 |
chat_handler_fn = gpu_chat_handler
|
| 869 |
else:
|
| 870 |
def chat_handler_wrapper(message, history, session_id=None):
|
|
|
|
| 941 |
if process_flow_available and flow_updates:
|
| 942 |
return (
|
| 943 |
result[0], result[1], result[2], result[3], result[4], result[5],
|
| 944 |
+
result[6], skills_content, gr.update(visible=skills_visible),
|
| 945 |
flow_updates.get("flow_display", ""),
|
| 946 |
flow_updates.get("flow_stats", {}),
|
| 947 |
flow_updates.get("performance_metrics", {}),
|
|
|
|
| 950 |
flow_updates.get("safety_details", {})
|
| 951 |
)
|
| 952 |
else:
|
| 953 |
+
return result
|
| 954 |
chat_handler_fn = chat_handler_wrapper
|
| 955 |
|
| 956 |
# Initialize orchestrator on module load
|
main.py
CHANGED
|
@@ -18,6 +18,7 @@ try:
|
|
| 18 |
from src.agents.intent_agent import create_intent_agent
|
| 19 |
from src.agents.synthesis_agent import create_synthesis_agent
|
| 20 |
from src.agents.safety_agent import create_safety_agent
|
|
|
|
| 21 |
from src.config import settings
|
| 22 |
from src.llm_router import LLMRouter
|
| 23 |
from src.orchestrator_engine import MVPOrchestrator
|
|
@@ -34,6 +35,7 @@ except ImportError as e:
|
|
| 34 |
create_intent_agent = lambda x: MockComponent()
|
| 35 |
create_synthesis_agent = lambda x: MockComponent()
|
| 36 |
create_safety_agent = lambda x: MockComponent()
|
|
|
|
| 37 |
settings = type('Settings', (), {'hf_token': os.getenv('HF_TOKEN', '')})()
|
| 38 |
LLMRouter = type('MockRouter', (), {'__init__': lambda self, x: None})
|
| 39 |
MVPOrchestrator = type('MockOrchestrator', (), {'__init__': lambda self, x, y, z: None})
|
|
@@ -55,7 +57,8 @@ def initialize_components():
|
|
| 55 |
agents = {
|
| 56 |
'intent_recognition': create_intent_agent(llm_router),
|
| 57 |
'response_synthesis': create_synthesis_agent(llm_router),
|
| 58 |
-
'safety_check': create_safety_agent(llm_router)
|
|
|
|
| 59 |
}
|
| 60 |
components['agents'] = agents
|
| 61 |
|
|
|
|
| 18 |
from src.agents.intent_agent import create_intent_agent
|
| 19 |
from src.agents.synthesis_agent import create_synthesis_agent
|
| 20 |
from src.agents.safety_agent import create_safety_agent
|
| 21 |
+
from src.agents.skills_identification_agent import create_skills_identification_agent
|
| 22 |
from src.config import settings
|
| 23 |
from src.llm_router import LLMRouter
|
| 24 |
from src.orchestrator_engine import MVPOrchestrator
|
|
|
|
| 35 |
create_intent_agent = lambda x: MockComponent()
|
| 36 |
create_synthesis_agent = lambda x: MockComponent()
|
| 37 |
create_safety_agent = lambda x: MockComponent()
|
| 38 |
+
create_skills_identification_agent = lambda x: MockComponent()
|
| 39 |
settings = type('Settings', (), {'hf_token': os.getenv('HF_TOKEN', '')})()
|
| 40 |
LLMRouter = type('MockRouter', (), {'__init__': lambda self, x: None})
|
| 41 |
MVPOrchestrator = type('MockOrchestrator', (), {'__init__': lambda self, x, y, z: None})
|
|
|
|
| 57 |
agents = {
|
| 58 |
'intent_recognition': create_intent_agent(llm_router),
|
| 59 |
'response_synthesis': create_synthesis_agent(llm_router),
|
| 60 |
+
'safety_check': create_safety_agent(llm_router),
|
| 61 |
+
'skills_identification': create_skills_identification_agent(llm_router)
|
| 62 |
}
|
| 63 |
components['agents'] = agents
|
| 64 |
|