代码拉取完成,页面将自动刷新
同步操作将从 N0ts/chatgpt-node-proxy 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
const express = require("express");
const cors = require("cors");
const axios = require("axios");
const app = express();
app.use(express.json());
app.use(cors());
axios.interceptors.response.use(
function (response) {
return response.data;
},
function (error) {
return Promise.reject(error);
}
);
app.post("/v1/chat/completions", async function (request, response) {
let { stream } = request.body;
const { authorization } = request.headers;
if (!stream) {
let result = null;
try {
result = await axios({
method: "POST",
url: "https://api.openai.com/v1/chat/completions",
data: request.body,
headers: {
authorization
}
});
} catch (err) {
return response.send(err.response.data);
}
return response.send(result);
}
response.writeHead(200, {
"Content-Type": "text/event-stream"
});
axios({
method: "POST",
url: "https://api.openai.com/v1/chat/completions",
data: request.body,
headers: {
authorization
},
responseType: "stream"
})
.then((res) => {
res.on("data", (chunk) => {
response.write(Buffer.from(chunk.toString()));
});
res.on("end", () => {
response.end();
});
})
.catch((err) => {
err.response.data.on("data", (chunk) => {
response.write(Buffer.from(chunk.toString()));
});
err.response.data.on("end", () => {
response.end();
});
});
});
app.get("/*", (request, response) => {
response.send("部署完成");
});
app.post("/*", (request, response) => {
response.send("部署完成");
});
app.listen(9000, function () {
console.log("http://localhost:9000");
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。