From 7f8526a1227e016fc79328ddcbe7afd09c0d63d1 Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:46:02 +0100 Subject: ~ New system for str to Provider --- g4f/gui/server/backend.py | 19 ++++++++++++------- g4f/gui/server/provider.py | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 g4f/gui/server/provider.py (limited to 'g4f/gui') diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py index 9a1dbbf8..8f4b529f 100644 --- a/g4f/gui/server/backend.py +++ b/g4f/gui/server/backend.py @@ -1,9 +1,11 @@ import g4f from flask import request -from threading import Thread from .internet import search from .config import special_instructions +from .provider import get_provider + +g4f.logging = True class Backend_Api: def __init__(self, app) -> None: @@ -31,22 +33,25 @@ class Backend_Api: conversation = request.json['meta']['content']['conversation'] prompt = request.json['meta']['content']['parts'][0] model = request.json['model'] + provider = get_provider(request.json.get('provider')) messages = special_instructions[jailbreak] + conversation + search(internet_access, prompt) + [prompt] def stream(): - answer = g4f.ChatCompletion.create(model = model, - messages = messages, stream=True) + if provider: + answer = g4f.ChatCompletion.create(model=model, + provider=provider, messages=messages, stream=True) + else: + answer = g4f.ChatCompletion.create(model=model, + messages=messages, stream=True) for token in answer: yield token - + return self.app.response_class(stream(), mimetype='text/event-stream') - except Exception as e: - print(e) + except Exception as e: return { - '_token': 'anerroroccuredmf', '_action': '_ask', 'success': False, "error": f"an error occured {str(e)}"}, 400 \ No newline at end of file diff --git a/g4f/gui/server/provider.py b/g4f/gui/server/provider.py new file mode 100644 index 00000000..286f881b --- /dev/null +++ b/g4f/gui/server/provider.py @@ -0,0 +1,17 @@ +import g4f + +def get_provider(provider: str) -> g4f.Provider.BaseProvider: + + if isinstance(provider, str): + print(provider) + if provider == 'g4f.Provider.Auto': + return None + + if provider in g4f.Provider.ProviderUtils.convert: + return g4f.Provider.ProviderUtils.convert[provider] + + else: + return None + + else: + return None -- cgit v1.2.3 From abc2fa2ca10c19cb2cbd500b8474d1edbe057781 Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:46:14 +0100 Subject: ~ Command line arguments for GUI --- g4f/gui/run.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'g4f/gui') diff --git a/g4f/gui/run.py b/g4f/gui/run.py index da672d59..731c7cbf 100644 --- a/g4f/gui/run.py +++ b/g4f/gui/run.py @@ -1,4 +1,18 @@ from g4f.gui import run_gui +from argparse import ArgumentParser + if __name__ == '__main__': - run_gui() \ No newline at end of file + + parser = ArgumentParser(description='Run the GUI') + + parser.add_argument('-host', type=str, default='0.0.0.0', help='hostname') + parser.add_argument('-port', type=int, default=80, help='port') + parser.add_argument('-debug', action='store_true', help='debug mode') + + args = parser.parse_args() + port = args.port + host = args.host + debug = args.debug + + run_gui(host, port, debug) \ No newline at end of file -- cgit v1.2.3 From e05987ace34b3db38d3849f7c33405bcc7e50ee9 Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:47:58 +0100 Subject: ~ | g4f `v-0.1.5.7` [Set Provider in GUI] + Provider Proxy --- g4f/gui/__init__.py | 2 +- g4f/gui/client/html/index.html | 291 ++++++++++++++++++++++------------------- g4f/gui/client/js/chat.v2.js | 14 +- 3 files changed, 164 insertions(+), 143 deletions(-) (limited to 'g4f/gui') diff --git a/g4f/gui/__init__.py b/g4f/gui/__init__.py index 90a6c7a6..48b78881 100644 --- a/g4f/gui/__init__.py +++ b/g4f/gui/__init__.py @@ -16,7 +16,7 @@ def run_gui(host: str = '0.0.0.0', port: int = 80, debug: bool = False) -> None: view_func = site.routes[route]['function'], methods = site.routes[route]['methods'], ) - + backend_api = Backend_Api(app) for route in backend_api.routes: app.add_url_rule( diff --git a/g4f/gui/client/html/index.html b/g4f/gui/client/html/index.html index 3acde2df..bb472706 100644 --- a/g4f/gui/client/html/index.html +++ b/g4f/gui/client/html/index.html @@ -1,161 +1,178 @@ - - - - - - - - - - - - - - - - - - - - - - - - g4f - gui - - -
-
-
-
- + /* Handle */ + #message-input::-webkit-scrollbar-thumb { + background: #c7a2ff; + } + + /* Handle on hover */ + #message-input::-webkit-scrollbar-thumb:hover { + background: #8b3dff; + } + + + + g4f - gui + + + +
+
+
+
+ +
+
+ +
+ + telegram: @g4f_official
+
-
- -
- - telegram: @g4f_official
-
-
-
- - github: @gpt4free
- leave a star ; ) -
-
+
+ + github: @gpt4free
+ leave a star ; ) +
-
-
- +
+
+
+ +
+
+
+
+
+ +
+ +
-
+
+
+
+ + + Web Access
-
-
- -
- -
-
+
+
-
-
- - - Web Access -
+
+
- + + + + + + + + + + + + + + + + + + + + + + + + + + +
-
- -
-
- Pick a color scheme - - - - - - - - - - - - - - -
-
-
+
- + + \ No newline at end of file diff --git a/g4f/gui/client/js/chat.v2.js b/g4f/gui/client/js/chat.v2.js index df827030..e1faa6bb 100644 --- a/g4f/gui/client/js/chat.v2.js +++ b/g4f/gui/client/js/chat.v2.js @@ -52,7 +52,7 @@ const remove_cancel_button = async () => { const ask_gpt = async (message) => { try { - message_input.value = ``; + message_input.value = ``; message_input.innerHTML = ``; message_input.innerText = ``; @@ -60,10 +60,11 @@ const ask_gpt = async (message) => { window.scrollTo(0, 0); window.controller = new AbortController(); - jailbreak = document.getElementById("jailbreak"); - model = document.getElementById("model"); - prompt_lock = true; - window.text = ``; + jailbreak = document.getElementById("jailbreak"); + provider = document.getElementById("provider"); + model = document.getElementById("model"); + prompt_lock = true; + window.text = ``; window.token = message_id(); stop_generating.classList.remove(`stop_generating-hidden`); @@ -109,12 +110,15 @@ const ask_gpt = async (message) => { headers: { "content-type": `application/json`, accept: `text/event-stream`, + // v: `1.0.0`, + // ts: Date.now().toString(), }, body: JSON.stringify({ conversation_id: window.conversation_id, action: `_ask`, model: model.options[model.selectedIndex].value, jailbreak: jailbreak.options[jailbreak.selectedIndex].value, + provider: provider.options[provider.selectedIndex].value, meta: { id: window.token, content: { -- cgit v1.2.3