redacts cookies in logs; fix sha on infopage

This commit is contained in:
nai-degen 2023-04-10 03:39:13 -07:00 committed by nai-degen
parent 2a4dfe2501
commit 4200d8203d
7 changed files with 107 additions and 24 deletions

View File

@ -1,26 +1,16 @@
# Copy this file to .env and fill in the values.
# Set your OpenAI API key below.
# Set your OpenAI API key(s) below, separated by commas if you have multiple keys.
OPENAI_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# You can also set a base-64 encoded JSON array of keys matching this schema:
# Trial keys will be prioritized. GPT4-enabled keys are necessary to use GPT-4.
# For example:
# [
# { "key": "your-openai-key-1", "isTrial": true, "isGpt4": false },
# { "key": "your-openai-key-2", "isTrial": false, "isGpt4": false },
# { "key": "your-openai-key-3", "isTrial": false, "isGpt4": true }
# ]
# Encoded in base-64, this would look like:
# OPENAI_KEYS=WwogeyAia2V5IjogInlvdXItb3BlbmFpLWtleS0xIiwgImlzVHJpYWwiOiB0cnVlLCAiaXNHcHQ0IjogZmFsc2UgfSwKIHsgImtleSI6ICJ5b3VyLW9wZW5haS1rZXktMiIsICJpc1RyaWFsIjogZmFsc2UsICJpc0dwdDQiOiBmYWxzZSB9LAogeyAia2V5IjogInlvdXItb3BlbmFpLWtleS0zIiwgImlzVHJpYWwiOiBmYWxzZSwgImlzR3B0NCI6IHRydWUgfQpd
# Optional settings (please see config.ts for more details)
# PORT=7860
# PROXY_KEY=your-secret-key
# MODEL_RATE_LIMIT=2
# MAX_OUTPUT_TOKENS=256
# MODEL_RATE_LIMIT=4
# MAX_OUTPUT_TOKENS=300
# LOG_LEVEL=info
# LOG_PROMPTS=false
# REJECT_DISALLOWED=false
# REJECT_MESSAGE="This content violates /aicg/'s acceptable use policy."
# REJECT_SAMPLE_RATE=0.2
# CHECK_KEYS=false

View File

@ -24,8 +24,7 @@ RUN apt-get update && \
apt-get install -y git
RUN git clone https://github.com/nai-degen/oai-reverse-proxy.git /app
WORKDIR /app
RUN git rev-parse HEAD > git-commit-sha.txt
ENV SHA=$(cat git-commit-sha.txt)
ENV NODE_ENV=production
RUN npm install
COPY . .
RUN npm run build
@ -57,7 +56,9 @@ CMD [ "npm", "start" ]
## Updating the server
You can just restart your server to have it pull the latest version of the code from GitHub.
To update your server, go to the Settings menu and select `Factory Reboot`. This will pull the latest version of the code from GitHub and restart the server.
Note that if you just perform a regular Restart, the server will be restarted with the same code that was running before.
## Customizing the server

70
package-lock.json generated
View File

@ -17,6 +17,7 @@
"pino": "^8.11.0",
"pino-http": "^8.3.3",
"showdown": "^2.1.0",
"simple-git": "^3.17.0",
"zlib": "^1.0.5"
},
"devDependencies": {
@ -68,6 +69,40 @@
"@jridgewell/sourcemap-codec": "^1.4.10"
}
},
"node_modules/@kwsites/file-exists": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz",
"integrity": "sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==",
"dependencies": {
"debug": "^4.1.1"
}
},
"node_modules/@kwsites/file-exists/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/@kwsites/file-exists/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/@kwsites/promise-deferred": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz",
"integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw=="
},
"node_modules/@tsconfig/node10": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz",
@ -1474,6 +1509,41 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/simple-git": {
"version": "3.17.0",
"resolved": "https://registry.npmjs.org/simple-git/-/simple-git-3.17.0.tgz",
"integrity": "sha512-JozI/s8jr3nvLd9yn2jzPVHnhVzt7t7QWfcIoDcqRIGN+f1IINGv52xoZti2kkYfoRhhRvzMSNPfogHMp97rlw==",
"dependencies": {
"@kwsites/file-exists": "^1.1.1",
"@kwsites/promise-deferred": "^1.1.1",
"debug": "^4.3.4"
},
"funding": {
"type": "github",
"url": "https://github.com/steveukx/git-js?sponsor=1"
}
},
"node_modules/simple-git/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/simple-git/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/simple-update-notifier": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.1.0.tgz",

