AnesKAM commited on
Commit
add68a8
·
verified ·
1 Parent(s): a08dabf

Create genisi.js

Browse files
Files changed (1) hide show
  1. genisi.js +65 -0
genisi.js ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import express from 'express';
2
+ import fetch from 'node-fetch';
3
+ import { OpenAI } from "openai";
4
+ import cors from 'cors';
5
+ import path from 'path';
6
+ import { fileURLToPath } from 'url';
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+ const app = express();
10
+
11
+ app.use(cors());
12
+ app.use(express.json());
13
+ app.use(express.static(__dirname));
14
+
15
+ // قراءة المفاتيح من الـ Secrets (أمان 100%)
16
+ const NVIDIA_KEY = process.env.NVIDIA_API_KEY;
17
+ const POE_KEY = process.env.POE_API_KEY;
18
+
19
+ // محرك الصور الفائق
20
+ async function generateImage(prompt) {
21
+ const url = "https://ai.api.nvidia.com/v1/genai/black-forest-labs/flux.1-dev";
22
+ const res = await fetch(url, {
23
+ method: "POST",
24
+ headers: {
25
+ "Authorization": `Bearer ${NVIDIA_KEY}`,
26
+ "Content-Type": "application/json"
27
+ },
28
+ body: JSON.stringify({
29
+ "prompt": `${prompt}, cinematic realistic 8k photography, highly detailed`,
30
+ "mode": "base", "cfg_scale": 3.5, "width": 1024, "height": 1024, "steps": 28
31
+ })
32
+ });
33
+ if (!res.ok) throw new Error("خطأ في محرك الصور");
34
+ return await res.json();
35
+ }
36
+
37
+ // محرك الدردشة الذكي
38
+ async function askChat(model, message) {
39
+ const client = new OpenAI({ apiKey: POE_KEY, baseURL: "https://api.poe.com/v1" });
40
+ const chat = await client.chat.completions.create({
41
+ model: model,
42
+ messages: [{ role: "user", content: message }]
43
+ });
44
+ return chat.choices[0].message.content;
45
+ }
46
+
47
+ // الروابط المؤمنة
48
+ app.post('/api/chat', async (req, res) => {
49
+ try {
50
+ const reply = await askChat(req.body.model, req.body.message);
51
+ res.json({ success: true, reply });
52
+ } catch (err) { res.status(500).json({ error: "فشل الاتصال بنموذج الدردشة" }); }
53
+ });
54
+
55
+ app.post('/api/image', async (req, res) => {
56
+ try {
57
+ const result = await generateImage(req.body.prompt);
58
+ res.json({ success: true, result });
59
+ } catch (err) { res.status(500).json({ error: "فشل توليد الصورة" }); }
60
+ });
61
+
62
+ app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'index.html')));
63
+
64
+ const PORT = 7860;
65
+ app.listen(PORT, () => console.log(`Genisi Secure Server is Live!`));