diff --git a/Dockerfile b/Dockerfile index f5955d3..6f8d968 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM python:3.12-slim WORKDIR /app/ COPY . . -RUN apt update && apt install gcc -y +RUN apt update && apt install gcc chromium-browser -y RUN pip3 install --upgrade pip RUN pip3 install -r requirements.txt diff --git a/requirements.txt b/requirements.txt index abd9e37..215de1d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,5 @@ auth Flask[async] g4f Werkzeug +aiohttp_socks +nodriver \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store index a428eaa..bdcb5a8 100644 Binary files a/src/.DS_Store and b/src/.DS_Store differ diff --git a/src/FreeGPT4_Server.py b/src/FreeGPT4_Server.py index d8a5acc..e91bfd1 100755 --- a/src/FreeGPT4_Server.py +++ b/src/FreeGPT4_Server.py @@ -16,9 +16,10 @@ from werkzeug.security import generate_password_hash, check_password_hash from werkzeug.utils import secure_filename -app = Flask(__name__) +app = Flask(__name__) + UPLOAD_FOLDER = 'data/' # ALLOWED_EXTENSIONS = {'json'} @@ -30,6 +31,7 @@ # Available providers PROVIDERS = { + "Auto": "", "AItianhu": g4f.Provider.AItianhu, "Acytoo": g4f.Provider.Acytoo, "Aichat": g4f.Provider.Aichat, @@ -52,12 +54,8 @@ "Gemini": g4f.Provider.Gemini, } -# Available Bing's tones -TONES = [ - "Creative", - "Balanced", - "Precise" -] +GENERIC_MODELS = ["gpt-3.5-turbo", "gpt-4"] + print( """ @@ -140,13 +138,6 @@ type=str, help="Add the keyword support", ) -parser.add_argument( - "--tone", - action='store', - required=False, - type=str, - help="Specify the model's tone if supported (Bing's default: Precise)", -) parser.add_argument( "--system-prompt", action='store', @@ -157,6 +148,13 @@ args, unknown = parser.parse_known_args() +# Get the absolute path of the script +script_path = os.path.abspath(__file__) +# Get the directory of the script +script_dir = os.path.dirname(script_path) +# Change the current working directory +os.chdir(script_dir) + # Loads the settings from the file with open(SETTINGS_FILE, "r") as f: data = json.load(f) @@ -193,11 +191,6 @@ data["cookie_file"] = args.cookie_file else: args.cookie_file = data["cookie_file"] - - if (args.tone != None): - data["tone"] = args.tone - else: - args.tone = data["tone"] if (args.system_prompt != None): data["system_prompt"] = args.system_prompt @@ -264,10 +257,9 @@ def saveSettings(request, file): data["file_input"] = bool(request.form["file_input"] == "true") data["remove_sources"] = bool(request.form["remove_sources"] == "true") data["port"] = request.form["port"] - # data["model"] = request.form["model"] #Considering to implement this + data["model"] = request.form["model"] #Considering to implement this data["keyword"] = request.form["keyword"] data["provider"] = request.form["provider"] - data["tone"] = request.form["tone"] data["system_prompt"] = request.form["system_prompt"] data["message_history"] = bool(request.form["message_history"] == "true") file = request.files["cookie_file"] @@ -301,7 +293,6 @@ def applySettings(file): 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"] args.enable_history = data["message_history"] f.close() @@ -319,16 +310,12 @@ async def index() -> str: # Starts the bot and gets the input print("Initializing...") question = None - tone = None print("start") 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 "
Invalid token
" - if (tone == None or tone not in TONES): - tone = args.tone print("get") else: file = request.files["file"] @@ -344,7 +331,6 @@ async def index() -> str: # print(PROVIDERS[args.provider].params) # supported args print("\nCookies: " + str(len(args.cookie_file))) print("\nInput: " + question) - print("\nTone: " + tone) if (len(args.cookie_file) != 0): try: cookies = json.load(open(args.cookie_file)) # Loads the cookies from the file @@ -367,6 +353,9 @@ async def index() -> str: message_history.append({"role": "system", "content": args.system_prompt}) message_history.append({"role": "user", "content": question}) + if (args.provider == "Auto"): + args.provider = "" + # Set with provider response = ( await g4f.ChatCompletion.create_async( @@ -374,10 +363,11 @@ async def index() -> str: provider=args.provider, messages=message_history, cookies=cookies, - auth=True, - tone=tone ) ) + + print(response) + #Joins the response into a single string resp_str = "" for message in response: @@ -422,6 +412,7 @@ async def settings(): if (auth()): try: providers=PROVIDERS + generic_models=GENERIC_MODELS data = json.loads(open(SETTINGS_FILE).read()) return render_template("settings.html", **locals()) except Exception as error: @@ -447,6 +438,16 @@ async def save(): else: return render_template("login.html", **locals()) +@app.route("/models", methods=["GET"]) +async def get_models(): + provider = request.args.get("provider") + if (provider == "Auto"): + return GENERIC_MODELS + try: + return PROVIDERS[provider].models + except: + return ["default"] + if __name__ == "__main__": # Starts the server, change the port if needed app.run("0.0.0.0", port=args.port, debug=False) \ No newline at end of file diff --git a/src/__pycache__/FreeGPT4_Server.cpython-311.pyc b/src/__pycache__/FreeGPT4_Server.cpython-311.pyc index 10d6e46..2b9da94 100644 Binary files a/src/__pycache__/FreeGPT4_Server.cpython-311.pyc and b/src/__pycache__/FreeGPT4_Server.cpython-311.pyc differ diff --git a/src/__pycache__/__init__.cpython-311.pyc b/src/__pycache__/__init__.cpython-311.pyc index 7659fec..854db44 100644 Binary files a/src/__pycache__/__init__.cpython-311.pyc and b/src/__pycache__/__init__.cpython-311.pyc differ diff --git a/src/data/settings.json b/src/data/settings.json index bae30ad..be1e7f6 100644 --- a/src/data/settings.json +++ b/src/data/settings.json @@ -6,9 +6,8 @@ "remove_sources": true, "port": "5500", "model": "gpt-4", - "provider": "Bing", - "tone": "Precise", + "provider": "", "keyword": "text", "cookie_file": "data/cookies.json", "system_prompt": "" -} +} \ No newline at end of file diff --git a/src/static/js/script.js b/src/static/js/script.js index 47d7d05..f0ebdd3 100644 --- a/src/static/js/script.js +++ b/src/static/js/script.js @@ -32,4 +32,33 @@ function showElement(id_to_show) { // Hides an element function hideElement(id_to_hide) { document.getElementById(id_to_hide).hidden = true; -} \ No newline at end of file +} + +// Gets available models for choosen A.I. Provider +$(document).ready(function(){ + $("#provider").change(function(){ + var inputValue = $(this).val(); + $.ajax({ + url: '/models', + data: { + 'provider': inputValue + }, + success: function(response) { + var select = document.getElementById("model"); + + // Remove existing models + while (select.firstChild) { + select.removeChild(select.firstChild); + } + + // Add the new models + for (var i=0; i