Skip to content

Commit

Permalink
Added token access for requests (Private Mode flag)
Browse files Browse the repository at this point in the history
  • Loading branch information
aledipa committed Mar 18, 2024
1 parent c2dc6f1 commit 3a0215a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/FreeGPT4_Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import json
import os
from uuid import uuid4

# GPT Library
import g4f
Expand Down Expand Up @@ -68,6 +69,8 @@ def saveSettings(request, file):
data["tone"] = request.form["tone"]
data["system_prompt"] = request.form["system_prompt"]
file = request.files["cookie_file"]
if (args.private_mode):
data["token"] = request.form["token"]
#checks if the file is not empty
if file.filename != '':
#checks if the file is a json file
Expand All @@ -94,6 +97,7 @@ def applySettings(file):
args.provider = data["provider"]
args.model = data["model"]
args.cookie_file = data["cookie_file"]
args.token = data["token"]
args.remove_sources = data["remove_sources"]
args.tone = data["tone"]
args.system_prompt = data["system_prompt"]
Expand All @@ -115,6 +119,8 @@ async def index() -> str:
if request.method == "GET":
question = request.args.get(args.keyword) #text
tone = request.args.get("tone") #tone
if (args.private_mode and request.args.get("token") != data["token"]):
return "<p id='response'>Invalid token</p>"
if (tone == None or tone not in TONES):
tone = args.tone
print("get")
Expand Down Expand Up @@ -229,7 +235,7 @@ async def save():
if __name__ == "__main__":
print(
"""
FreeGPT4 Web API - A Web API for GPT-4 (Using BingAI)
FreeGPT4 Web API - A Web API for GPT-4
Repo: github.com/aledipa/FreeGPT4-WEB-API
By: Alessandro Di Pasquale
Expand All @@ -249,6 +255,12 @@ async def save():
required=False,
help="Use a graphical interface for settings",
)
parser.add_argument(
"--private-mode",
action='store_true',
required=False,
help="Use a private token to access the API",
)
parser.add_argument(
"--password",
action='store',
Expand Down Expand Up @@ -358,6 +370,17 @@ async def save():
else:
args.system_prompt = data["system_prompt"]

if (args.remove_sources == False):
args.remove_sources = data["remove_sources"]
else:
data["remove_sources"] = args.remove_sources

if (args.private_mode and data["token"] == ""):
token = str(uuid4())
data["token"] = token
elif (data["token"] != ""):
token = data["token"]

json.dump(data, f)
f.close()

Expand Down
1 change: 1 addition & 0 deletions src/data/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"password": "",
"token": "",
"file_input": "True",
"remove_sources": "True",
"port": "5500",
Expand Down

0 comments on commit 3a0215a

Please sign in to comment.