View File

@ -22,6 +22,7 @@
"pino": "^8.11.0",
"pino-http": "^8.3.3",
"showdown": "^2.1.0",
"simple-git": "^3.17.0",
"zlib": "^1.0.5"
},
"devDependencies": {

View File

@ -1,6 +1,8 @@
import dotenv from "dotenv";
dotenv.config();
const isDev = process.env.NODE_ENV !== "production";
type Config = {
/** The port the proxy server will listen on. */
port: number;
@ -26,12 +28,14 @@ type Config = {
checkKeys?: boolean;
};
// To change configs, create a file called .env in the root directory.
// See .env.example for an example.
export const config: Config = {
port: getEnvWithDefault("PORT", 7860),
openaiKey: getEnvWithDefault("OPENAI_KEY", ""),
proxyKey: getEnvWithDefault("PROXY_KEY", ""),
modelRateLimit: getEnvWithDefault("MODEL_RATE_LIMIT", 2),
maxOutputTokens: getEnvWithDefault("MAX_OUTPUT_TOKENS", 256),
modelRateLimit: getEnvWithDefault("MODEL_RATE_LIMIT", 4),
maxOutputTokens: getEnvWithDefault("MAX_OUTPUT_TOKENS", 300),
rejectDisallowed: getEnvWithDefault("REJECT_DISALLOWED", false),
rejectSampleRate: getEnvWithDefault("REJECT_SAMPLE_RATE", 0.2),
rejectMessage: getEnvWithDefault(
@ -39,8 +43,8 @@ export const config: Config = {
"This content violates /aicg/'s acceptable use policy."
),
logLevel: getEnvWithDefault("LOG_LEVEL", "info"),
logPrompts: getEnvWithDefault("LOG_PROMPTS", false),
checkKeys: getEnvWithDefault("CHECK_KEYS", true),
logPrompts: getEnvWithDefault("LOG_PROMPTS", false), // Not yet implemented
checkKeys: getEnvWithDefault("CHECK_KEYS", !isDev),
} as const;
export const SENSITIVE_KEYS: (keyof Config)[] = ["proxyKey", "openaiKey"];

View File

@ -51,7 +51,7 @@ function getInfoPageHtml(host: string) {
...(config.modelRateLimit ? { proomptersNow: getUniqueIps() } : {}),
keyInfo,
config: listConfig(),
sha: (process.env.SHA?.slice(0, 7) || "dev").toUpperCase(),
sha: process.env.COMMIT_SHA?.slice(0, 7) || "dev",
};
const readme = require("fs").readFileSync("info-page.md", "utf8");

View File

@ -2,6 +2,7 @@ import { config } from "./config";
import express from "express";
import cors from "cors";
import pinoHttp from "pino-http";
import { simpleGit } from "simple-git";
import { logger } from "./logger";
import { keyPool } from "./key-management";
import { proxyRouter, rewriteTavernRequests } from "./proxy/routes";
@ -17,6 +18,10 @@ app.use(
logger,
// SillyTavern spams the hell out of this endpoint so don't log it
autoLogging: { ignore: (req) => req.url === "/proxy/kobold/api/v1/model" },
redact: {
paths: ["req.headers.cookie", 'res.headers["set-cookie"]'],
censor: "********",
},
})
);
app.use(cors());
@ -42,7 +47,19 @@ app.use((_req: unknown, res: express.Response) => {
res.status(404).json({ error: "Not found" });
});
// start server and load keys
app.listen(PORT, () => {
logger.info(`Server listening on port ${PORT}`);
app.listen(PORT, async () => {
try {
const git = simpleGit();
const log = git.log({ n: 1 });
const sha = (await log).latest!.hash;
process.env.COMMIT_SHA = sha;
} catch (error) {
process.env.COMMIT_SHA = "unknown";
}
logger.info(
{ sha: process.env.COMMIT_SHA },
`Server listening on port ${PORT}`
);
keyPool.init();
});