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]