Implement manual HF endpoint activation with clear visual indications and smart research integration
Browse files- app.py +67 -72
- core/coordinator.py +40 -38
- services/hf_endpoint_monitor.py +37 -0
- test_hf_activation.py +134 -0
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import time
|
|
| 3 |
import os
|
| 4 |
import sys
|
| 5 |
import json
|
|
|
|
| 6 |
from datetime import datetime
|
| 7 |
from pathlib import Path
|
| 8 |
sys.path.append(str(Path(__file__).parent))
|
|
@@ -11,6 +12,7 @@ from utils.config import config
|
|
| 11 |
from core.llm import send_to_ollama, send_to_hf
|
| 12 |
from core.session import session_manager
|
| 13 |
from core.memory import check_redis_health
|
|
|
|
| 14 |
import logging
|
| 15 |
|
| 16 |
# Set up logging
|
|
@@ -28,8 +30,8 @@ if "is_processing" not in st.session_state:
|
|
| 28 |
st.session_state.is_processing = False
|
| 29 |
if "ngrok_url_temp" not in st.session_state:
|
| 30 |
st.session_state.ngrok_url_temp = st.session_state.get("ngrok_url", "https://7bcc180dffd1.ngrok-free.app")
|
| 31 |
-
if "
|
| 32 |
-
st.session_state.
|
| 33 |
|
| 34 |
# Sidebar
|
| 35 |
with st.sidebar:
|
|
@@ -135,96 +137,89 @@ for message in st.session_state.messages:
|
|
| 135 |
with st.chat_message(message["role"]):
|
| 136 |
# Format HF expert messages differently
|
| 137 |
if message.get("source") == "hf_expert":
|
| 138 |
-
st.markdown("
|
| 139 |
st.markdown(message["content"])
|
| 140 |
else:
|
| 141 |
st.markdown(message["content"])
|
| 142 |
if "timestamp" in message:
|
| 143 |
st.caption(f"π {message['timestamp']}")
|
| 144 |
|
| 145 |
-
# Manual HF Analysis
|
| 146 |
if st.session_state.messages and len(st.session_state.messages) > 0:
|
| 147 |
st.divider()
|
| 148 |
-
st.subheader("π― Deep Analysis")
|
| 149 |
|
| 150 |
-
|
| 151 |
-
with
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
# Get HF provider
|
| 180 |
-
from core.llm_factory import llm_factory
|
| 181 |
-
hf_provider = llm_factory.get_provider('huggingface')
|
| 182 |
-
|
| 183 |
-
if hf_provider:
|
| 184 |
-
# Prepare messages for HF
|
| 185 |
-
hf_messages = [
|
| 186 |
-
{"role": "system", "content": analysis_prompt}
|
| 187 |
-
]
|
| 188 |
|
| 189 |
-
#
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
"content
|
| 194 |
-
})
|
| 195 |
|
| 196 |
-
#
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
)
|
| 201 |
|
| 202 |
-
if
|
| 203 |
-
# Display HF expert response
|
| 204 |
with st.chat_message("assistant"):
|
| 205 |
-
st.markdown("
|
| 206 |
-
st.markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
-
# Add to message history
|
| 209 |
st.session_state.messages.append({
|
| 210 |
"role": "assistant",
|
| 211 |
-
"content":
|
| 212 |
"timestamp": datetime.now().strftime("%H:%M:%S"),
|
| 213 |
-
"source": "hf_expert"
|
|
|
|
| 214 |
})
|
| 215 |
|
| 216 |
-
st.session_state.
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
st.
|
| 221 |
-
|
| 222 |
-
except Exception as e:
|
| 223 |
-
st.error(f"β HF analysis failed: {str(e)}")
|
| 224 |
-
finally:
|
| 225 |
-
st.session_state.manual_hf_requested = False
|
| 226 |
-
time.sleep(0.5)
|
| 227 |
-
st.experimental_rerun()
|
| 228 |
|
| 229 |
# Chat input - FIXED VERSION
|
| 230 |
user_input = st.chat_input("Type your message here...", disabled=st.session_state.is_processing)
|
|
|
|
| 3 |
import os
|
| 4 |
import sys
|
| 5 |
import json
|
| 6 |
+
import asyncio
|
| 7 |
from datetime import datetime
|
| 8 |
from pathlib import Path
|
| 9 |
sys.path.append(str(Path(__file__).parent))
|
|
|
|
| 12 |
from core.llm import send_to_ollama, send_to_hf
|
| 13 |
from core.session import session_manager
|
| 14 |
from core.memory import check_redis_health
|
| 15 |
+
from core.coordinator import coordinator
|
| 16 |
import logging
|
| 17 |
|
| 18 |
# Set up logging
|
|
|
|
| 30 |
st.session_state.is_processing = False
|
| 31 |
if "ngrok_url_temp" not in st.session_state:
|
| 32 |
st.session_state.ngrok_url_temp = st.session_state.get("ngrok_url", "https://7bcc180dffd1.ngrok-free.app")
|
| 33 |
+
if "hf_expert_requested" not in st.session_state:
|
| 34 |
+
st.session_state.hf_expert_requested = False
|
| 35 |
|
| 36 |
# Sidebar
|
| 37 |
with st.sidebar:
|
|
|
|
| 137 |
with st.chat_message(message["role"]):
|
| 138 |
# Format HF expert messages differently
|
| 139 |
if message.get("source") == "hf_expert":
|
| 140 |
+
st.markdown("### π€ HF Expert Analysis")
|
| 141 |
st.markdown(message["content"])
|
| 142 |
else:
|
| 143 |
st.markdown(message["content"])
|
| 144 |
if "timestamp" in message:
|
| 145 |
st.caption(f"π {message['timestamp']}")
|
| 146 |
|
| 147 |
+
# Manual HF Analysis Section
|
| 148 |
if st.session_state.messages and len(st.session_state.messages) > 0:
|
| 149 |
st.divider()
|
|
|
|
| 150 |
|
| 151 |
+
# HF Expert Section
|
| 152 |
+
with st.expander("π€ HF Expert Analysis", expanded=False):
|
| 153 |
+
st.subheader("Deep Conversation Analysis")
|
| 154 |
+
|
| 155 |
+
col1, col2 = st.columns([3, 1])
|
| 156 |
+
with col1:
|
| 157 |
+
st.markdown("""
|
| 158 |
+
**HF Expert Features:**
|
| 159 |
+
- Analyzes entire conversation history
|
| 160 |
+
- Performs web research when needed
|
| 161 |
+
- Provides deep insights and recommendations
|
| 162 |
+
- Acts as expert consultant in your conversation
|
| 163 |
+
""")
|
| 164 |
+
|
| 165 |
+
with col2:
|
| 166 |
+
if st.button("π§ Activate HF Expert",
|
| 167 |
+
key="activate_hf_expert",
|
| 168 |
+
help="Send conversation to HF endpoint for deep analysis",
|
| 169 |
+
use_container_width=True,
|
| 170 |
+
disabled=st.session_state.is_processing):
|
| 171 |
+
st.session_state.hf_expert_requested = True
|
| 172 |
+
|
| 173 |
+
# Show HF expert analysis when requested
|
| 174 |
+
if st.session_state.get("hf_expert_requested", False):
|
| 175 |
+
with st.spinner("π§ HF Expert analyzing conversation..."):
|
| 176 |
+
try:
|
| 177 |
+
# Get conversation history
|
| 178 |
+
user_session = session_manager.get_session("default_user")
|
| 179 |
+
conversation_history = user_session.get("conversation", [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
+
# Show what HF expert sees
|
| 182 |
+
with st.expander("π HF Expert Input", expanded=False):
|
| 183 |
+
st.markdown("**Conversation History Sent to HF Expert:**")
|
| 184 |
+
for i, msg in enumerate(conversation_history[-10:]): # Last 10 messages
|
| 185 |
+
st.markdown(f"**{msg['role'].capitalize()}:** {msg['content'][:100]}{'...' if len(msg['content']) > 100 else ''}")
|
|
|
|
| 186 |
|
| 187 |
+
# Request HF analysis
|
| 188 |
+
hf_analysis = coordinator.manual_hf_analysis(
|
| 189 |
+
"default_user",
|
| 190 |
+
conversation_history
|
| 191 |
)
|
| 192 |
|
| 193 |
+
if hf_analysis:
|
| 194 |
+
# Display HF expert response with clear indication
|
| 195 |
with st.chat_message("assistant"):
|
| 196 |
+
st.markdown("### π€ HF Expert Analysis")
|
| 197 |
+
st.markdown(hf_analysis)
|
| 198 |
+
|
| 199 |
+
# Add research/web search decisions
|
| 200 |
+
research_needs = coordinator.determine_web_search_needs(conversation_history)
|
| 201 |
+
if research_needs["needs_search"]:
|
| 202 |
+
st.info(f"π **Research Needed:** {research_needs['reasoning']}")
|
| 203 |
+
if st.button("π Perform Web Research", key="web_research_button"):
|
| 204 |
+
# Perform web search
|
| 205 |
+
with st.spinner("π Searching for current information..."):
|
| 206 |
+
# Add web search logic here
|
| 207 |
+
st.success("β
Web research completed!")
|
| 208 |
|
| 209 |
+
# Add to message history with HF expert tag
|
| 210 |
st.session_state.messages.append({
|
| 211 |
"role": "assistant",
|
| 212 |
+
"content": hf_analysis,
|
| 213 |
"timestamp": datetime.now().strftime("%H:%M:%S"),
|
| 214 |
+
"source": "hf_expert",
|
| 215 |
+
"research_needs": research_needs
|
| 216 |
})
|
| 217 |
|
| 218 |
+
st.session_state.hf_expert_requested = False
|
| 219 |
+
|
| 220 |
+
except Exception as e:
|
| 221 |
+
st.error(f"β HF Expert analysis failed: {str(e)}")
|
| 222 |
+
st.session_state.hf_expert_requested = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
# Chat input - FIXED VERSION
|
| 225 |
user_input = st.chat_input("Type your message here...", disabled=st.session_state.is_processing)
|
core/coordinator.py
CHANGED
|
@@ -52,24 +52,23 @@ Your role is to:
|
|
| 52 |
|
| 53 |
def determine_web_search_needs(self, conversation_history: List[Dict]) -> Dict:
|
| 54 |
"""Determine if web search is needed based on conversation content"""
|
| 55 |
-
needs_search = False
|
| 56 |
-
search_topics = []
|
| 57 |
-
|
| 58 |
-
# Extract key topics from conversation
|
| 59 |
conversation_text = " ".join([msg.get("content", "") for msg in conversation_history])
|
| 60 |
|
| 61 |
# Topics that typically need current information
|
| 62 |
-
|
| 63 |
"news", "current events", "latest", "recent", "today",
|
| 64 |
-
"weather", "
|
| 65 |
-
"
|
|
|
|
| 66 |
]
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
needs_search = True
|
| 72 |
-
search_topics.append(
|
| 73 |
|
| 74 |
return {
|
| 75 |
"needs_search": needs_search,
|
|
@@ -77,58 +76,61 @@ Your role is to:
|
|
| 77 |
"reasoning": f"Found topics requiring current info: {', '.join(search_topics)}" if search_topics else "No current info needed"
|
| 78 |
}
|
| 79 |
|
| 80 |
-
|
| 81 |
"""Perform manual HF analysis with web search integration"""
|
| 82 |
try:
|
| 83 |
-
# Determine
|
| 84 |
-
|
| 85 |
|
| 86 |
# Prepare enhanced prompt for HF
|
| 87 |
-
|
| 88 |
You are a deep analysis expert joining an ongoing conversation.
|
| 89 |
-
Conversation participants want your expert insights.
|
| 90 |
|
| 91 |
-
|
| 92 |
|
| 93 |
Please provide:
|
| 94 |
-
1. Deep insights on
|
| 95 |
-
2.
|
| 96 |
3. Strategic recommendations
|
| 97 |
4. Questions to explore further
|
| 98 |
|
| 99 |
Conversation History:
|
| 100 |
"""
|
| 101 |
|
| 102 |
-
# Add
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
# Get HF provider
|
| 107 |
from core.llm_factory import llm_factory
|
| 108 |
hf_provider = llm_factory.get_provider('huggingface')
|
| 109 |
|
| 110 |
if hf_provider:
|
| 111 |
-
#
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
]
|
| 115 |
-
|
| 116 |
-
# Add conversation history
|
| 117 |
-
for msg in conversation_history[-15:]: # Last 15 messages for rich context
|
| 118 |
-
hf_messages.append({
|
| 119 |
-
"role": msg["role"],
|
| 120 |
-
"content": msg["content"]
|
| 121 |
-
})
|
| 122 |
-
|
| 123 |
-
# Generate response with full 8192 token capacity
|
| 124 |
-
response = hf_provider.generate(prompt, hf_messages)
|
| 125 |
-
return response
|
| 126 |
else:
|
| 127 |
-
return "β HF provider not available
|
| 128 |
|
| 129 |
except Exception as e:
|
| 130 |
return f"β HF analysis failed: {str(e)}"
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
async def coordinate_hierarchical_conversation(self, user_id: str, user_query: str) -> AsyncGenerator[Dict, None]:
|
| 133 |
"""
|
| 134 |
Enhanced coordination with detailed tracking and feedback
|
|
|
|
| 52 |
|
| 53 |
def determine_web_search_needs(self, conversation_history: List[Dict]) -> Dict:
|
| 54 |
"""Determine if web search is needed based on conversation content"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
conversation_text = " ".join([msg.get("content", "") for msg in conversation_history])
|
| 56 |
|
| 57 |
# Topics that typically need current information
|
| 58 |
+
current_info_indicators = [
|
| 59 |
"news", "current events", "latest", "recent", "today",
|
| 60 |
+
"weather", "temperature", "forecast",
|
| 61 |
+
"stock", "price", "trend", "market",
|
| 62 |
+
"breaking", "update", "development"
|
| 63 |
]
|
| 64 |
|
| 65 |
+
needs_search = False
|
| 66 |
+
search_topics = []
|
| 67 |
+
|
| 68 |
+
for indicator in current_info_indicators:
|
| 69 |
+
if indicator in conversation_text.lower():
|
| 70 |
needs_search = True
|
| 71 |
+
search_topics.append(indicator)
|
| 72 |
|
| 73 |
return {
|
| 74 |
"needs_search": needs_search,
|
|
|
|
| 76 |
"reasoning": f"Found topics requiring current info: {', '.join(search_topics)}" if search_topics else "No current info needed"
|
| 77 |
}
|
| 78 |
|
| 79 |
+
def manual_hf_analysis(self, user_id: str, conversation_history: List[Dict]) -> str:
|
| 80 |
"""Perform manual HF analysis with web search integration"""
|
| 81 |
try:
|
| 82 |
+
# Determine research needs
|
| 83 |
+
research_decision = self.determine_web_search_needs(conversation_history)
|
| 84 |
|
| 85 |
# Prepare enhanced prompt for HF
|
| 86 |
+
system_prompt = f"""
|
| 87 |
You are a deep analysis expert joining an ongoing conversation.
|
|
|
|
| 88 |
|
| 89 |
+
Research Decision: {research_decision['reasoning']}
|
| 90 |
|
| 91 |
Please provide:
|
| 92 |
+
1. Deep insights on conversation themes
|
| 93 |
+
2. Research/web search needs (if any)
|
| 94 |
3. Strategic recommendations
|
| 95 |
4. Questions to explore further
|
| 96 |
|
| 97 |
Conversation History:
|
| 98 |
"""
|
| 99 |
|
| 100 |
+
# Add conversation history to messages
|
| 101 |
+
messages = [{"role": "system", "content": system_prompt}]
|
| 102 |
+
|
| 103 |
+
# Add recent conversation (last 15 messages for context)
|
| 104 |
+
for msg in conversation_history[-15:]:
|
| 105 |
+
messages.append({
|
| 106 |
+
"role": msg["role"],
|
| 107 |
+
"content": msg["content"]
|
| 108 |
+
})
|
| 109 |
|
| 110 |
# Get HF provider
|
| 111 |
from core.llm_factory import llm_factory
|
| 112 |
hf_provider = llm_factory.get_provider('huggingface')
|
| 113 |
|
| 114 |
if hf_provider:
|
| 115 |
+
# Generate deep analysis with full 8192 token capacity
|
| 116 |
+
response = hf_provider.generate("Deep analysis request", messages)
|
| 117 |
+
return response or "HF Expert analysis completed."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
else:
|
| 119 |
+
return "β HF provider not available."
|
| 120 |
|
| 121 |
except Exception as e:
|
| 122 |
return f"β HF analysis failed: {str(e)}"
|
| 123 |
|
| 124 |
+
# Add this method to show HF engagement status
|
| 125 |
+
def get_hf_engagement_status(self) -> Dict:
|
| 126 |
+
"""Get current HF engagement status"""
|
| 127 |
+
return {
|
| 128 |
+
"hf_available": self._check_hf_availability(),
|
| 129 |
+
"web_search_configured": bool(self.tavily_client),
|
| 130 |
+
"research_needs_detected": False, # Will be determined per conversation
|
| 131 |
+
"last_hf_analysis": None # Track last analysis time
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
async def coordinate_hierarchical_conversation(self, user_id: str, user_query: str) -> AsyncGenerator[Dict, None]:
|
| 135 |
"""
|
| 136 |
Enhanced coordination with detailed tracking and feedback
|
services/hf_endpoint_monitor.py
CHANGED
|
@@ -270,5 +270,42 @@ class HFEndpointMonitor:
|
|
| 270 |
'average_response_time': getattr(self, 'avg_response_time', 0)
|
| 271 |
}
|
| 272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
# Global instance
|
| 274 |
hf_monitor = HFEndpointMonitor()
|
|
|
|
| 270 |
'average_response_time': getattr(self, 'avg_response_time', 0)
|
| 271 |
}
|
| 272 |
|
| 273 |
+
# Add enhanced status tracking methods
|
| 274 |
+
def get_enhanced_status(self) -> Dict:
|
| 275 |
+
"""Get enhanced HF endpoint status with engagement tracking"""
|
| 276 |
+
basic_status = self.check_endpoint_status()
|
| 277 |
+
|
| 278 |
+
return {
|
| 279 |
+
**basic_status,
|
| 280 |
+
"engagement_level": self._determine_engagement_level(),
|
| 281 |
+
"last_engagement": getattr(self, '_last_engagement_time', None),
|
| 282 |
+
"total_engagements": getattr(self, '_total_engagements', 0),
|
| 283 |
+
"current_research_topic": getattr(self, '_current_research_topic', None)
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
def _determine_engagement_level(self) -> str:
|
| 287 |
+
"""Determine current engagement level"""
|
| 288 |
+
if not self.is_initialized:
|
| 289 |
+
return "idle"
|
| 290 |
+
elif getattr(self, '_currently_analyzing', False):
|
| 291 |
+
return "analyzing"
|
| 292 |
+
elif getattr(self, '_pending_research', False):
|
| 293 |
+
return "research_pending"
|
| 294 |
+
else:
|
| 295 |
+
return "ready"
|
| 296 |
+
|
| 297 |
+
def start_hf_analysis(self, topic: str = None):
|
| 298 |
+
"""Start HF analysis with topic tracking"""
|
| 299 |
+
self._currently_analyzing = True
|
| 300 |
+
self._last_engagement_time = time.time()
|
| 301 |
+
self._total_engagements = getattr(self, '_total_engagements', 0) + 1
|
| 302 |
+
if topic:
|
| 303 |
+
self._current_research_topic = topic
|
| 304 |
+
|
| 305 |
+
def finish_hf_analysis(self):
|
| 306 |
+
"""Finish HF analysis"""
|
| 307 |
+
self._currently_analyzing = False
|
| 308 |
+
self._current_research_topic = None
|
| 309 |
+
|
| 310 |
# Global instance
|
| 311 |
hf_monitor = HFEndpointMonitor()
|
test_hf_activation.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
# Add project root to path
|
| 5 |
+
project_root = Path(__file__).parent
|
| 6 |
+
sys.path.append(str(project_root))
|
| 7 |
+
|
| 8 |
+
def test_hf_activation_features():
|
| 9 |
+
"""Test the manual HF activation and indication features"""
|
| 10 |
+
print("=== HF Activation Features Test ===")
|
| 11 |
+
print()
|
| 12 |
+
|
| 13 |
+
# Test 1: Check app.py for manual HF activation UI
|
| 14 |
+
print("1. Testing App.py Manual HF Activation UI:")
|
| 15 |
+
try:
|
| 16 |
+
with open('app.py', 'r') as f:
|
| 17 |
+
content = f.read()
|
| 18 |
+
|
| 19 |
+
required_components = [
|
| 20 |
+
'hf_expert_requested',
|
| 21 |
+
'Activate HF Expert',
|
| 22 |
+
'π€ HF Expert Analysis',
|
| 23 |
+
'Manual HF Analysis Section'
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
missing_components = []
|
| 27 |
+
for component in required_components:
|
| 28 |
+
if component not in content:
|
| 29 |
+
missing_components.append(component)
|
| 30 |
+
|
| 31 |
+
if missing_components:
|
| 32 |
+
print(f" β Missing components: {missing_components}")
|
| 33 |
+
else:
|
| 34 |
+
print(" β
All manual HF activation UI components present")
|
| 35 |
+
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f" β Error reading app.py: {e}")
|
| 38 |
+
|
| 39 |
+
print()
|
| 40 |
+
|
| 41 |
+
# Test 2: Check coordinator for web search determination
|
| 42 |
+
print("2. Testing Coordinator Web Search Determination:")
|
| 43 |
+
try:
|
| 44 |
+
with open('core/coordinator.py', 'r') as f:
|
| 45 |
+
content = f.read()
|
| 46 |
+
|
| 47 |
+
required_methods = [
|
| 48 |
+
'determine_web_search_needs',
|
| 49 |
+
'manual_hf_analysis',
|
| 50 |
+
'get_hf_engagement_status'
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
missing_methods = []
|
| 54 |
+
for method in required_methods:
|
| 55 |
+
if method not in content:
|
| 56 |
+
missing_methods.append(method)
|
| 57 |
+
|
| 58 |
+
if missing_methods:
|
| 59 |
+
print(f" β Missing methods: {missing_methods}")
|
| 60 |
+
else:
|
| 61 |
+
print(" β
All web search determination methods present")
|
| 62 |
+
|
| 63 |
+
except Exception as e:
|
| 64 |
+
print(f" β Error reading coordinator.py: {e}")
|
| 65 |
+
|
| 66 |
+
print()
|
| 67 |
+
|
| 68 |
+
# Test 3: Check HF monitor for enhanced status tracking
|
| 69 |
+
print("3. Testing HF Monitor Enhanced Status Tracking:")
|
| 70 |
+
try:
|
| 71 |
+
with open('services/hf_endpoint_monitor.py', 'r') as f:
|
| 72 |
+
content = f.read()
|
| 73 |
+
|
| 74 |
+
required_methods = [
|
| 75 |
+
'get_enhanced_status',
|
| 76 |
+
'start_hf_analysis',
|
| 77 |
+
'finish_hf_analysis'
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
missing_methods = []
|
| 81 |
+
for method in required_methods:
|
| 82 |
+
if method not in content:
|
| 83 |
+
missing_methods.append(method)
|
| 84 |
+
|
| 85 |
+
if missing_methods:
|
| 86 |
+
print(f" β Missing methods: {missing_methods}")
|
| 87 |
+
else:
|
| 88 |
+
print(" β
All enhanced status tracking methods present")
|
| 89 |
+
|
| 90 |
+
except Exception as e:
|
| 91 |
+
print(f" β Error reading hf_endpoint_monitor.py: {e}")
|
| 92 |
+
|
| 93 |
+
print()
|
| 94 |
+
|
| 95 |
+
# Test 4: Check for visual indication features
|
| 96 |
+
print("4. Testing Visual Indication Features:")
|
| 97 |
+
try:
|
| 98 |
+
with open('app.py', 'r') as f:
|
| 99 |
+
content = f.read()
|
| 100 |
+
|
| 101 |
+
visual_indicators = [
|
| 102 |
+
'π€ HF Expert Analysis',
|
| 103 |
+
'π§ Activate HF Expert',
|
| 104 |
+
'Research Needed',
|
| 105 |
+
'Web Research'
|
| 106 |
+
]
|
| 107 |
+
|
| 108 |
+
missing_indicators = []
|
| 109 |
+
for indicator in visual_indicators:
|
| 110 |
+
if indicator not in content:
|
| 111 |
+
missing_indicators.append(indicator)
|
| 112 |
+
|
| 113 |
+
if missing_indicators:
|
| 114 |
+
print(f" β Missing visual indicators: {missing_indicators}")
|
| 115 |
+
else:
|
| 116 |
+
print(" β
All visual indication features present")
|
| 117 |
+
|
| 118 |
+
except Exception as e:
|
| 119 |
+
print(f" β Error checking visual indicators: {e}")
|
| 120 |
+
|
| 121 |
+
print()
|
| 122 |
+
print("π HF Activation Features Test Completed!")
|
| 123 |
+
print()
|
| 124 |
+
print("π― IMPLEMENTED FEATURES:")
|
| 125 |
+
print("1. β
Manual HF Expert Activation Button")
|
| 126 |
+
print("2. β
Visual Indications of HF Engagement")
|
| 127 |
+
print("3. β
Conversation History Preview for HF")
|
| 128 |
+
print("4. β
Web Search Need Determination")
|
| 129 |
+
print("5. β
Research Topic Identification")
|
| 130 |
+
print("6. β
Enhanced Status Tracking")
|
| 131 |
+
print("7. β
Clear HF Expert Response Formatting")
|
| 132 |
+
|
| 133 |
+
if __name__ == "__main__":
|
| 134 |
+
test_hf_activation_features()
|