Spaces:
Sleeping
Sleeping
Update Index.html
Browse files- Index.html +203 -285
Index.html
CHANGED
|
@@ -1,303 +1,221 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
import json
|
| 5 |
-
import time
|
| 6 |
-
from huggingface_hub import InferenceClient
|
| 7 |
-
|
| 8 |
-
# Load tokens securely
|
| 9 |
-
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 10 |
-
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")
|
| 11 |
-
|
| 12 |
-
class AdvancedDeepSeekAssistant:
|
| 13 |
-
def __init__(self):
|
| 14 |
-
self.hf_client = InferenceClient(token=HF_TOKEN)
|
| 15 |
-
self.deepseek_api_key = DEEPSEEK_API_KEY
|
| 16 |
-
self.conversation_history = []
|
| 17 |
-
|
| 18 |
-
def query_deepseek_advanced(self, message, use_advanced=True):
|
| 19 |
-
"""Enhanced DeepSeek query with full API access"""
|
| 20 |
-
try:
|
| 21 |
-
if use_advanced and self.deepseek_api_key:
|
| 22 |
-
# Use official DeepSeek API with full capabilities
|
| 23 |
-
headers = {
|
| 24 |
-
"Authorization": f"Bearer {self.deepseek_api_key}",
|
| 25 |
-
"Content-Type": "application/json"
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
# Build conversation context
|
| 29 |
-
messages = [
|
| 30 |
-
{
|
| 31 |
-
"role": "system",
|
| 32 |
-
"content": """You are DeepSeek AI, a Pi Network and blockchain expert integrated into PiForge.
|
| 33 |
-
|
| 34 |
-
SPECIAL CAPABILITIES:
|
| 35 |
-
- Pi Network mining optimization
|
| 36 |
-
- Ethical scoring algorithms
|
| 37 |
-
- Smart contract development
|
| 38 |
-
- Blockchain architecture
|
| 39 |
-
- SDK integration guidance
|
| 40 |
-
- Community building strategies
|
| 41 |
-
|
| 42 |
-
Provide detailed, actionable advice. You can write code, analyze projects, and suggest improvements."""
|
| 43 |
-
}
|
| 44 |
-
]
|
| 45 |
-
|
| 46 |
-
# Add conversation history for context
|
| 47 |
-
for msg in self.conversation_history[-6:]: # Keep last 6 exchanges
|
| 48 |
-
messages.append(msg)
|
| 49 |
-
|
| 50 |
-
# Add current message
|
| 51 |
-
messages.append({"role": "user", "content": message})
|
| 52 |
-
|
| 53 |
-
payload = {
|
| 54 |
-
"model": "deepseek-chat",
|
| 55 |
-
"messages": messages,
|
| 56 |
-
"max_tokens": 1000,
|
| 57 |
-
"temperature": 0.7,
|
| 58 |
-
"stream": False
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
response = requests.post(
|
| 62 |
-
"https://api.deepseek.com/v1/chat/completions",
|
| 63 |
-
headers=headers,
|
| 64 |
-
json=payload,
|
| 65 |
-
timeout=30
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
if response.status_code == 200:
|
| 69 |
-
result = response.json()
|
| 70 |
-
ai_response = result["choices"][0]["message"]["content"]
|
| 71 |
-
|
| 72 |
-
# Update conversation history
|
| 73 |
-
self.conversation_history.append({"role": "user", "content": message})
|
| 74 |
-
self.conversation_history.append({"role": "assistant", "content": ai_response})
|
| 75 |
-
|
| 76 |
-
return ai_response
|
| 77 |
-
else:
|
| 78 |
-
raise Exception(f"API Error: {response.status_code}")
|
| 79 |
-
|
| 80 |
-
else:
|
| 81 |
-
# Fallback to HF Inference
|
| 82 |
-
return self.query_deepseek_hf(message)
|
| 83 |
-
|
| 84 |
-
except Exception as e:
|
| 85 |
-
print(f"DeepSeek Advanced Error: {e}")
|
| 86 |
-
return self.query_deepseek_hf(message)
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
Provide comprehensive, actionable advice about:
|
| 96 |
-
- Pi Network development and mining
|
| 97 |
-
- Ethical scoring systems
|
| 98 |
-
- Blockchain technology
|
| 99 |
-
- Code examples when relevant
|
| 100 |
-
- Best practices and optimization
|
| 101 |
-
|
| 102 |
-
Answer:"""
|
| 103 |
-
|
| 104 |
-
response = self.hf_client.text_generation(
|
| 105 |
-
prompt,
|
| 106 |
-
model="deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct",
|
| 107 |
-
max_new_tokens=800,
|
| 108 |
-
temperature=0.7,
|
| 109 |
-
do_sample=True
|
| 110 |
-
)
|
| 111 |
-
return response
|
| 112 |
-
except Exception as e:
|
| 113 |
-
return f"🤖 **DeepSeek Assistant**: I'm here to help with Pi Network development! Currently, I can provide guidance on mining optimization, ethical scoring, and app development. (Error: {str(e)})"
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
analysis_prompt = f"""
|
| 118 |
-
Analyze this Pi Network project proposal for ethical scoring:
|
| 119 |
-
|
| 120 |
-
PROPOSAL: {proposal_text}
|
| 121 |
-
|
| 122 |
-
Please evaluate based on:
|
| 123 |
-
1. Transparency and honesty
|
| 124 |
-
2. Community benefit value
|
| 125 |
-
3. Technical feasibility
|
| 126 |
-
4. Long-term sustainability
|
| 127 |
-
5. Alignment with Pi Network principles
|
| 128 |
-
|
| 129 |
-
Provide:
|
| 130 |
-
- Strengths and weaknesses
|
| 131 |
-
- Specific improvement suggestions
|
| 132 |
-
- Ethical score estimate (0-1000)
|
| 133 |
-
- Resonance level prediction
|
| 134 |
-
|
| 135 |
-
ANALYSIS:
|
| 136 |
-
"""
|
| 137 |
-
|
| 138 |
-
return self.query_deepseek_advanced(analysis_prompt)
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
Please include:
|
| 148 |
-
- Relevant code snippets (JavaScript/Python)
|
| 149 |
-
- Step-by-step implementation guide
|
| 150 |
-
- Best practices and security considerations
|
| 151 |
-
- Common pitfalls to avoid
|
| 152 |
-
|
| 153 |
-
Focus on practical, runnable code examples.
|
| 154 |
-
"""
|
| 155 |
-
|
| 156 |
-
return self.query_deepseek_advanced(code_prompt)
|
| 157 |
-
|
| 158 |
-
# Initialize advanced assistant
|
| 159 |
-
advanced_assistant = AdvancedDeepSeekAssistant()
|
| 160 |
-
|
| 161 |
-
def ethical_audit_with_ai_analysis(proposal_text, deep_analysis=False):
|
| 162 |
-
"""Enhanced ethical audit with AI analysis"""
|
| 163 |
-
# Basic scoring
|
| 164 |
-
base_score = min(1000, max(600, len(proposal_text) * 2))
|
| 165 |
-
resonance = (base_score * 0.7 + 80 * 3) // 10
|
| 166 |
-
boost = 15 if resonance >= 691 else 0
|
| 167 |
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
"
|
| 171 |
-
"
|
| 172 |
-
|
| 173 |
-
}
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
def chat_with_deepseek_advanced(message, history, use_advanced=True):
|
| 185 |
-
"""Advanced chat with conversation history"""
|
| 186 |
-
response = advanced_assistant.query_deepseek_advanced(message, use_advanced)
|
| 187 |
-
return response
|
| 188 |
-
|
| 189 |
-
# Create enhanced Gradio interface
|
| 190 |
-
with gr.Blocks(theme=gr.themes.Soft(), title="PiForge + DeepSeek Pro") as demo:
|
| 191 |
-
gr.Markdown("""
|
| 192 |
-
# 🔨 PiForge Ethical Dual-Forge
|
| 193 |
-
## 🤖 Powered by DeepSeek AI Pro
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
)
|
| 222 |
-
|
| 223 |
-
def respond(message, chat_history, use_advanced):
|
| 224 |
-
bot_message = chat_with_deepseek_advanced(message, chat_history, use_advanced)
|
| 225 |
-
chat_history.append((message, bot_message))
|
| 226 |
-
return "", chat_history
|
| 227 |
|
| 228 |
-
|
| 229 |
-
advanced_assistant.conversation_history.clear()
|
| 230 |
-
return None
|
| 231 |
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
with gr.Tab("🔍 Advanced Ethical Audit"):
|
| 236 |
-
gr.Markdown("### AI-Powered Project Analysis")
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
info="Get detailed project evaluation from DeepSeek"
|
| 249 |
-
)
|
| 250 |
-
analyze_btn = gr.Button("Run Advanced Analysis", variant="primary")
|
| 251 |
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
-
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
label="DeepSeek Code Assistance",
|
| 276 |
-
show_copy_button=True
|
| 277 |
-
)
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
|
|
|
| 281 |
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!-- Replace your existing AI assistant section with this enhanced version -->
|
| 2 |
+
<div id="ai-assistant" style="display: none; margin-top: 20px; background: rgba(255,255,255,0.1); padding: 20px; border-radius: 10px;">
|
| 3 |
+
<h3>🧠 PiForge AI Pro (DeepSeek Powered)</h3>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
<!-- AI Mode Selector -->
|
| 6 |
+
<div style="margin-bottom: 15px; display: flex; gap: 10px; align-items: center;">
|
| 7 |
+
<label style="font-size: 14px;">
|
| 8 |
+
<input type="checkbox" id="advanced-ai" checked> Advanced AI Mode
|
| 9 |
+
</label>
|
| 10 |
+
<button onclick="clearAIChat()" style="padding: 5px 10px; background: #ff6b35; border: none; border-radius: 3px; color: white; font-size: 12px;">Clear Chat</button>
|
| 11 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
<!-- Enhanced Chat Interface -->
|
| 14 |
+
<div id="chat-messages" style="height: 250px; overflow-y: auto; margin-bottom: 15px; padding: 15px; background: rgba(0,0,0,0.3); border-radius: 8px; border: 1px solid rgba(255,255,255,0.1);"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
<!-- Quick Action Buttons -->
|
| 17 |
+
<div style="display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 15px;">
|
| 18 |
+
<button onclick="quickQuestion('How do I optimize my Pi mining?')" style="padding: 8px 12px; background: rgba(76,175,80,0.3); border: 1px solid #4CAF50; border-radius: 5px; color: white; font-size: 12px;">Mining Help</button>
|
| 19 |
+
<button onclick="quickQuestion('Pi SDK authentication code example')" style="padding: 8px 12px; background: rgba(33,150,243,0.3); border: 1px solid #2196F3; border-radius: 5px; color: white; font-size: 12px;">SDK Code</button>
|
| 20 |
+
<button onclick="quickQuestion('Explain ethical scoring algorithm')" style="padding: 8px 12px; background: rgba(255,107,53,0.3); border: 1px solid #ff6b35; border-radius: 5px; color: white; font-size: 12px;">Ethical Scoring</button>
|
| 21 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
<!-- Input Area -->
|
| 24 |
+
<div style="display: flex; gap: 10px;">
|
| 25 |
+
<input type="text" id="ai-question" placeholder="Ask DeepSeek about Pi development, code, or strategy..." style="flex: 1; padding: 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.3); background: rgba(255,255,255,0.1); color: white;">
|
| 26 |
+
<button onclick="askDeepSeekPro()" style="padding: 12px 20px; background: #2196F3; border: none; border-radius: 8px; color: white; font-weight: bold;">Ask DeepSeek</button>
|
| 27 |
+
</div>
|
|
|
|
| 28 |
|
| 29 |
+
<!-- Status Indicator -->
|
| 30 |
+
<div id="ai-status" style="margin-top: 10px; font-size: 12px; opacity: 0.7;"></div>
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<script>
|
| 34 |
+
// Enhanced AI functionality
|
| 35 |
+
let aiConversationHistory = [];
|
| 36 |
+
|
| 37 |
+
async function askDeepSeekPro() {
|
| 38 |
+
const question = document.getElementById('ai-question').value;
|
| 39 |
+
const chat = document.getElementById('chat-messages');
|
| 40 |
+
const useAdvanced = document.getElementById('advanced-ai').checked;
|
| 41 |
+
const status = document.getElementById('ai-status');
|
| 42 |
|
| 43 |
+
if (!question.trim()) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
// Add user message
|
| 46 |
+
const userMessageId = 'user-' + Date.now();
|
| 47 |
+
chat.innerHTML += `
|
| 48 |
+
<div id="${userMessageId}" style="text-align: right; margin: 15px 0;">
|
| 49 |
+
<div style="display: inline-block; background: rgba(76,175,80,0.3); padding: 10px 15px; border-radius: 15px; max-width: 80%; border: 1px solid rgba(76,175,80,0.5);">
|
| 50 |
+
<b>You:</b> ${question}
|
| 51 |
+
</div>
|
| 52 |
+
</div>
|
| 53 |
+
`;
|
| 54 |
|
| 55 |
+
// Show loading with mode indicator
|
| 56 |
+
const loadingId = 'loading-' + Date.now();
|
| 57 |
+
const modeText = useAdvanced ? 'DeepSeek Pro' : 'Standard AI';
|
| 58 |
+
chat.innerHTML += `
|
| 59 |
+
<div id="${loadingId}" style="text-align: left; margin: 15px 0;">
|
| 60 |
+
<div style="display: inline-block; background: rgba(255,255,255,0.1); padding: 10px 15px; border-radius: 15px; border: 1px dashed rgba(255,255,255,0.3);">
|
| 61 |
+
<i>${modeText} is thinking...</i>
|
| 62 |
+
</div>
|
| 63 |
+
</div>
|
| 64 |
+
`;
|
| 65 |
+
|
| 66 |
+
status.textContent = useAdvanced ? 'Using DeepSeek Pro API...' : 'Using standard AI...';
|
| 67 |
+
chat.scrollTop = chat.scrollHeight;
|
| 68 |
+
|
| 69 |
+
try {
|
| 70 |
+
const response = await fetch('https://onenoly11-piforge.hf.space/run/predict', {
|
| 71 |
+
method: 'POST',
|
| 72 |
+
headers: {
|
| 73 |
+
'Content-Type': 'application/json',
|
| 74 |
+
},
|
| 75 |
+
body: JSON.stringify({
|
| 76 |
+
data: [question, aiConversationHistory, useAdvanced]
|
| 77 |
+
})
|
| 78 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
const data = await response.json();
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
// Remove loading
|
| 83 |
+
document.getElementById(loadingId).remove();
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
// Add AI response
|
| 86 |
+
if (data && data.data && data.data[0]) {
|
| 87 |
+
const aiResponse = data.data[0];
|
| 88 |
+
chat.innerHTML += `
|
| 89 |
+
<div style="text-align: left; margin: 15px 0;">
|
| 90 |
+
<div style="display: inline-block; background: rgba(33,150,243,0.2); padding: 15px; border-radius: 15px; max-width: 85%; border: 1px solid rgba(33,150,243,0.4);">
|
| 91 |
+
<b>🤖 DeepSeek${useAdvanced ? ' Pro' : ''}:</b> ${aiResponse}
|
| 92 |
+
</div>
|
| 93 |
+
</div>
|
| 94 |
+
`;
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
// Update conversation history
|
| 97 |
+
aiConversationHistory.push([question, aiResponse]);
|
| 98 |
+
|
| 99 |
+
status.textContent = `Response received (${modeText})`;
|
| 100 |
+
} else {
|
| 101 |
+
throw new Error('No data received');
|
| 102 |
+
}
|
| 103 |
+
} catch (error) {
|
| 104 |
+
document.getElementById(loadingId).remove();
|
| 105 |
+
chat.innerHTML += `
|
| 106 |
+
<div style="text-align: left; margin: 15px 0;">
|
| 107 |
+
<div style="display: inline-block; background: rgba(255,107,53,0.2); padding: 15px; border-radius: 15px; border: 1px solid rgba(255,107,53,0.4);">
|
| 108 |
+
<b>🤖 DeepSeek:</b> ${getEnhancedFallbackResponse(question)}
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
`;
|
| 112 |
+
status.textContent = 'Using enhanced fallback response';
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
document.getElementById('ai-question').value = '';
|
| 116 |
+
chat.scrollTop = chat.scrollHeight;
|
| 117 |
+
|
| 118 |
+
// Auto-clear status after 3 seconds
|
| 119 |
+
setTimeout(() => {
|
| 120 |
+
status.textContent = 'Ready for questions';
|
| 121 |
+
}, 3000);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function quickQuestion(question) {
|
| 125 |
+
document.getElementById('ai-question').value = question;
|
| 126 |
+
askDeepSeekPro();
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
function clearAIChat() {
|
| 130 |
+
document.getElementById('chat-messages').innerHTML = '';
|
| 131 |
+
aiConversationHistory = [];
|
| 132 |
+
document.getElementById('ai-status').textContent = 'Chat cleared';
|
| 133 |
|
| 134 |
+
// Add welcome message back
|
| 135 |
+
setTimeout(() => {
|
| 136 |
+
showAIAssistant();
|
| 137 |
+
}, 500);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
function getEnhancedFallbackResponse(question) {
|
| 141 |
+
const lowerQ = question.toLowerCase();
|
| 142 |
+
|
| 143 |
+
if (lowerQ.includes('mining') || lowerQ.includes('pi coin')) {
|
| 144 |
+
return `**Pi Mining Optimization:**
|
| 145 |
+
- Mine daily at consistent times
|
| 146 |
+
- Maintain and grow your security circle
|
| 147 |
+
- Use Pi apps like PiForge for bonus rates
|
| 148 |
+
- Engage with the Pi community
|
| 149 |
+
- Stay updated with Pi Network news
|
| 150 |
|
| 151 |
+
Current mining rates adjust based on network participation and lockup commitments.`;
|
| 152 |
+
}
|
| 153 |
+
else if (lowerQ.includes('sdk') || lowerQ.includes('authenticate') || lowerQ.includes('code')) {
|
| 154 |
+
return `**Pi SDK Implementation:**
|
| 155 |
+
\`\`\`javascript
|
| 156 |
+
// Initialize Pi SDK
|
| 157 |
+
await Pi.init({ version: "2.0", sandbox: true });
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
+
// Authenticate user
|
| 160 |
+
const scopes = ['username', 'payments'];
|
| 161 |
+
const authResult = await Pi.authenticate(scopes, onIncompletePaymentFound);
|
| 162 |
|
| 163 |
+
// Create payment
|
| 164 |
+
const payment = await Pi.createPayment({
|
| 165 |
+
amount: 0.1,
|
| 166 |
+
memo: "Example payment",
|
| 167 |
+
metadata: { type: 'boost' }
|
| 168 |
+
});
|
| 169 |
+
\`\`\`
|
| 170 |
+
Always test in sandbox mode first and follow Pi's security guidelines.`;
|
| 171 |
+
}
|
| 172 |
+
else if (lowerQ.includes('ethical') || lowerQ.includes('scoring') || lowerQ.includes('resonance')) {
|
| 173 |
+
return `**Ethical Scoring System:**
|
| 174 |
+
PiForge evaluates projects on multiple dimensions:
|
| 175 |
+
- **Transparency** (25%): Clear goals and open communication
|
| 176 |
+
- **Community Value** (30%): Benefits to Pi ecosystem
|
| 177 |
+
- **Technical Soundness** (20%): Feasible implementation
|
| 178 |
+
- **Sustainability** (25%): Long-term viability
|
| 179 |
+
|
| 180 |
+
Projects scoring 691+ resonance receive 15% mining boosts.`;
|
| 181 |
+
}
|
| 182 |
+
else if (lowerQ.includes('boost') || lowerQ.includes('bonus')) {
|
| 183 |
+
return `**Mining Boost Activation:**
|
| 184 |
+
- Achieve 691+ ethical resonance score
|
| 185 |
+
- Authenticate with Pi Wallet
|
| 186 |
+
- Complete ethical audit process
|
| 187 |
+
- Boost applies for 24 hours
|
| 188 |
+
- Can be reactivated after cooldown
|
| 189 |
|
| 190 |
+
Current boost: +15% mining rate`;
|
| 191 |
+
}
|
| 192 |
+
else {
|
| 193 |
+
return `I can provide detailed help with:
|
| 194 |
+
- **Pi Network Development**: SDK integration, authentication, payments
|
| 195 |
+
- **Mining Strategies**: Optimization, boost activation, best practices
|
| 196 |
+
- **Ethical Scoring**: Algorithm details, resonance calculation, improvements
|
| 197 |
+
- **Technical Implementation**: Code examples, architecture, security
|
| 198 |
|
| 199 |
+
What specific area would you like to explore in detail?`;
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
// Enhanced AI assistant show function
|
| 204 |
+
function showAIAssistant() {
|
| 205 |
+
const aiAssistant = document.getElementById('ai-assistant');
|
| 206 |
+
if (aiAssistant) {
|
| 207 |
+
aiAssistant.style.display = 'block';
|
| 208 |
+
const chat = document.getElementById('chat-messages');
|
| 209 |
+
chat.innerHTML = `
|
| 210 |
+
<div style="text-align: left; margin: 15px 0;">
|
| 211 |
+
<div style="display: inline-block; background: rgba(33,150,243,0.2); padding: 15px; border-radius: 15px; border: 1px solid rgba(33,150,243,0.4);">
|
| 212 |
+
<b>🤖 DeepSeek Pro:</b> Welcome! I'm your advanced AI assistant with full DeepSeek capabilities.
|
| 213 |
+
I can help with Pi Network development, code examples, mining optimization, and ethical scoring algorithms.
|
| 214 |
+
What would you like to explore today?
|
| 215 |
+
</div>
|
| 216 |
+
</div>
|
| 217 |
+
`;
|
| 218 |
+
document.getElementById('ai-status').textContent = 'Advanced AI ready - Full DeepSeek access enabled';
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
</script>
|