Update genisi.js
Browse files
genisi.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import express from 'express';
|
| 2 |
import cors from 'cors';
|
| 3 |
import { OpenAI } from "openai";
|
| 4 |
-
import
|
| 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
|
| 16 |
app.post('/api/fast', async (req, res) => {
|
| 17 |
const { message } = req.body;
|
| 18 |
|
| 19 |
try {
|
| 20 |
-
// ا
|
| 21 |
-
const
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
});
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
res.json({
|
| 34 |
success: true,
|
| 35 |
-
content: result.data
|
| 36 |
-
model: "MiniMax-M2.5-Chat"
|
| 37 |
});
|
| 38 |
|
| 39 |
} catch (err) {
|
| 40 |
-
console.error('
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 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
|
| 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 |
});
|