show git revision
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import { createEvent } from "./utils.mjs";
|
import { createEvent, getGitRevision } from "./utils.mjs";
|
||||||
import YouProvider from "./provider.mjs";
|
import YouProvider from "./provider.mjs";
|
||||||
import localtunnel from 'localtunnel';
|
import localtunnel from "localtunnel";
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from "uuid";
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.PORT || 8080;
|
const port = process.env.PORT || 8080;
|
||||||
const validApiKey = process.env.PASSWORD;
|
const validApiKey = process.env.PASSWORD;
|
||||||
@@ -106,7 +106,13 @@ app.post("/v1/chat/completions", OpenAIApiKeyAuth, (req, res) => {
|
|||||||
|
|
||||||
// call provider to get completion
|
// call provider to get completion
|
||||||
await provider
|
await provider
|
||||||
.getCompletion(randomSession, jsonBody.messages, jsonBody.stream ? true : false, jsonBody.model, process.env.USE_CUSTOM_MODE == "true" ? true : false)
|
.getCompletion(
|
||||||
|
randomSession,
|
||||||
|
jsonBody.messages,
|
||||||
|
jsonBody.stream ? true : false,
|
||||||
|
jsonBody.model,
|
||||||
|
process.env.USE_CUSTOM_MODE == "true" ? true : false
|
||||||
|
)
|
||||||
.then(({ completion, cancel }) => {
|
.then(({ completion, cancel }) => {
|
||||||
completion.on("start", (id) => {
|
completion.on("start", (id) => {
|
||||||
if (jsonBody.stream) {
|
if (jsonBody.stream) {
|
||||||
@@ -207,7 +213,9 @@ app.post("/v1/chat/completions", OpenAIApiKeyAuth, (req, res) => {
|
|||||||
sexual: { filtered: false, severity: "safe" },
|
sexual: { filtered: false, severity: "safe" },
|
||||||
violence: { filtered: false, severity: "safe" },
|
violence: { filtered: false, severity: "safe" },
|
||||||
},
|
},
|
||||||
delta: { content: "Error occurred, please check the log.\n\n出现错误,请检查日志:<pre>" + error.stack || error + "</pre>" },
|
delta: {
|
||||||
|
content: "Error occurred, please check the log.\n\n出现错误,请检查日志:<pre>" + error.stack || error + "</pre>",
|
||||||
|
},
|
||||||
finish_reason: null,
|
finish_reason: null,
|
||||||
index: 0,
|
index: 0,
|
||||||
},
|
},
|
||||||
@@ -418,7 +426,8 @@ app.post("/v1/messages", AnthropicApiKeyAuth, (req, res) => {
|
|||||||
|
|
||||||
// handle other
|
// handle other
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
res.status(404).send("Not Found");
|
const { revision, branch } = getGitRevision();
|
||||||
|
res.status(404).send("Not Found (YouChat_Proxy " + revision + "@" + branch + ")");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(port, async () => {
|
app.listen(port, async () => {
|
||||||
@@ -443,11 +452,11 @@ app.listen(port, async () => {
|
|||||||
const tunnel = await localtunnel(tunnelOptions);
|
const tunnel = await localtunnel(tunnelOptions);
|
||||||
console.log(`隧道已成功创建,可通过以下URL访问: ${tunnel.url}/v1`);
|
console.log(`隧道已成功创建,可通过以下URL访问: ${tunnel.url}/v1`);
|
||||||
|
|
||||||
tunnel.on('close', () => {
|
tunnel.on("close", () => {
|
||||||
console.log('已关闭隧道');
|
console.log("已关闭隧道");
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('创建隧道失败:', error);
|
console.error("创建隧道失败:", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,18 @@
|
|||||||
import * as docx from "docx";
|
import * as docx from "docx";
|
||||||
import cookie from "cookie";
|
import cookie from "cookie";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import { execSync } from "child_process";
|
||||||
|
|
||||||
|
function getGitRevision() {
|
||||||
|
// get git revision and branch
|
||||||
|
try {
|
||||||
|
const revision = execSync("git rev-parse --short HEAD").toString().trim();
|
||||||
|
const branch = execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
|
||||||
|
return { revision, branch };
|
||||||
|
} catch (e) {
|
||||||
|
return { revision: "unknown", branch: "unknown" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createDirectoryIfNotExists(dirPath) {
|
function createDirectoryIfNotExists(dirPath) {
|
||||||
if (!fs.existsSync(dirPath)) {
|
if (!fs.existsSync(dirPath)) {
|
||||||
@@ -97,4 +109,4 @@ function createEvent(event, data) {
|
|||||||
return `event: ${event}\ndata: ${data}\n\n`;
|
return `event: ${event}\ndata: ${data}\n\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { createEvent, createDirectoryIfNotExists, sleep, extractCookie, getSessionCookie, createDocx };
|
export { createEvent, createDirectoryIfNotExists, sleep, extractCookie, getSessionCookie, createDocx, getGitRevision };
|
||||||
|
|||||||
Reference in New Issue
Block a user