File size: 1,164 Bytes
7626743 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
const express = require("express");
const axios = require("axios");
const bodyParser = require("body-parser");
const path = require("path");
const app = express();
app.use(express.static(path.join(__dirname, ".")));
app.use(bodyParser.json());
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname + "/index.html"));
});
app.post("/chat/completions", async (req, res) => {
try {
const {
openai_endpoint,
openai_request_method,
openai_request_headers,
openai_request_body,
} = req.body;
const response = await axios({
method: openai_request_method,
url: openai_endpoint + "/chat/completions",
data: openai_request_body,
headers: openai_request_headers,
responseType: "stream",
});
response.data.pipe(res);
} catch (error) {
console.error(error);
console.log(error.response.data);
res.status(500).json({ error: "Error calling OpenAI API" });
}
});
const port = 12345;
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
|