From 738f9d86c659ec5a5fa7210565d00fe1e1db71b8 Mon Sep 17 00:00:00 2001 From: Alessandro <51910404+aledipa@users.noreply.github.com> Date: Sun, 21 Apr 2024 13:33:42 +0200 Subject: [PATCH] Added the 'Model Selection' feature to the GUI Settings, you can now choose a model from the settings without the need to pick a specific provider. Bing's tones are now under the model's list. Decluttered code and files. Fixed Pytest. --- Dockerfile | 2 +- requirements.txt | 2 + src/.DS_Store | Bin 6148 -> 8196 bytes src/FreeGPT4_Server.py | 59 +++++++++--------- .../FreeGPT4_Server.cpython-311.pyc | Bin 18882 -> 19195 bytes src/__pycache__/__init__.cpython-311.pyc | Bin 178 -> 178 bytes src/data/settings.json | 5 +- src/static/js/script.js | 31 ++++++++- src/templates/settings.html | 37 +++++------ .../__pycache__/__init__.cpython-311.pyc | Bin 184 -> 184 bytes .../test_launch.cpython-311-pytest-7.3.1.pyc | Bin 1074 -> 1074 bytes tests/__pycache__/__init__.cpython-311.pyc | Bin 180 -> 180 bytes .../test_launch.cpython-311-pytest-7.3.1.pyc | Bin 1070 -> 1070 bytes tests/data/settings.json | 1 - 14 files changed, 79 insertions(+), 58 deletions(-) delete mode 100644 tests/data/settings.json 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 a428eaabafa160db66239b18934df00d6290a7e9..bdcb5a86eed6c7ff56db5e33c2f0e67ab6e925a0 100644 GIT binary patch literal 8196 zcmeHMPiqrF6n~SZO==K=Sg41>TCb(1e^8QVm7-pi<_O0O&dxnaM#6um}Ko zEQ}WmSfvn?vob~**|UtCpgn*OJ*eZ~Ds;xQO^1nqiGYcKiGYcKiNG{O0MBej`3dK~ zkeb>=z(nA`i~!poEG&#yBp(RQw+^iM6##h_yE$PS?*ZJ#lDs1MKyYq~V~X1Yk)}jm zF^Dinxy96xS0o<@F3f=lb0BhNB5x>!&yIE$R|irN+|(ulCIaITSjMgbzq9)gYWMg3 zI{|Gv0d-J=y;Rq+tp4PLt)W#1_Mr(4EG_WZI0>uQzh~t}&A_2FIA-8rXU%TXw*0Vg z^l`EaZCa~I$Ma9Wyg2pg^E>9efH~%Ho4S9X-D#;_yl4Jq!NmadprJ!2ODIzV7VA0v zs3ZM*>vRG?>Xk|#NMHzSpl8&)%S6 zui=MYmmB!5hbj;6`=LwwRk|Cx5x2F4U>>PnTs$~f+qkr1ZI&({u2=`<^%Azr>xYN) z`GpG?uimXc3EClj#(?22DtB8rEuQ20IksXv!{jmLxKmHpxi_jzP0+&EI6<+knvyiR zo`ebxJ(_pV?uG#kcd(E7a|Uif7gweSw_yvmVH4M=jZa{M{+X~{>KK=p1fGABNbrq^u(OKyZ{G{qqk2 Xcr5aXQ_ffYY&7S;Isf@eIg!;bk?Q-y delta 329 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50C@Kn)2a6>$Br+s3WH6*M#BVHI z&dew}Sy51G@+1L6Cc(>K=6wMkwz!49g)h%d{wSbE8=Asq*aKOox}Qh>J0MR)4#u1$qB@yXRFO%CdGZAjvB`F#JZvRb!HNPzRS-;x$&*A) wCzhlwX6N7#WCmIa1OnVZ!W9%68w 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 10d6e4610ec141abd274b444669f0298e4acfe4b..2b9da9429196be43411b87ea736b2fe7e4f295d9 100644 GIT binary patch delta 6885 zcmb6+TX0*)b-VZC;z9D_L4p*)7xNlBLY5J^2qg-|4lk_>^|D+&+=Pz$iK zY0#t-C8b?9qOx*ArAoqS8#Oc5M>3jZl9_bsI_jvIi8GXg#w=P*HElD^R|lFpQ#VaL z-E;A}fLxEeB+lJEd(PQCXU}8zU55YrEiC_qEaxHK^8c&;QskEGz~8vF^8-DR87Agi zA3NAFY~EQ81kgCrsu=x_#0VjOMXJYVZ0tC8ushf+S81?CYy~?k_AIVy_K(;h*J!9p z*e^J5xnSN|r@@wHan);P9IQfcFrQ$S8#UN+c2aP3R%CJ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b0dd6fe587e0f15b06363ee48..854db444e6121390fde7a1be37b7c1940e007606 100644 GIT binary patch delta 19 ZcmdnQxQUT_IWI340}xD|pgfU#IRGvJ1jqmY delta 19 ZcmdnQxQUT_IWI340}#aYicaKS4gf4<1bzSj 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; iServer settings A.I. Provider: - {% for key, value in providers.items() %} @@ -100,19 +100,24 @@

Server settings

- - + Cookies: @@ -134,18 +139,6 @@

Server settings

- - Tone: - - - - - - System Prompt: @@ -166,14 +159,12 @@

Server settings

- - - {% endblock %} + diff --git a/src/tests/__pycache__/__init__.cpython-311.pyc b/src/tests/__pycache__/__init__.cpython-311.pyc index b06177e58752d0fefda71e604efc569760756ec8..31575e9403a72b4a05db672747a84003790ae250 100644 GIT binary patch delta 19 ZcmdnNxPy^IWI340}$N!qB4*wi1$F=c delta 19 ZcmdnOxP_5>IWI340}y!K<)6sC5&$i_1iSzM diff --git a/tests/__pycache__/test_launch.cpython-311-pytest-7.3.1.pyc b/tests/__pycache__/test_launch.cpython-311-pytest-7.3.1.pyc index 9c4b5cac52cb9a4cd425f8132d1129756c3e2b73..182f0179f67700cddfd91dc3a851ff233c583592 100644 GIT binary patch delta 20 acmZ3-v5td#IWI340}$N!qOy@&nFRng+XWT? delta 20 acmZ3-v5td#IWI340}y=V5!uMC%mM&0$^