Update server.js
Browse files
server.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
// server.js adaptado para remover login e usar OpenRouter
|
| 2 |
-
|
| 3 |
import express from "express";
|
| 4 |
import path from "path";
|
| 5 |
import { fileURLToPath } from "url";
|
|
@@ -7,7 +5,6 @@ import dotenv from "dotenv";
|
|
| 7 |
import bodyParser from "body-parser";
|
| 8 |
import { InferenceClient } from "@huggingface/inference";
|
| 9 |
|
| 10 |
-
// Load env vars
|
| 11 |
dotenv.config();
|
| 12 |
|
| 13 |
const app = express();
|
|
@@ -15,6 +12,7 @@ const __filename = fileURLToPath(import.meta.url);
|
|
| 15 |
const __dirname = path.dirname(__filename);
|
| 16 |
const PORT = process.env.APP_PORT || 3000;
|
| 17 |
const MODEL_ID = "deepseek-ai/DeepSeek-V3-0324";
|
|
|
|
| 18 |
|
| 19 |
app.use(bodyParser.json());
|
| 20 |
app.use(express.static(path.join(__dirname, "dist")));
|
|
@@ -25,8 +23,12 @@ app.post("/api/ask-ai", async (req, res) => {
|
|
| 25 |
return res.status(400).send({ ok: false, message: "Missing prompt" });
|
| 26 |
}
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
res.setHeader("Content-Type", "text/plain");
|
| 32 |
res.setHeader("Cache-Control", "no-cache");
|
|
|
|
|
|
|
|
|
|
| 1 |
import express from "express";
|
| 2 |
import path from "path";
|
| 3 |
import { fileURLToPath } from "url";
|
|
|
|
| 5 |
import bodyParser from "body-parser";
|
| 6 |
import { InferenceClient } from "@huggingface/inference";
|
| 7 |
|
|
|
|
| 8 |
dotenv.config();
|
| 9 |
|
| 10 |
const app = express();
|
|
|
|
| 12 |
const __dirname = path.dirname(__filename);
|
| 13 |
const PORT = process.env.APP_PORT || 3000;
|
| 14 |
const MODEL_ID = "deepseek-ai/DeepSeek-V3-0324";
|
| 15 |
+
const OPENROUTER_API_KEY = process.env.OPENROUTER_API_KEY;
|
| 16 |
|
| 17 |
app.use(bodyParser.json());
|
| 18 |
app.use(express.static(path.join(__dirname, "dist")));
|
|
|
|
| 23 |
return res.status(400).send({ ok: false, message: "Missing prompt" });
|
| 24 |
}
|
| 25 |
|
| 26 |
+
if (!OPENROUTER_API_KEY) {
|
| 27 |
+
return res.status(500).send({
|
| 28 |
+
ok: false,
|
| 29 |
+
message: "Missing OpenRouter API Key",
|
| 30 |
+
});
|
| 31 |
+
}
|
| 32 |
|
| 33 |
res.setHeader("Content-Type", "text/plain");
|
| 34 |
res.setHeader("Cache-Control", "no-cache");
|