From 8143795d5ebb3cac1d50026550ae344d5bfadbfb Mon Sep 17 00:00:00 2001 From: nai-degen <44111-khanon@users.noreply.gitgud.io> Date: Sat, 8 Apr 2023 08:50:03 -0500 Subject: [PATCH] updates docs --- README.md | 22 ++++++++++++++++++---- package-lock.json | 33 ++++++++++++++++++++++++++++++++- package.json | 4 +++- src/info-page.ts | 17 ++++++++++++++--- 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3bb12f4..bfa7801 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/package-lock.json b/package-lock.json index edca9cb..c874207 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index a14cf29..cb0ade8 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/info-page.ts b/src/info-page.ts index c86279f..7992884 100644 --- a/src/info-page.ts +++ b/src/info-page.ts @@ -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 ` + 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 = `