AnesKAM commited on
Commit
aa3cbc4
·
verified ·
1 Parent(s): 39cf21e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +51 -132
index.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Dual Mode AI</title>
7
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
8
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
9
 
@@ -64,35 +64,17 @@
64
  .mode-btn.active.fast { background: var(--fast); color: white; }
65
  .mode-btn.active.think { background: var(--think); color: white; }
66
 
67
- .mode-info {
68
  font-size: 12px;
69
- line-height: 1.6;
70
  padding: 12px;
71
  border-radius: 8px;
72
  margin-bottom: 20px;
73
  }
74
-
75
- .mode-info.fast { background: rgba(35,134,54,0.1); border: 1px solid var(--fast); }
76
- .mode-info.think { background: rgba(163,113,247,0.1); border: 1px solid var(--think); }
77
-
78
- .status-badge {
79
- display: inline-block;
80
- font-size: 10px;
81
- padding: 2px 6px;
82
- border-radius: 4px;
83
- margin-right: 6px;
84
- }
85
- .status-badge.ready { background: var(--fast); color: white; }
86
- .status-badge.loading { background: #d29922; color: black; }
87
- .status-badge.error { background: #f85149; color: white; }
88
-
89
- .chat-container {
90
- flex: 1;
91
- display: flex;
92
- flex-direction: column;
93
- position: relative;
94
- }
95
 
 
 
96
  #chat-flow {
97
  flex: 1;
98
  padding: 40px 15% 120px;
@@ -109,7 +91,10 @@
109
  animation: fadeIn 0.3s ease;
110
  }
111
 
112
- @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
 
 
 
113
 
114
  .message.user { align-self: flex-end; flex-direction: row-reverse; }
115
  .message.ai { align-self: flex-start; }
@@ -119,7 +104,6 @@
119
  display: flex; align-items: center; justify-content: center;
120
  flex-shrink: 0;
121
  }
122
-
123
  .message.fast .avatar { background: var(--fast); color: white; }
124
  .message.think .avatar { background: var(--think); color: white; }
125
 
@@ -133,16 +117,14 @@
133
  padding: 16px; border-radius: 12px; line-height: 1.6;
134
  border: 1px solid var(--border); word-wrap: break-word;
135
  }
