File size: 7,431 Bytes
5e0ae28 a43361e 5e0ae28 a43361e 5e0ae28 a43361e 5e0ae28 a43361e 5e0ae28 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 |
"""
Reusable UI components
"""
from src.config.settings import AppConfig
from src.config.constants import ReasoningMode, ModelConfig
from src.core.reasoner import AdvancedReasoner
from src.core.prompt_engine import PromptEngine
from src.utils.logger import logger
class UIComponents:
"""
π¨ REUSABLE UI COMPONENTS
"""
@staticmethod
def get_header_html() -> str:
"""
π GENERATE ENHANCED HEADER HTML
"""
return """
<div class="research-header">
<div class="header-branding">
<div class="logo-section">
<div class="logo-circle">π§ </div>
<div class="brand-text">
<h1>Advanced AI Reasoning System Pro</h1>
<span class="brand-tagline">Next-Generation AI Research Platform</span>
</div>
</div>
<div class="status-indicator">
<span class="status-dot"></span>
<span class="status-text">System Active</span>
</div>
</div>
<div class="header-subtitle">
<p><strong>π Research-Backed Implementation:</strong> Tree of Thoughts + Constitutional AI + Multi-Agent Validation + Performance Optimization</p>
</div>
<div class="feature-badges">
<span class="badge feature-badge">π³ Tree of Thoughts (Yao '23)</span>
<span class="badge feature-badge">π‘οΈ Constitutional AI (Bai '22)</span>
<span class="badge feature-badge">π¬ 6 Reasoning Modes</span>
<span class="badge feature-badge">β‘ Smart Caching + Rate Limiting</span>
<span class="badge feature-badge">ποΈ Dynamic Configuration</span>
<span class="badge feature-badge">π Real-Time Analytics</span>
</div>
</div>
"""
@staticmethod
def get_metrics_html(reasoner: AdvancedReasoner) -> str:
"""
π GENERATE METRICS HTML
"""
m = reasoner.metrics
cache_stats = reasoner.cache.get_stats()
if m.tokens_used > 0:
status = '<span class="status-active">β Active</span>'
else:
status = '<span style="color: #64748b;">β Ready</span>'
return f"""<div class="metrics-card">
<strong>β‘ Inference:</strong> {m.inference_time:.2f}s<br>
<strong>β±οΈ Avg Time:</strong> {m.avg_response_time:.2f}s<br>
<strong>π Speed:</strong> {m.tokens_per_second:.1f} tok/s<br>
<strong>π§ Reasoning:</strong> {m.reasoning_depth} steps<br>
<strong>π Corrections:</strong> {m.self_corrections}<br>
<strong>β¨ Confidence:</strong> {m.confidence_score:.1f}%<br>
<strong>π¬ Total:</strong> {m.total_conversations}<br>
<strong>π Tokens:</strong> {m.tokens_used:,}<br>
<strong>ποΈ Peak:</strong> {m.peak_tokens}<br>
<strong>πΎ Cache:</strong> {cache_stats['hit_rate']}% hit rate<br>
<strong>π‘ Status:</strong> {status}<br>
<strong>π Session:</strong> {reasoner.session_id[:8]}...
</div>"""
@staticmethod
def get_empty_analytics_html() -> str:
"""
π GENERATE ENHANCED EMPTY ANALYTICS HTML
"""
return """
<div class="analytics-panel-welcome">
<div class="analytics-header">
<div class="analytics-icon">π</div>
<div class="analytics-text">
<h3>Analytics Dashboard</h3>
<p class="analytics-subtitle">Performance insights & conversation metrics</p>
</div>
</div>
<div class="analytics-placeholder">
<div class="placeholder-icon">π</div>
<h4>No Data Available Yet</h4>
<p>Start a conversation to begin collecting detailed performance analytics and usage insights.</p>
<div class="metrics-preview">
<div class="metric-item">
<span class="metric-emoji">β‘</span>
<span class="metric-label">Inference Speed</span>
</div>
<div class="metric-item">
<span class="metric-emoji">π§ </span>
<span class="metric-label">Reasoning Depth</span>
</div>
<div class="metric-item">
<span class="metric-emoji">β¨</span>
<span class="metric-label">Confidence Score</span>
</div>
<div class="metric-item">
<span class="metric-emoji">πΎ</span>
<span class="metric-label">Cache Performance</span>
</div>
</div>
<div class="get-started">
<div class="arrow-icon">π</div>
<span>Navigate to the "Reasoning Workspace" tab to get started!</span>
</div>
</div>
</div>"""
@staticmethod
def get_system_info_html(reasoner: AdvancedReasoner) -> str:
"""
βΉοΈ GENERATE SYSTEM INFO HTML
"""
return f"""
**Session ID:** `{reasoner.session_id}`
**Environment:** `{AppConfig.ENV}`
**Cache Size:** {AppConfig.CACHE_SIZE} entries
**Cache TTL:** {AppConfig.CACHE_TTL}s
**Rate Limit:** {AppConfig.RATE_LIMIT_REQUESTS} req/{AppConfig.RATE_LIMIT_WINDOW}s
**Max History:** {AppConfig.MAX_HISTORY_LENGTH} messages
**Available Models:** {len(ModelConfig)} models
**Reasoning Modes:** {len(ReasoningMode)} modes
"""
@staticmethod
def get_settings_table_html() -> str:
"""
βοΈ GENERATE SETTINGS TABLE HTML
"""
return f"""
| Setting | Value |
|---------|-------|
| **Environment** | `{AppConfig.ENV}` |
| **Debug Mode** | `{AppConfig.DEBUG}` |
| **Max History Length** | {AppConfig.MAX_HISTORY_LENGTH} messages |
| **Max Conversation Storage** | {AppConfig.MAX_CONVERSATION_STORAGE} conversations |
| **Cache Size** | {AppConfig.CACHE_SIZE} entries |
| **Cache TTL** | {AppConfig.CACHE_TTL} seconds |
| **Rate Limit** | {AppConfig.RATE_LIMIT_REQUESTS} requests per {AppConfig.RATE_LIMIT_WINDOW}s |
| **Request Timeout** | {AppConfig.REQUEST_TIMEOUT} seconds |
| **Max Retries** | {AppConfig.MAX_RETRIES} attempts |
| **Export Directory** | `{AppConfig.EXPORT_DIR}` |
| **Backup Directory** | `{AppConfig.BACKUP_DIR}` |
| **Available Models** | {len(ModelConfig)} models |
| **Reasoning Modes** | {len(ReasoningMode)} modes |
"""
@staticmethod
def get_reasoning_mode_choices() -> list:
"""Get reasoning mode choices"""
return [mode.value for mode in ReasoningMode]
@staticmethod
def get_prompt_template_choices() -> list:
"""Get prompt template choices"""
return list(PromptEngine.TEMPLATES.keys())
@staticmethod
def get_model_choices() -> list:
"""Get model choices"""
return [m.model_id for m in ModelConfig]
|