AnesKAM commited on
Commit
ec70e9b
·
verified ·
1 Parent(s): 788582a

Update genisi.js

Browse files
Files changed (1) hide show
  1. genisi.js +42 -24
genisi.js CHANGED
@@ -1,7 +1,7 @@
1
  import express from 'express';
2
  import cors from 'cors';
3
  import { OpenAI } from "openai";
4
- import { Client } from '@gradio/client'; // جديد
5
  import path from 'path';
6
  import { fileURLToPath } from 'url';
7
 
@@ -12,36 +12,54 @@ app.use(cors());
12
  app.use(express.json());
13
  app.use(express.static(__dirname));
14
 
15
- // ✅ الوضع السريع: MiniMax-M2.5-Chat عبر Hugging Face Gradio
16
  app.post('/api/fast', async (req, res) => {
17
  const { message } = req.body;
18
 
19
  try {
20
- // الاتصال بـ Space المحدد
21
- const client = await Client.connect("ostarling/MiniMax-M2.5-Chat");
22
-
23
- // استدعاء الـ API حرفياً كما في الوثائق
24
- const result = await client.predict("/respond", {
25
- message: message,
26
- system_message: "You are a helpful assistant. Your name is MiniMax-M2.5.",
27
- max_tokens: 2048,
28
- temperature: 0.7,
29
- top_p: 0.95
 
 
 
 
 
 
 
30
  });
31
 
32
- // result.data يحتوي على الرد النصي
 
 
 
 
33
  res.json({
34
  success: true,
35
- content: result.data, // الرد من MiniMax
36
- model: "MiniMax-M2.5-Chat"
37
  });
38
 
39
  } catch (err) {
40
- console.error('MiniMax Error:', err);
41
- res.status(500).json({
42
- success: false,
43
- error: "فشل الاتصال بـ MiniMax: " + err.message
44
- });
 
 
 
 
 
 
 
45
  }
46
  });
47
 
@@ -89,11 +107,11 @@ app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'index.html')));
89
  const PORT = process.env.PORT || 7860;
90
  app.listen(PORT, () => {
91
  console.log(`
92
- ✅ Server Ready
93
- -------------------
94
- ⚡ Fast: MiniMax-M2.5-Chat (HF Gradio)
95
  🧠 Think: Kimi K2.5 FW (Poe API)
96
  Port: ${PORT}
97
- -------------------
98
  `);
99
  });
 
1
  import express from 'express';
2
  import cors from 'cors';
3
  import { OpenAI } from "openai";
4
+ import fetch from 'node-fetch'; // أو fetch الأصلي في Node 18+
5
  import path from 'path';
6
  import { fileURLToPath } from 'url';
7
 
 
12
  app.use(express.json());
13
  app.use(express.static(__dirname));
14
 
15
+ // ✅ الوضع السريع: MiniMax عبر Hugging Face Inference API (بدون @gradio/client)
16
  app.post('/api/fast', async (req, res) => {
17
  const { message } = req.body;
18
 
19
  try {
20
+ // استدعاء مباشر لـ Hugging Face Space API
21
+ const response = await fetch('https://ostarling-minimax-m2-5-chat.hf.space/api/predict', {
22
+ method: 'POST',
23
+ headers: {
24
+ 'Content-Type': 'application/json',
25
+ // إذا احتجت token لاحقاً: 'Authorization': 'Bearer hf_...'
26
+ },
27
+ body: JSON.stringify({
28
+ fn_index: 0, // عادةً 0 للدالة الأولى
29
+ data: [
30
+ message, // message
31
+ "You are a helpful assistant.", // system_message
32
+ 2048, // max_tokens
33
+ 0.7, // temperature
34
+ 0.95 // top_p
35
+ ]
36
+ })
37
  });
38
 
39
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
40
+
41
+ const result = await response.json();
42
+ // result.data يحتوي على الرد
43
+
44
  res.json({
45
  success: true,
46
+ content: result.data?.[0] || result.data || "لا يوجد رد",
47
+ model: "MiniMax-M2.5-Chat (HF)"
48
  });
49
 
50
  } catch (err) {
51
+ console.error('HF Error:', err);
52
+ // fallback: استخدام pollinations مباشرة
53
+ try {
54
+ const pollRes = await fetch('https://text.pollinations.ai/' + encodeURIComponent(message));
55
+ const text = await pollRes.text();
56
+ res.json({ success: true, content: text, model: "Pollinations (Fallback)" });
57
+ } catch (pollErr) {
58
+ res.status(500).json({
59
+ success: false,
60
+ error: "فشل الاتصال: " + err.message
61
+ });
62
+ }
63
  }
64
  });
65
 
 
107
  const PORT = process.env.PORT || 7860;
108
  app.listen(PORT, () => {
109
  console.log(`
110
+ ✅ Server Ready (No @gradio/client needed)
111
+ -------------------------------------------
112
+ ⚡ Fast: MiniMax (HF API) or Pollinations
113
  🧠 Think: Kimi K2.5 FW (Poe API)
114
  Port: ${PORT}
115
+ -------------------------------------------
116
  `);
117
  });