Update genisi.js
Browse files
genisi.js
CHANGED
|
@@ -11,10 +11,8 @@ app.use(cors());
|
|
| 11 |
app.use(express.json());
|
| 12 |
app.use(express.static(__dirname));
|
| 13 |
|
| 14 |
-
// ✅
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
app.post('/api/chat', async (req, res) => {
|
| 18 |
const { message } = req.body;
|
| 19 |
const POE_KEY = process.env.POE_API_KEY;
|
| 20 |
|
|
@@ -22,10 +20,8 @@ app.post('/api/chat', async (req, res) => {
|
|
| 22 |
return res.status(401).json({ error: "POE_API_KEY غير موجود" });
|
| 23 |
}
|
| 24 |
|
| 25 |
-
// إعداد Streaming
|
| 26 |
res.setHeader('Content-Type', 'text/event-stream');
|
| 27 |
res.setHeader('Cache-Control', 'no-cache');
|
| 28 |
-
res.setHeader('Connection', 'keep-alive');
|
| 29 |
|
| 30 |
const client = new OpenAI({
|
| 31 |
apiKey: POE_KEY,
|
|
@@ -33,20 +29,20 @@ app.post('/api/chat', async (req, res) => {
|
|
| 33 |
});
|
| 34 |
|
| 35 |
try {
|
|
|
|
|
|
|
|
|
|
| 36 |
const stream = await client.chat.completions.create({
|
| 37 |
-
model:
|
| 38 |
messages: [{ role: "user", content: message }],
|
| 39 |
stream: true,
|
| 40 |
-
temperature: 0.7
|
| 41 |
-
//
|
| 42 |
-
extra_body: {
|
| 43 |
-
reasoning: false,
|
| 44 |
-
thinking_budget: 0,
|
| 45 |
-
reasoning_effort: "none",
|
| 46 |
-
disable_thinking: true // محاولة إضافية خاصة بـ kimi
|
| 47 |
-
}
|
| 48 |
});
|
| 49 |
|
|
|
|
|
|
|
|
|
|
| 50 |
for await (const chunk of stream) {
|
| 51 |
const content = chunk.choices[0]?.delta?.content || "";
|
| 52 |
if (content) {
|
|
@@ -58,11 +54,8 @@ app.post('/api/chat', async (req, res) => {
|
|
| 58 |
res.end();
|
| 59 |
|
| 60 |
} catch (err) {
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
res.write(`data: ${JSON.stringify({ error: err.message })}\n\n`);
|
| 64 |
-
res.end();
|
| 65 |
-
}
|
| 66 |
}
|
| 67 |
});
|
| 68 |
|
|
@@ -70,12 +63,5 @@ app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'index.html')));
|
|
| 70 |
|
| 71 |
const PORT = process.env.PORT || 7860;
|
| 72 |
app.listen(PORT, () => {
|
| 73 |
-
console.log(`
|
| 74 |
-
🚀 Kimi K2.5 FW (No Thinking Mode)
|
| 75 |
-
----------------------------------
|
| 76 |
-
Model: ${MODEL}
|
| 77 |
-
Reasoning: DISABLED (Forced)
|
| 78 |
-
Port: ${PORT}
|
| 79 |
-
----------------------------------
|
| 80 |
-
`);
|
| 81 |
});
|
|
|
|
| 11 |
app.use(express.json());
|
| 12 |
app.use(express.static(__dirname));
|
| 13 |
|
| 14 |
+
// ✅ وضع المفكر: Kimi مع إظهار التفكير
|
| 15 |
+
app.post('/api/think', async (req, res) => {
|
|
|
|
|
|
|
| 16 |
const { message } = req.body;
|
| 17 |
const POE_KEY = process.env.POE_API_KEY;
|
| 18 |
|
|
|
|
| 20 |
return res.status(401).json({ error: "POE_API_KEY غير موجود" });
|
| 21 |
}
|
| 22 |
|
|
|
|
| 23 |
res.setHeader('Content-Type', 'text/event-stream');
|
| 24 |
res.setHeader('Cache-Control', 'no-cache');
|
|
|
|
| 25 |
|
| 26 |
const client = new OpenAI({
|
| 27 |
apiKey: POE_KEY,
|
|
|
|
| 29 |
});
|
| 30 |
|
| 31 |
try {
|
| 32 |
+
// إرسال إشارة بدء التفكير أولاً
|
| 33 |
+
res.write(`data: ${JSON.stringify({ status: "thinking" })}\n\n`);
|
| 34 |
+
|
| 35 |
const stream = await client.chat.completions.create({
|
| 36 |
+
model: "kimi-k2.5-fw", // النموذج المفكر
|
| 37 |
messages: [{ role: "user", content: message }],
|
| 38 |
stream: true,
|
| 39 |
+
temperature: 0.7
|
| 40 |
+
// لا نحاول تعطيل التفكير هنا - نتركه يفكر
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
});
|
| 42 |
|
| 43 |
+
// إرسال إشارة بدء الرد الفعلي
|
| 44 |
+
res.write(`data: ${JSON.stringify({ status: "responding" })}\n\n`);
|
| 45 |
+
|
| 46 |
for await (const chunk of stream) {
|
| 47 |
const content = chunk.choices[0]?.delta?.content || "";
|
| 48 |
if (content) {
|
|
|
|
| 54 |
res.end();
|
| 55 |
|
| 56 |
} catch (err) {
|
| 57 |
+
res.write(`data: ${JSON.stringify({ error: err.message })}\n\n`);
|
| 58 |
+
res.end();
|
|
|
|
|
|
|
|
|
|
| 59 |
}
|
| 60 |
});
|
| 61 |
|
|
|
|
| 63 |
|
| 64 |
const PORT = process.env.PORT || 7860;
|
| 65 |
app.listen(PORT, () => {
|
| 66 |
+
console.log(`🚀 Server: Think Mode (Kimi) active on port ${PORT}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
});
|