136
-
137
  .user .bubble { background: #21262d; }
138
- .ai.fast .bubble { border-color: rgba(35,134,54,0.3); }
139
- .ai.think .bubble { border-color: rgba(163,113,247,0.3); }
140
 
141
  .thinking-indicator {
142
  display: flex; align-items: center; gap: 8px;
143
  color: var(--think); font-size: 13px; margin-bottom: 8px;
144
  }
145
-
146
  .thinking-indicator i { animation: spin 1s linear infinite; }
147
  @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
148
 
@@ -166,23 +148,11 @@
166
 
167
  .send-btn {
168
  width: 36px; height: 36px; border-radius: 6px;
169
- border: none; cursor: pointer; color: white;
170
- transition: 0.2s;
171
  }
172
-
173
  .send-btn.fast { background: var(--fast); }
174
  .send-btn.think { background: var(--think); }
175
  .send-btn:disabled { background: #30363d !important; cursor: not-allowed; }
176
-
177
- .error-box {
178
- background: rgba(248,81,73,0.1);
179
- border: 1px solid #f85149;
180
- color: #f85149;
181
- padding: 8px 12px;
182
- border-radius: 6px;
183
- font-size: 12px;
184
- margin-top: 8px;
185
- }
186
  </style>
187
  </head>
188
  <body>
@@ -199,17 +169,14 @@
199
  </button>
200
  </div>
201
 
202
- <div class="mode-info fast" id="modeInfo">
203
- <strong>
204
- G4F Mode
205
- <span class="status-badge loading" id="g4fStatus">جاري التحميل...</span>
206
- </strong><br>
207
- مجاني • فوري • بدون API Key<br>
208
- <div id="g4fError"></div>
209
  </div>
210
 
211
  <div style="margin-top: auto; font-size: 11px; color: #8b949e;">
212
- <div id="currentMode">الوضع الحالي: سريع</div>
213
  </div>
214
  </aside>
215
 
@@ -218,87 +185,58 @@
218
  <div class="message ai fast">
219
  <div class="avatar"><i class="fas fa-robot"></i></div>
220
  <div class="bubble">
221
- مرحباً! اختر الوضع المناسب:<br><br>
222
- <strong>الوضع السريع:</strong> ردود فورية مجانية<br>
223
- 🧠 <strong>الوضع المفكر:</strong> تحليل عميق عبر Kimi
 
 
224
  </div>
225
  </div>
226
  </div>
227
 
228
  <div class="input-wrapper">
229
  <input type="text" id="userInput" placeholder="اكتب رسالتك..." autocomplete="off">
230
- <button class="send-btn fast" id="sendBtn" onclick="handleSend()" disabled>
231
  <i class="fas fa-paper-plane"></i>
232
  </button>
233
  </div>
234
  </main>
235
 
 
236
  <script type="module">
237
- // استيراد G4F بشكل صحيح كـ ES Module
238
- let g4fClient = null;
239
- let g4fReady = false;
240
 
241
- // محاولة تحميل G4F
242
- async function initG4F() {
243
- try {
244
- const { createClient } = await import('https://g4f.dev/dist/js/providers.js');
245
- g4fClient = createClient('azure');
246
- g4fReady = true;
247
-
248
- document.getElementById('g4fStatus').textContent = 'جاهز';
249
- document.getElementById('g4fStatus').className = 'status-badge ready';
250
- document.getElementById('sendBtn').disabled = false;
251
-
252
- console.log('✅ G4F Client Ready');
253
- } catch (err) {
254
- console.error('❌ G4F Error:', err);
255
- document.getElementById('g4fStatus').textContent = 'خطأ';
256
- document.getElementById('g4fStatus').className = 'status-badge error';
257
- document.getElementById('g4fError').innerHTML =
258
- `<div class="error-box">فشل تحميل G4F. سيتم استخدام الوضع المفكر فقط.</div>`;
259
-
260
- // تفعيل الوضع المفكر تلقائياً إذا فشل G4F
261
- setMode('think');
262
- document.getElementById('sendBtn').disabled = false;
263
- }
264
- }
265
 
266
  let currentMode = 'fast';
267
-
268
- window.setMode = function(mode) {
269
  currentMode = mode;
270
-
271
  document.querySelectorAll('.mode-btn').forEach(btn => btn.classList.remove('active'));
272
  document.querySelector(`.mode-btn.${mode}`).classList.add('active');
273
 
274
- const info = document.getElementById('modeInfo');
275
  const btn = document.getElementById('sendBtn');
276
- const status = document.getElementById('currentMode');
277
 
278
  if (mode === 'fast') {
279
- info.className = 'mode-info fast';
 
280
  btn.className = 'send-btn fast';
281
- status.textContent = 'الوضع الحالي: سريع (G4F)';
282
-
283
- if (!g4fReady) {
284
- info.innerHTML = `
285
- <strong>G4F Mode</strong>
286
- <span class="status-badge error">غير متوفر</span><br>
287
- فشل الاتصال بـ G4F
288
- `;
289
- }
290
  } else {
291
- info.className = 'mode-info think';
 
292
  btn.className = 'send-btn think';
293
- status.textContent = 'الوضع الحالي: مفكر (Kimi)';
294
  }
295
  };
296
 
297
- window.handleSend = async function() {
298
  const input = document.getElementById('userInput');
299
  const btn = document.getElementById('sendBtn');
300
  const text = input.value.trim();
301
-
302
  if (!text) return;
303
 
304
  addMessage(text, 'user');
@@ -320,29 +258,21 @@
320
  async function sendFast(text) {
321
  const msgId = addMessage('', 'ai', 'fast');
322
  const bubble = document.getElementById(msgId).querySelector('.bubble');
323
-
324
- // التحقق من توفر G4F
325
- if (!g4fReady || !g4fClient) {
326
- bubble.innerHTML = `<span style="color:#f85149">
327
- ⚠️ G4F غير متوفر. <button onclick="setMode('think'); handleSend()" style="background:var(--think);border:none;color:white;padding:4px 8px;border-radius:4px;cursor:pointer;">التبديل للوضع المفكر</button>
328
- </span>`;
329
- return;
330
- }
331
 
332
  try {
333
- bubble.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i> جاري الرد...';
334
-
335
- const result = await g4fClient.chat.completions.create({
336
- model: 'auto',
337
- messages: [{ role: 'user', content: text }]
338
  });
339
 
340
- const content = result.choices[0].message.content;
341
- bubble.innerHTML = marked.parse(content);
342
 
343
  } catch (err) {
344
- console.error('G4F Error:', err);
345
- bubble.innerHTML = `<span style="color:#f85149">خطأ في G4F: ${err.message}. <a href="#" onclick="setMode('think')" style="color:var(--think)">جرب الوضع المفكر</a></span>`;
346
  }
347
  }
348
 
@@ -351,7 +281,6 @@
351
  const msgElement = document.getElementById(msgId);
352
  const bubble = msgElement.querySelector('.bubble');
353
 
354
- // إضافة مؤشر التفكير
355
  msgElement.classList.add('thinking');
356
  const indicator = document.createElement('div');
357
  indicator.className = 'thinking-indicator';
@@ -368,7 +297,6 @@
368
  const reader = res.body.getReader();
369
  const decoder = new TextDecoder();
370
  let fullText = "";
371
- let respondingStarted = false;
372
 
373
  while (true) {
374
  const { done, value } = await reader.read();
@@ -379,31 +307,24 @@
379
 
380
  for (const line of lines) {
381
  if (!line.startsWith('data: ')) continue;
382
-
383
  const data = line.replace('data: ', '').trim();
384
  if (data === '[DONE]') break;
385
 
386
  try {
387
  const json = JSON.parse(data);
388
-
389
- if (json.status === 'responding' && !respondingStarted) {
390
- respondingStarted = true;
391
  indicator.style.display = 'none';
392
  msgElement.classList.remove('thinking');
393
  }
394
-
395
  if (json.content) {
396
  fullText += json.content;
397
  bubble.innerHTML = marked.parse(fullText);
398
- } else if (json.error) {
399
- bubble.innerHTML = `<span style="color:#f85149">خطأ: ${json.error}</span>`;
400
  }
401
  } catch (e) {}
402
  }
403
  }
404
-
405
  } catch (err) {
406
- bubble.innerHTML = `<span style="color:#f85149">فشل الاتصال بالسيرفر: ${err.message}</span>`;
407
  } finally {
408
  indicator.style.display = 'none';
409
  msgElement.classList.remove('thinking');
@@ -431,9 +352,7 @@
431
  document.getElementById('userInput').addEventListener('keypress', (e) => {
432
  if (e.key === 'Enter') window.handleSend();
433
  });
434
-
435
- // ✅ بدء التحميل
436
- initG4F();
437
  </script>
 
438
  </body>
439
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>G4F Literal + Kimi</title>
7
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
8
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
9
 
 
64
  .mode-btn.active.fast { background: var(--fast); color: white; }
65
  .mode-btn.active.think { background: var(--think); color: white; }
66
 
67
+ .model-status {
68
  font-size: 12px;
 
69
  padding: 12px;
70
  border-radius: 8px;
71
  margin-bottom: 20px;
72
  }
73
+ .model-status.fast { background: rgba(35,134,54,0.1); border: 1px solid var(--fast); }
74
+ .model-status.think { background: rgba(163,113,247,0.1); border: 1px solid var(--think); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
+ .chat-container { flex: 1; display: flex; flex-direction: column; position: relative; }
77
+
78
  #chat-flow {
79
  flex: 1;
80
  padding: 40px 15% 120px;
 
91
  animation: fadeIn 0.3s ease;
92
  }
93
 
94
+ @keyframes fadeIn {
95
+ from { opacity: 0; transform: translateY(10px); }
96
+ to { opacity: 1; transform: translateY(0); }
97
+ }
98
 
99
  .message.user { align-self: flex-end; flex-direction: row-reverse; }
100
  .message.ai { align-self: flex-start; }
 
104
  display: flex; align-items: center; justify-content: center;
105
  flex-shrink: 0;
106
  }
 
107
  .message.fast .avatar { background: var(--fast); color: white; }
108
  .message.think .avatar { background: var(--think); color: white; }
109
 
 
117
  padding: 16px; border-radius: 12px; line-height: 1.6;
118
  border: 1px solid var(--border); word-wrap: break-word;
119
  }
 
120
  .user .bubble { background: #21262d; }
121
+ .ai.fast .bubble { border-color: var(--fast); }
122
+ .ai.think .bubble { border-color: var(--think); }
123
 
124
  .thinking-indicator {
125
  display: flex; align-items: center; gap: 8px;
126
  color: var(--think); font-size: 13px; margin-bottom: 8px;
127
  }
 
128
  .thinking-indicator i { animation: spin 1s linear infinite; }
129
  @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
130
 
 
148
 
149
  .send-btn {
150
  width: 36px; height: 36px; border-radius: 6px;
151
+ border: none; cursor: pointer; color: white; transition: 0.2s;
 
152
  }
 
153
  .send-btn.fast { background: var(--fast); }
154
  .send-btn.think { background: var(--think); }
155
  .send-btn:disabled { background: #30363d !important; cursor: not-allowed; }
 
 
 
 
 
 
 
 
 
 
156
  </style>
157
  </head>
158
  <body>
 
169
  </button>
170
  </div>
171
 
172
+ <div class="model-status fast" id="modelStatus">
173
+ <strong>G4F + Pollinations</strong><br>
174
+ createClient("pollinations")<br>
175
+ model: 'openai-fast'
 
 
 
176
  </div>
177
 
178
  <div style="margin-top: auto; font-size: 11px; color: #8b949e;">
179
+ <div id="currentMode">الوضع الحالي: سريع (G4F)</div>
180
  </div>
181
  </aside>
182
 
 
185
  <div class="message ai fast">
186
  <div class="avatar"><i class="fas fa-robot"></i></div>
187
  <div class="bubble">
188
+ مرحباً! النظام يستخدم الكود حرفياً:<br>
189
+ <code style="background:#161b22;padding:4px 8px;border-radius:4px;display:block;margin:8px 0;">
190
+ createClient("pollinations")<br>
191
+ model: 'openai-fast'
192
+ </code>
193
  </div>
194
  </div>
195
  </div>
196
 
197
  <div class="input-wrapper">
198
  <input type="text" id="userInput" placeholder="اكتب رسالتك..." autocomplete="off">
199
+ <button class="send-btn fast" id="sendBtn" onclick="handleSend()">
200
  <i class="fas fa-paper-plane"></i>
201
  </button>
202
  </div>
203
  </main>
204
 
205
+ <!-- ✅✅✅ الكود الحرفي المطلوب ✅✅✅ -->
206
  <script type="module">
207
+ // ========== الكود حرفياً كما طلبت ==========
208
+ import { createClient } from 'https://g4f.dev/dist/js/providers.js';
 
209
 
210
+ const client = createClient("pollinations");
211
+ // ==========================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
 
213
  let currentMode = 'fast';
214
+ window.setMode = (mode) => {
 
215
  currentMode = mode;
 
216
  document.querySelectorAll('.mode-btn').forEach(btn => btn.classList.remove('active'));
217
  document.querySelector(`.mode-btn.${mode}`).classList.add('active');
218
 
219
+ const status = document.getElementById('modelStatus');
220
  const btn = document.getElementById('sendBtn');
221
+ const current = document.getElementById('currentMode');
222
 
223
  if (mode === 'fast') {
224
+ status.className = 'model-status fast';
225
+ status.innerHTML = '<strong>G4F + Pollinations</strong><br>createClient("pollinations")<br>model: \'openai-fast\'';
226
  btn.className = 'send-btn fast';
227
+ current.textContent = 'الوضع الحالي: سريع (G4F)';
 
 
 
 
 
 
 
 
228
  } else {
229
+ status.className = 'model-status think';
230
+ status.innerHTML = '<strong>Kimi K2.5 FW</strong><br>مع تفكير وتحليل عميق';
231
  btn.className = 'send-btn think';
232
+ current.textContent = 'الوضع الحالي: مفكر (Kimi)';
233
  }
234
  };
235
 
236
+ window.handleSend = async () => {
237
  const input = document.getElementById('userInput');
238
  const btn = document.getElementById('sendBtn');
239
  const text = input.value.trim();
 
240
  if (!text) return;
241
 
242
  addMessage(text, 'user');
 
258
  async function sendFast(text) {
259
  const msgId = addMessage('', 'ai', 'fast');
260
  const bubble = document.getElementById(msgId).querySelector('.bubble');
261
+ bubble.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i> جاري الرد...';
 
 
 
 
 
 
 
262
 
263
  try {
264
+ // ✅✅✅ الكود حرفياً مع تمرير النص فقط ✅✅✅
265
+ const result = await client.chat.completions.create({
266
+ model: 'openai-fast',
267
+ messages: [{ role: 'user', content: text }] // text بدلاً من 'Hello!'
 
268
  });
269
 
270
+ // عرض الناتج (console.log الأصلي لا يظهر في الصفحة)
271
+ bubble.innerHTML = marked.parse(result.choices[0].message.content);
272
 
273
  } catch (err) {
274
+ console.error(err);
275
+ bubble.innerHTML = `<span style="color:#f85149">خطأ في G4F: ${err.message}<br>تأكد من الاتصال بالإنترنت</span>`;
276
  }
277
  }
278
 
 
281
  const msgElement = document.getElementById(msgId);
282
  const bubble = msgElement.querySelector('.bubble');
283
 
 
284
  msgElement.classList.add('thinking');
285
  const indicator = document.createElement('div');
286
  indicator.className = 'thinking-indicator';
 
297
  const reader = res.body.getReader();
298
  const decoder = new TextDecoder();
299
  let fullText = "";
 
300
 
301
  while (true) {
302
  const { done, value } = await reader.read();
 
307
 
308
  for (const line of lines) {
309
  if (!line.startsWith('data: ')) continue;
 
310
  const data = line.replace('data: ', '').trim();
311
  if (data === '[DONE]') break;
312
 
313
  try {
314
  const json = JSON.parse(data);
315
+ if (json.status === 'responding') {
 
 
316
  indicator.style.display = 'none';
317
  msgElement.classList.remove('thinking');
318
  }
 
319
  if (json.content) {
320
  fullText += json.content;
321
  bubble.innerHTML = marked.parse(fullText);
 
 
322
  }
323
  } catch (e) {}
324
  }
325
  }
 
326
  } catch (err) {
327
+ bubble.innerHTML = `<span style="color:#f85149">خطأ: ${err.message}</span>`;
328
  } finally {
329
  indicator.style.display = 'none';
330
  msgElement.classList.remove('thinking');
 
352
  document.getElementById('userInput').addEventListener('keypress', (e) => {
353
  if (e.key === 'Enter') window.handleSend();
354
  });
 
 
 
355
  </script>
356
+
357
  </body>
358
  </html>