updates docs

This commit is contained in:
nai-degen 2023-04-08 08:50:03 -05:00 committed by nai-degen
parent 51e07b82f5
commit 8143795d5e
4 changed files with 67 additions and 9 deletions

View File

@ -6,6 +6,7 @@ colorTo: purple
sdk: docker
pinned: false
---
<!-- -->
# OAI Reverse Proxy Server
Simple reverse proxy server for the OpenAI API.
@ -22,15 +23,28 @@ So, if you still want to share access to your key, you can use this to do so saf
### 1. Get an API key
- Go to [OpenAI](https://openai.com/) and sign up for an account.
### 2. Clone this Huggingface repository to your account
- Go to [Huggingface](https://huggingface.co/) and sign up for an account.
- Once logged in, click on the `+` button in the top right corner and select `Duplicate Space`.
- Once logged in, click on the `+` button in the top right corner and select `Duplicate this Space`.
![Duplicate Space](https://files.catbox.moe/3n6ubn.png)
### 3. Set your OpenAI API key as a secret
- Click the Settings button in the top right corner of your repository.
- Scroll down to the `Secrets` section and click `New Secret`.
- Enter `OPENAI_API_KEY` as the name and your OpenAI API key as the value.
- Scroll down to the `Repository Secrets` section and click `New Secret`.
![Secrets](https://files.catbox.moe/irrp2p.png)
- Enter `OPENAI_KEY` as the name and your OpenAI API key as the value.
![New Secret](https://files.catbox.moe/ka6s1a.png)
**Do not paste the key into `server.js`!** That file is public and anyone can see it. Leave it alone; it will load the key from the secret you just created.
### 4. Deploy the server
- Click the `Deploy` button in the top right corner of your repository.
- Your server should automatically deploy when you add the secret, but if not you can select `Factory Reset` from that same Settings menu.
### 5. Share the link
- The Service Info screen should show the URL for your server. You can share this with anyone to safely give them access to your OpenAI API key.
- If you want to protect access to the server, add another secret with the key `PROXY_KEY` using the method as for `OPENAI_KEY`.

33
package-lock.json generated
View File

@ -13,11 +13,13 @@
"dotenv": "^16.0.3",
"express": "^4.18.2",
"http-proxy-middleware": "^3.0.0-beta.1",
"pino-http": "^8.3.3"
"pino-http": "^8.3.3",
"showdown": "^2.1.0"
},
"devDependencies": {
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/showdown": "^2.0.0",
"nodemon": "^2.0.22",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
@ -176,6 +178,12 @@
"@types/node": "*"
}
},
"node_modules/@types/showdown": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@types/showdown/-/showdown-2.0.0.tgz",
"integrity": "sha512-70xBJoLv+oXjB5PhtA8vo7erjLDp9/qqI63SRHm4REKrwuPOLs8HhXwlZJBJaB4kC18cCZ1UUZ6Fb/PLFW4TCA==",
"dev": true
},
"node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@ -406,6 +414,14 @@
"fsevents": "~2.3.2"
}
},
"node_modules/commander": {
"version": "9.5.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz",
"integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==",
"engines": {
"node": "^12.20.0 || >=14"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -1372,6 +1388,21 @@
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
},
"node_modules/showdown": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/showdown/-/showdown-2.1.0.tgz",
"integrity": "sha512-/6NVYu4U819R2pUIk79n67SYgJHWCce0a5xTP979WbNp0FL9MN1I1QK662IDU1b6JzKTvmhgI7T7JYIxBi3kMQ==",
"dependencies": {
"commander": "^9.0.0"
},
"bin": {
"showdown": "bin/showdown.js"
},
"funding": {
"type": "individual",
"url": "https://www.paypal.me/tiviesantos"
}
},
"node_modules/side-channel": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",

View File

@ -14,11 +14,13 @@
"dotenv": "^16.0.3",
"express": "^4.18.2",
"http-proxy-middleware": "^3.0.0-beta.1",
"pino-http": "^8.3.3"
"pino-http": "^8.3.3",
"showdown": "^2.1.0"
},
"devDependencies": {
"@types/cors": "^2.8.13",
"@types/express": "^4.17.17",
"@types/showdown": "^2.0.0",
"nodemon": "^2.0.22",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"

View File

@ -1,4 +1,5 @@
import { Request, Response } from "express";
import showdown from "showdown";
import { keys } from "./keys";
export const handleInfoPage = (req: Request, res: Response) => {
@ -11,6 +12,7 @@ function getInfoPageHtml(host: string) {
message: "OpenAI Reverse Proxy",
uptime: process.uptime(),
timestamp: Date.now(),
baseUrl: host,
kobold: host + "/proxy/kobold",
openai: host + "/proxy/openai",
keys: {
@ -21,15 +23,24 @@ function getInfoPageHtml(host: string) {
},
};
return `<!DOCTYPE html>
const readme = require("fs").readFileSync("README.md", "utf8");
const readmeBody = readme.split("---")[2];
const converter = new showdown.Converter();
const html = converter.makeHtml(readmeBody);
const pageBody = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>OpenAI Reverse Proxy</title>
</head>
<body>
<h1>OpenAI Reverse Proxy</h1>
<body style="font-family: sans-serif; background-color: #f0f0f0; padding: 1em;"
${html}
<hr />
<h2>Service Info</h2>
<pre>${JSON.stringify(info, null, 2)}</pre>
</body>
</html>`;
return pageBody;
}