From 963c71718f4ef8ef28a9fc99b569d241bb778fe9 Mon Sep 17 00:00:00 2001 From: nsde Date: Sun, 20 Aug 2023 13:41:24 +0200 Subject: [PATCH] Added replit security tutorial --- .vscode/settings.json | 7 +++- web/app.py | 10 ++++-- web/templates/panel.html | 13 +++---- web/templates/replit.html | 71 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 web/templates/replit.html diff --git a/.vscode/settings.json b/.vscode/settings.json index c926943..8ea37e0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,6 +20,11 @@ "static/css/home.css", "static/css/navbar.css", "static/css/input.css", - "static/css/footer.css" + "static/css/footer.css", + "web/static/css/base.css", + "web/static/css/footer.css", + "web/static/css/home.css", + "web/static/css/input.css", + "web/static/css/navbar.css" ] } \ No newline at end of file diff --git a/web/app.py b/web/app.py index fc4eb1c..95f1387 100644 --- a/web/app.py +++ b/web/app.py @@ -33,14 +33,18 @@ def create_app() -> flask.Flask: def alt_design(): return flask.render_template('alt-design.html') - @app.route('/panel') - def panel(): + @app.route('/go') + def go(): return flask.render_template('panel.html') @app.route('/novacord') - def novacord(): + def novacord_page(): return flask.render_template('novacord.html') + @app.route('/replit') + def replit_page(): + return flask.render_template('replit.html') + @app.route('/favicon.ico') def favicon(): return flask.send_file('static/img/fav.ico', mimetype='image/vnd.microsoft.icon') diff --git a/web/templates/panel.html b/web/templates/panel.html index dde8343..361c85f 100644 --- a/web/templates/panel.html +++ b/web/templates/panel.html @@ -3,21 +3,16 @@

API Panel

-

- Warning - this is a very early prototype of NovaAI. Do not use it in production. - You have been warned. -

Python

Endpoint

To use NovaAI in your code, simply set the endpoint of NovaAI. - It's compitable with ClosedAI's library. + It's compitable with the official OpenAI Python library.

import openai as novaai
-        
+
 novaai.api_base = 'https://api.nova-oss.com/v1'
@@ -45,7 +40,7 @@ novaai.api_base = 'https://api.nova-oss.com/v1'

Unofficial front-ends (Better ChatGPT, ...)

- Keep in mind not to violate ClosedAI's terms of service, or it'll break their hearts :( + Keep in mind not to violate OpenAIAI's terms of service, or it'll break their hearts :( (and maybe write you a C&D).

Anyways, set the API endpoint to https://api.nova-oss.com/v1 and don't forget to add your NovaAI API key, too. @@ -58,7 +53,7 @@ novaai.api_base = 'https://api.nova-oss.com/v1'

Documentation

-

Official ClosedAI documentation

+

Official OpenAI documentation

diff --git a/web/templates/replit.html b/web/templates/replit.html new file mode 100644 index 0000000..a38b7d9 --- /dev/null +++ b/web/templates/replit.html @@ -0,0 +1,71 @@ +{% include 'parts/begin.html' %} + + +
+

Prevent your API keys and Discord bot tokens from being stolen when using replit

+

+ Everyone can see your code created using replit.
+ It's really important that you don't set your API keys and other secret credentials directly in your code. + This isn't just for NovaAI, but for all your projects. +

+

How to add new secrets

+

+ It's really simple: +

    +
  1. + Click the lock icon in the left sidebar +
  2. +
  3. + Set key to something like NOVA_API_KEY or DISCORD_BOT_TOKEN (don't use spaces etc.) + and the field value to your API key/token that you want to hide. +
  4. +
  5. + Click Add new secret +
  6. +
  7. + Now, you'll need to change the code a bit. Don't worry, it's just one or two lines. +
  8. +
+

+ +

How to use secrets in your code

+

In the following example, we're assuming you have just created a new NOVA_API_KEY secret.

+ +

Python

+

To set the variable nova_api_key to the value of the secret, use the following code:

+
import os
+
+nova_api_key = os.environ['NOVA_API_KEY']
+ + +

For example, if you want to use the openai Python library, your code might look a bit like this:

+
import openai as novaai
+import os
+
+novaai.api_base = 'https://api.nova-oss.com/v1'
+novaai.api_key = os.environ['NOVA_API_KEY']
+
+# ...
+ + +

Node.js

+

To set the variable novaApiKey to the value of the secret, use the following code:

+
const novaApiKey = process.env.NOVA_API_KEY
+ +

If you're using discord.js, your code might look a bit like this:

+
const Discord = require('discord.js')
+const client = new Discord.Client()
+// ...
+client.login(process.env.DISCORD_BOT_TOKEN)
+ +

Need help?

+

+ Learn more in the replit documentation + Here's a nice, well explained video tutorial by the team behind replit on how to use secrets: + https://youtu.be/Xrg2XP1JJec + And here's a shorter, but unofficial video tutorial by + https://youtu.be/BKlv__1OoGc?t=24. +

+
+ +{% include 'parts/end.html' %}